From 3898dd920d0689a193be2a3f2967f79b2d21bfc9 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, 28 Jul 2022 17:35:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B1=87=E6=80=BB=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/constants.py | 11 +++++++++-- source/tool.py | 14 +++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/source/constants.py b/source/constants.py index c595c76..d950666 100755 --- a/source/constants.py +++ b/source/constants.py @@ -9,10 +9,17 @@ else: # 非Windows系统存储路径 USERDATA_PATH = os.path.expanduser(os.path.join("~", ".config", "wszqkzqk.dev", "pypvz", "userdata.json")) USERLOG_PATH = os.path.expanduser(os.path.join("~", ".config", "wszqkzqk.dev", "pypvz", "run.log")) +# 窗口图标 +ORIGINAL_LOGO = os.path.join(os.path.dirname(os.path.dirname(__file__)), "pypvz-exec-logo.png") +# 僵尸显示特殊定义文件路径 +JSON_PATH_ZOMBIE = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'resources', 'data', 'entity', 'zombie.json') +# 植物显示特殊定义文件路径 +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") + # 窗口标题 ORIGINAL_CAPTION = 'pypvz' -# 窗口图标 -ORIGINAL_LOGO = "pypvz-exec-logo.png" # 游戏模式 GAME_MODE = 'mode' diff --git a/source/tool.py b/source/tool.py index 6ad36f1..b7bf7ff 100755 --- a/source/tool.py +++ b/source/tool.py @@ -213,25 +213,21 @@ def load_all_gfx(directory, colorkey=c.WHITE, accept=('.png', '.jpg', '.bmp', '. # 从文件加载矩形碰撞范围 # 用于消除文件边框影响 def loadZombieImageRect(): - file_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'resources', 'data', 'entity', 'zombie.json') - with open(file_path) as f: + with open(c.JSON_PATH_ZOMBIE) as f: data = json.load(f) return data[c.ZOMBIE_IMAGE_RECT] def loadPlantImageRect(): - file_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'resources', 'data', 'entity', 'plant.json') - with open(file_path) as f: + with open(c.JSON_PATH_PLANTS) as f: data = json.load(f) return data[c.PLANT_IMAGE_RECT] pg.display.set_caption(c.ORIGINAL_CAPTION) # 设置标题 SCREEN = pg.display.set_mode(c.SCREEN_SIZE) # 设置初始屏幕 pg.mixer.set_num_channels(255) # 设置可以同时播放的音频数量,默认为8,经常不够用 -try: # 设置窗口图标,仅对非Nuitka时生效,Nuitka不需要包括额外的图标文件,自动跳过这一过程即可 - pg.display.set_icon(pg.image.load(os.path.join(os.path.dirname(os.path.dirname(__file__)), c.ORIGINAL_LOGO))) -except: - pass +if os.path.exists(c.ORIGINAL_LOGO): # 设置窗口图标,仅对非Nuitka时生效,Nuitka不需要包括额外的图标文件,自动跳过这一过程即可 + pg.display.set_icon(pg.image.load(c.ORIGINAL_LOGO)) -GFX = load_all_gfx(os.path.join(os.path.dirname(os.path.dirname(__file__)) ,os.path.join("resources","graphics"))) +GFX = load_all_gfx(c.IMG_DIR_PATH) ZOMBIE_RECT = loadZombieImageRect() PLANT_RECT = loadPlantImageRect()