小球碰撞问题
while running:for event in pygame.event.get():
if event.type==pygame.QUIT:
sys.exit()
elif event.type==GAMEOVER:
loser_sound.play()
pygame.time.delay(5000)
laugh_sound.play()
pygame.time.delay(5000)
running=False
elif event.type==MYTIMER:
if motion:
for each in group:
if each.check(motion):
each.speed=
each.control=True
motion=0
elif event.type==pygame.MOUSEMOTION:
motion+=1
elif event.type==pygame.KEYDOWN:
if event.key==pygame.K_w:
for each in group:
if each.control:
each.speed-=1
if event.key==pygame.K_s:
for each in group:
if each.control:
each.speed+=1
if event.key==pygame.K_a:
for each in group:
if each.control:
each.speed-=1
if event.key==pygame.K_d:
for each in group:
if each.control:
each.speed+=1
if event.key==pygame.K_SPACE:
for each in group:
if each.control:
for i in hole:
if i<=each.rect.left<=i and \
i<=each.rect.top<=i:
hole_sound.play()
each.speed=
group.remove(each)
temp=balls.pop(balls.index(each))
balls.insert(0,temp)
hole.remove(i)
if not hole:
pygame.mixer.music.stop()
winner_sound.play()
pygame.time.delay(5000)
laugh_sound.play()
最后5球入洞,停止音乐(pygame.mixer.music.stop()),会发送GAMEOVER事件吧?
elif event.type==GAMEOVER:
loser_sound.play()
pygame.time.delay(5000)
laugh_sound.play()
pygame.time.delay(5000)
Gameover = pygame.USEREVENT
pygame.mixer.music.set_endevent(Gameover)
页:
[1]