From e29a1a25678850c59a5dbdb202a503602705fa83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=A4=96=E4=B9=8B=E7=A5=9E?= Date: Thu, 7 Apr 2022 23:22:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9A=82=E5=81=9C=E4=BA=86?= =?UTF-8?q?=E4=BD=86=E6=98=AF=E6=B2=A1=E6=9C=89=E5=AE=8C=E5=85=A8=E6=9A=82?= =?UTF-8?q?=E5=81=9C=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/state/level.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/source/state/level.py b/source/state/level.py index 103715b..9fa0c87 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -18,6 +18,10 @@ class Level(tool.State): self.map_y_len = c.GRID_Y_LEN self.map = map.Map(c.GRID_X_LEN, self.map_y_len) + # 暂停状态 + self.pause = False + self.pauseTime = 0 + # 默认显然不用显示菜单 self.showLittleMenu = False @@ -112,7 +116,7 @@ class Level(tool.State): # 更新函数每帧被调用,将鼠标事件传入给状态处理函数 def update(self, surface, current_time, mouse_pos, mouse_click): - self.current_time = self.game_info[c.CURRENT_TIME] = current_time + self.current_time = self.game_info[c.CURRENT_TIME] = self.pvzTime(current_time) if self.state == c.CHOOSE: self.choose(mouse_pos, mouse_click) elif self.state == c.PLAY: @@ -120,6 +124,14 @@ class Level(tool.State): self.draw(surface) + def pvzTime(self, current_time): + # 扣除暂停时间 + if not self.pause: + self.beforePauseTime = current_time - self.pauseTime + else: + self.pauseTime = current_time - self.beforePauseTime + return self.beforePauseTime + def initBowlingMap(self): print('initBowlingMap') for x in range(3, self.map.width): @@ -280,11 +292,14 @@ class Level(tool.State): def play(self, mouse_pos, mouse_click): # 如果暂停 if self.showLittleMenu: + # 设置暂停状态 + self.pause = True # 暂停播放音乐 pg.mixer.music.pause() if mouse_click[0]: if self.checkReturnClick(mouse_pos): # 终止暂停,停止显示菜单 + self.pause = False self.showLittleMenu = False # 继续播放音乐 pg.mixer.music.unpause()