diff --git a/source/constants.py b/source/constants.py index d950666..f455ef6 100755 --- a/source/constants.py +++ b/source/constants.py @@ -16,7 +16,11 @@ JSON_PATH_ZOMBIE = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'res # 植物显示特殊定义文件路径 JSON_PATH_PLANTS = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'resources', 'data', 'entity', 'plant.json') # 游戏图片资源路径 -IMG_DIR_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "resources","graphics") +PATH_IMG_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "resources","graphics") +# 游戏关卡地图文件夹路径 +PATH_MAP_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "resources","map") +# 游戏音乐文件夹路径 +PATH_MUSIC_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "resources","music") # 窗口标题 ORIGINAL_CAPTION = 'pypvz' diff --git a/source/state/level.py b/source/state/level.py index f98cd2f..a09eb05 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -48,7 +48,7 @@ class Level(tool.State): map_file = f'level_{self.game_info[c.LEVEL_NUM]}.json' # 设置标题 pg.display.set_caption(f"pypvz: 冒险模式 第{self.game_info[c.LEVEL_NUM]}关") - file_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))),'resources' , 'data', 'map', map_file) + file_path = os.path.join(c.PATH_MAP_DIR, map_file) # 最后一关之后应该结束了 try: with open(file_path) as f: @@ -379,7 +379,7 @@ class Level(tool.State): # 播放选卡音乐 pg.mixer.music.stop() - pg.mixer.music.load(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "music", "chooseYourSeeds.opus")) + pg.mixer.music.load(os.path.join(c.PATH_MUSIC_DIR, "chooseYourSeeds.opus")) pg.mixer.music.play(-1, 0) pg.mixer.music.set_volume(self.game_info[c.VOLUME]) @@ -401,7 +401,7 @@ class Level(tool.State): # 播放bgm pg.mixer.music.stop() - pg.mixer.music.load(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "music", self.bgm)) + pg.mixer.music.load(os.path.join(c.PATH_MUSIC_DIR, self.bgm)) pg.mixer.music.play(-1, 0) pg.mixer.music.set_volume(self.game_info[c.VOLUME]) diff --git a/source/state/mainmenu.py b/source/state/mainmenu.py index bb426a8..e9fed35 100644 --- a/source/state/mainmenu.py +++ b/source/state/mainmenu.py @@ -18,7 +18,7 @@ class Menu(tool.State): self.setupOptionMenu() self.setupSunflowerTrophy() 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.load(os.path.join(c.PATH_MUSIC_DIR, "intro.opus")) pg.mixer.music.play(-1, 0) pg.display.set_caption(c.ORIGINAL_CAPTION) pg.mixer.music.set_volume(self.game_info[c.VOLUME]) diff --git a/source/tool.py b/source/tool.py index b7bf7ff..3705a34 100755 --- a/source/tool.py +++ b/source/tool.py @@ -228,6 +228,6 @@ pg.mixer.set_num_channels(255) # 设置可以同时播放的音频数量,默 if os.path.exists(c.ORIGINAL_LOGO): # 设置窗口图标,仅对非Nuitka时生效,Nuitka不需要包括额外的图标文件,自动跳过这一过程即可 pg.display.set_icon(pg.image.load(c.ORIGINAL_LOGO)) -GFX = load_all_gfx(c.IMG_DIR_PATH) +GFX = load_all_gfx(c.PATH_IMG_DIR) ZOMBIE_RECT = loadZombieImageRect() PLANT_RECT = loadPlantImageRect()