修复暂停了但是没有完全暂停的bug
This commit is contained in:
parent
ada477c5a5
commit
e29a1a2567
@ -18,6 +18,10 @@ class Level(tool.State):
|
|||||||
self.map_y_len = c.GRID_Y_LEN
|
self.map_y_len = c.GRID_Y_LEN
|
||||||
self.map = map.Map(c.GRID_X_LEN, self.map_y_len)
|
self.map = map.Map(c.GRID_X_LEN, self.map_y_len)
|
||||||
|
|
||||||
|
# 暂停状态
|
||||||
|
self.pause = False
|
||||||
|
self.pauseTime = 0
|
||||||
|
|
||||||
# 默认显然不用显示菜单
|
# 默认显然不用显示菜单
|
||||||
self.showLittleMenu = False
|
self.showLittleMenu = False
|
||||||
|
|
||||||
@ -112,7 +116,7 @@ class Level(tool.State):
|
|||||||
|
|
||||||
# 更新函数每帧被调用,将鼠标事件传入给状态处理函数
|
# 更新函数每帧被调用,将鼠标事件传入给状态处理函数
|
||||||
def update(self, surface, current_time, mouse_pos, mouse_click):
|
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:
|
if self.state == c.CHOOSE:
|
||||||
self.choose(mouse_pos, mouse_click)
|
self.choose(mouse_pos, mouse_click)
|
||||||
elif self.state == c.PLAY:
|
elif self.state == c.PLAY:
|
||||||
@ -120,6 +124,14 @@ class Level(tool.State):
|
|||||||
|
|
||||||
self.draw(surface)
|
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):
|
def initBowlingMap(self):
|
||||||
print('initBowlingMap')
|
print('initBowlingMap')
|
||||||
for x in range(3, self.map.width):
|
for x in range(3, self.map.width):
|
||||||
@ -280,11 +292,14 @@ class Level(tool.State):
|
|||||||
def play(self, mouse_pos, mouse_click):
|
def play(self, mouse_pos, mouse_click):
|
||||||
# 如果暂停
|
# 如果暂停
|
||||||
if self.showLittleMenu:
|
if self.showLittleMenu:
|
||||||
|
# 设置暂停状态
|
||||||
|
self.pause = True
|
||||||
# 暂停播放音乐
|
# 暂停播放音乐
|
||||||
pg.mixer.music.pause()
|
pg.mixer.music.pause()
|
||||||
if mouse_click[0]:
|
if mouse_click[0]:
|
||||||
if self.checkReturnClick(mouse_pos):
|
if self.checkReturnClick(mouse_pos):
|
||||||
# 终止暂停,停止显示菜单
|
# 终止暂停,停止显示菜单
|
||||||
|
self.pause = False
|
||||||
self.showLittleMenu = False
|
self.showLittleMenu = False
|
||||||
# 继续播放音乐
|
# 继续播放音乐
|
||||||
pg.mixer.music.unpause()
|
pg.mixer.music.unpause()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user