存储项目的大部分函数

This commit is contained in:
206530219 2021-06-19 12:31:58 +08:00
parent 42042ef7b6
commit 6b3b05364a
1 changed files with 41 additions and 0 deletions

View File

@ -261,3 +261,44 @@ def change_fleet_direction(ai_settings, aliens):
def change_bossalien_direction(ai_settings, bossalien):
"""改变BOSS外星人的方向"""
ai_settings.bossalien_direction *= -1
def ship_hit(ai_settings, screen, stats, sb, ship, aliens, bullets, bossalien, bossbullet):
"""响应被外星人撞到的飞船"""
if stats.ships_left > 0:
# 增加:播放失去生命值音效
pygame.mixer.init()
sound = pygame.mixer.Sound('sounds/loselifes.wav')
sound.play()
# 将ships_left减1
stats.ships_left -= 1
# 更新记分牌
sb.prep_ships()
# 清空外星人列表和子弹列表
aliens.empty()
bullets.empty()
# 增加如果不是BOSS关就创建一群新的外星人并将飞船放到屏幕底端中央
if stats.level != stats.bosslevel:
create_fleet(ai_settings, screen, ship, aliens)
ship.center_ship()
# 增加如果是BOSS关直接创建一个飞船继续并且重置撞击到飞船的子弹的位置
else:
ship.center_ship()
bossbullet.reset_position(bossalien)
# 暂停
sleep(0.5)
else:
stats.game_active = False
pygame.mouse.set_visible(True)
# 增加:播放游戏结束音效
pygame.mixer.music.stop()
pygame.mixer.init()
sound = pygame.mixer.Sound('sounds/gameover.wav')
sound.play()