近日事务繁多,作业暂搁了两天
进度
- 优化游戏失败逻辑,失败播放音乐时,全体植物和僵尸应停止运动、显示失败图片,然后弹出选择框,可实现重开或关闭
def gamelose(self):
# 加载失败图片
img_lose = pygame.image.load('assets/其他图片/gamelose.png')
img_lose_rect = myfunc1(self.scr, img_lose)
# 绘制失败图片
self.scr.blit(img_lose, img_lose_rect)
# 播放失败音乐
Thread(target=play_music('assets/音乐音效/lose.wav')).start()
# 延时,以播放音乐
t = 60*5
while True:
t -= 1
pygame.display.flip()
pyClock.tick(60)
if t == 0:
GameData['status'] = 'self.gameover'
break
- 优化游戏胜利逻辑,全屏变暗后,同样弹出选择框
def gamewin(self):
img_win = pygame.Surface(mainScreen)
img_win_color = 255
Thread(target=play_music('assets/音乐音效/win.wav')).start()
t = 60*4.5
while True:
t -= 1
img_win_color -= 0.03
img_win.fill((img_win_color, img_win_color, img_win_color))
self.scr.blit(img_win, (0, 0), special_flags=pygame.BLEND_RGBA_MULT)
pygame.display.flip()
pyClock.tick(60)
if t == 0:
GameData['status'] = 'self.gameover'
break
效果
植物大战僵尸 困难ai-失败