“Game Over” 屏幕
主循环顶部 添加 game_over 变量,标记游戏结束状态
show_go_screen() 函数稍后定义
重置所有内容
# 游戏主循环
game_over = True
running = True
while running:
if game_over:
show_go_screen()
game_over = False
all_sprites = pygame.sprite.Group()
mobs = pygame.sprite.Group()
bullets = pygame.sprite.Group()
powerups = pygame.sprite.Group()
player = Player()
all_sprites.add(player)
for i in range(8):
newmob()
score = 0
当玩家生命值为0,设置 game_over = True
# 如果玩家死亡 并且 爆炸动画播放完毕。
if player.lives==0 and not death_explosion.alive():
game_over = True
Game Over 屏幕
添加 show_go_screen() 函数
def show_go_screen():
screen.blit(background, background_rect)
draw_text(screen, "太空狙击!", 64, WIDTH / 2, HEIGHT / 4)
draw_text(screen, "方向键 移动,空格键 开火", 22,
WIDTH / 2, HEIGHT / 2)
draw_text(screen, "按任意键开始", 18, WIDTH / 2, HEIGHT * 3 / 4)
pygame.display.flip()
waiting = True
while waiting:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
if event.type == pygame.KEYUP:
waiting = False
更多创意:
更多道具,敌人攻击,Boss,关卡