优化音乐播放代码位置
This commit is contained in:
parent
7aee0662a5
commit
ee8de23bd5
@ -60,9 +60,6 @@ class Level(tool.State):
|
|||||||
self.game_info[c.LITTLEGAME_COMPLETIONS] += 1
|
self.game_info[c.LITTLEGAME_COMPLETIONS] += 1
|
||||||
self.done = True
|
self.done = True
|
||||||
self.next = c.MAIN_MENU
|
self.next = c.MAIN_MENU
|
||||||
pg.mixer.music.stop()
|
|
||||||
pg.mixer.music.load(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "music", "intro.opus"))
|
|
||||||
pg.mixer.music.play(-1, 0)
|
|
||||||
with open(c.USERDATA_PATH, "w") as f:
|
with open(c.USERDATA_PATH, "w") as f:
|
||||||
userdata = {}
|
userdata = {}
|
||||||
for i in self.game_info:
|
for i in self.game_info:
|
||||||
@ -554,9 +551,6 @@ class Level(tool.State):
|
|||||||
self.done = True
|
self.done = True
|
||||||
self.next = c.MAIN_MENU
|
self.next = c.MAIN_MENU
|
||||||
self.persist = {c.CURRENT_TIME:0, c.LEVEL_NUM:self.persist[c.LEVEL_NUM], c.LITTLEGAME_NUM:self.persist[c.LITTLEGAME_NUM]}
|
self.persist = {c.CURRENT_TIME:0, c.LEVEL_NUM:self.persist[c.LEVEL_NUM], c.LITTLEGAME_NUM:self.persist[c.LITTLEGAME_NUM]}
|
||||||
pg.mixer.music.stop()
|
|
||||||
pg.mixer.music.load(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "music", "intro.opus"))
|
|
||||||
pg.mixer.music.play(-1, 0)
|
|
||||||
# 播放点击音效
|
# 播放点击音效
|
||||||
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "buttonclick.ogg")).play()
|
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "buttonclick.ogg")).play()
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,10 @@ class Menu(tool.State):
|
|||||||
self.game_info = persist
|
self.game_info = persist
|
||||||
self.setupBackground()
|
self.setupBackground()
|
||||||
self.setupOptions()
|
self.setupOptions()
|
||||||
|
self.setupOptionButton()
|
||||||
|
pg.mixer.music.stop()
|
||||||
|
pg.mixer.music.load(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "music", "intro.opus"))
|
||||||
|
pg.mixer.music.play(-1, 0)
|
||||||
pg.display.set_caption(c.ORIGINAL_CAPTION)
|
pg.display.set_caption(c.ORIGINAL_CAPTION)
|
||||||
|
|
||||||
def setupBackground(self):
|
def setupBackground(self):
|
||||||
@ -172,6 +176,7 @@ class Menu(tool.State):
|
|||||||
|
|
||||||
# 音量+、音量-
|
# 音量+、音量-
|
||||||
|
|
||||||
|
# 在选项菜单打开时,检测是否点击到返回
|
||||||
def checkReturnClick(self, mouse_pos):
|
def checkReturnClick(self, mouse_pos):
|
||||||
x, y = mouse_pos
|
x, y = mouse_pos
|
||||||
if (x >= self.return_button_rect.x and x <= self.return_button_rect.right and
|
if (x >= self.return_button_rect.x and x <= self.return_button_rect.right and
|
||||||
|
|||||||
@ -229,8 +229,3 @@ except:
|
|||||||
GFX = load_all_gfx(os.path.join(os.path.dirname(os.path.dirname(__file__)) ,os.path.join("resources","graphics")))
|
GFX = load_all_gfx(os.path.join(os.path.dirname(os.path.dirname(__file__)) ,os.path.join("resources","graphics")))
|
||||||
ZOMBIE_RECT = loadZombieImageRect()
|
ZOMBIE_RECT = loadZombieImageRect()
|
||||||
PLANT_RECT = loadPlantImageRect()
|
PLANT_RECT = loadPlantImageRect()
|
||||||
|
|
||||||
# 播放音乐
|
|
||||||
pg.mixer.init()
|
|
||||||
pg.mixer.music.load(os.path.join(os.path.dirname(os.path.dirname(__file__)) ,"resources", "music", "intro.opus"))
|
|
||||||
pg.mixer.music.play(-1, 0)
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user