存储项目的大部分函数

This commit is contained in:
206530219 2021-06-19 12:35:22 +08:00
parent 5429100c85
commit 6afd573f44
1 changed files with 39 additions and 0 deletions

View File

@ -312,3 +312,42 @@ def check_aliens_bottom(ai_settings, screen, stats, sb, ship, aliens, bullets):
# 像飞船被撞到一样进行处理
ship_hit(ai_settings, screen, stats, sb, ship, aliens, bossalien, bullets)
break
def check_play_button(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets, mouse_x, mouse_y):
"""在玩家单击Play按钮时开始新游戏"""
button_clicked = play_button.rect.collidepoint(mouse_x, mouse_y)
if button_clicked and not stats.game_active:
# 增加:播放音效
pygame.mixer.init()
sound = pygame.mixer.Sound('sounds/clickbuttons.wav')
sound.play()
# 重置游戏设置
ai_settings.initialize_dynamic_settings()
# 隐藏光标
pygame.mouse.set_visible(False)
# 重置游戏统计信息
stats.reset_stats()
stats.game_active = True
# 重置记分牌图像
sb.prep_score()
sb.prep_high_score()
sb.prep_level()
sb.prep_ships()
# 清空外星人列表和子弹列表
aliens.empty()
bullets.empty()
# 创建一群新的外星人,并让飞船居中
create_fleet(ai_settings, screen, ship, aliens)
ship.center_ship()
def check_high_score(stats, sb):
"""检查是否诞生了新的最高得分"""
if stats.score > stats.high_score:
stats.high_score = stats.score
sb.prep_high_score()