存储项目的大部分函数
This commit is contained in:
parent
a4c2e8c86d
commit
26df9e99b6
|
@ -16,4 +16,14 @@ def check_keydown_events(event, ai_settings, screen, ship, bullets):
|
|||
elif event.key == pygame.K_SPACE:
|
||||
fire_bullet(ai_settings, screen, ship, bullets)
|
||||
elif event.key == pygame.K_q:
|
||||
sys.exit()
|
||||
sys.exit()
|
||||
def fire_bullet(ai_settings, screen, ship, bullets):
|
||||
"""如果还没有到达限制,就发射一颗子弹"""
|
||||
# 创建一颗子弹,并将其加入到编组bullets中
|
||||
if len(bullets) < ai_settings.bullets_allowed:
|
||||
new_bullet = Bullet(ai_settings, screen, ship)
|
||||
bullets.add(new_bullet)
|
||||
# 增加:添加发射音效
|
||||
pygame.mixer.init()
|
||||
sound = pygame.mixer.Sound('sounds/firebullets.wav')
|
||||
sound.play()
|
Loading…
Reference in New Issue