功能函数更改
This commit is contained in:
parent
e58c678436
commit
e808c597d3
|
@ -295,3 +295,54 @@ def check_aliens_bottom(ai_settings, game_stats, scoreb, screen, ship, aliens, b
|
|||
break
|
||||
|
||||
|
||||
ef ship_aliens_hit(ai_settings, game_stats, scoreb, screen, ship, aliens, bullets):
|
||||
"""
|
||||
响应外星人飞船相撞的后续操作
|
||||
"""
|
||||
# 外星人飞船相撞时 发出碰撞声音 ship_left减1
|
||||
if game_stats.ships_left > 0:
|
||||
music.voice_large()
|
||||
game_stats.ships_left -= 1
|
||||
|
||||
# 更新屏幕上飞船的艘数
|
||||
scoreb.prep_ships()
|
||||
|
||||
else:
|
||||
game_stats.game_active = False
|
||||
ai_settings.increase_wen() # 游戏结束后alien的速度得回到最初为
|
||||
pygame.mouse.set_visible(True) # 游戏结束后Play按钮显示出来
|
||||
|
||||
# 清空外星人列表和子弹列表
|
||||
aliens.empty()
|
||||
bullets.empty()
|
||||
|
||||
# 创建一群新的外星人并将飞船重新出现在屏幕在底部中央
|
||||
create_fleet(ai_settings, screen, ship, aliens)
|
||||
ship.center_ship()
|
||||
|
||||
# 暂停让用户反应一会
|
||||
sleep(0.5)
|
||||
|
||||
|
||||
def update_aliens(ai_settings, game_stats, scoreb, screen, ship, aliens, bullets):
|
||||
"""
|
||||
更新外星人群中所有外星人的位置
|
||||
"""
|
||||
check_fleet_edges(ai_settings, aliens)
|
||||
aliens.update()
|
||||
|
||||
if pygame.sprite.spritecollideany(ship, aliens):
|
||||
"""
|
||||
接收俩个实参--检测飞船和外星人是否发生碰撞:发生了---往下走;没发生---返回None
|
||||
"""
|
||||
ship_aliens_hit(ai_settings, game_stats, scoreb, screen, ship, aliens, bullets)
|
||||
|
||||
# 检测是否有外星人到达屏幕底部
|
||||
check_aliens_bottom(ai_settings, game_stats, scoreb, screen, ship, aliens, bullets)
|
||||
|
||||
|
||||
def check_high_score(game_stats, scoreb):
|
||||
"""检查是否诞生了新的最高得分"""
|
||||
if game_stats.score > game_stats.high_score:
|
||||
game_stats.high_score = game_stats.score
|
||||
scoreb.prep_high_score()
|
Loading…
Reference in New Issue