你好,我正在为大学做一个典型的pygame上的防御者街机游戏。我目前的目标是让游戏暂停,并在玩家失去生命时显示一条消息,并在按下一个键时继续下一次生命。这是hp和lives的代码:
hit = pygame.sprite.spritecollide(shuttle,sprites, True)
if hit:
shuttle.damage += 10 #increase damage
tesla_sprite1 = aliens.Alien(screen, ai_settings, random.randrange(800,
ai_settings.screen_width),random.randrange(0, ai_settings.screen_height))
sprites.add(tesla_sprite1)
if shuttle.damage == 100:
shuttle.damage = 0
you_crashed = "You have crashed!"
you_crashed_label = crash_font.render(f"{you_crashed}",1, (255,0,0))
screen.blit(you_crashed_label, (ai_settings.screen_width - 800, ai_settings.screen_height / 2))穿梭机是一个职业的实例,伤害是hp,精灵是一个包含敌人的精灵团队。ai_settings是一个不同的模块,我从它借用变量。有什么建议吗?
发布于 2021-05-03 22:43:24
要创建弹出菜单并停止游戏,您必须实现按钮并在主循环内嵌入while循环。您可以在该循环中绘制按钮,也可以检测鼠标输入。当按钮被按下时,简单地改变游戏状态并从内部循环中断。
https://stackoverflow.com/questions/67370831
复制相似问题