From 36f0d4ae4b161eb7f322f0ad81e1fda03a059c22 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, 31 Mar 2022 09:20:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9B=AE=E5=BD=95=E8=AE=BF?= =?UTF-8?q?=E9=97=AEbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/state/level.py | 3 ++- source/tool.py | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/source/state/level.py b/source/state/level.py index 846d62b..bd0356f 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -2,6 +2,7 @@ __author__ = 'marble_xu' import os import json +import sys import pygame as pg from .. import tool from .. import constants as c @@ -24,7 +25,7 @@ class Level(tool.State): def loadMap(self): map_file = 'level_' + str(self.game_info[c.LEVEL_NUM]) + '.json' - file_path = os.path.join('source', 'data', 'map', map_file) + file_path = os.path.join(sys.path[0], 'source', 'data', 'map', map_file) f = open(file_path) self.map_data = json.load(f) f.close() diff --git a/source/tool.py b/source/tool.py index 1a319c8..2ebc9f6 100755 --- a/source/tool.py +++ b/source/tool.py @@ -2,6 +2,7 @@ __author__ = 'marble_xu' import os import json +import sys from abc import abstractmethod import pygame as pg from . import constants as c @@ -154,14 +155,14 @@ def load_all_gfx(directory, colorkey=c.WHITE, accept=('.png', '.jpg', '.bmp', '. return graphics def loadZombieImageRect(): - file_path = os.path.join('source', 'data', 'entity', 'zombie.json') + file_path = os.path.join(sys.path[0], 'source', 'data', 'entity', 'zombie.json') f = open(file_path) data = json.load(f) f.close() return data[c.ZOMBIE_IMAGE_RECT] def loadPlantImageRect(): - file_path = os.path.join('source', 'data', 'entity', 'plant.json') + file_path = os.path.join(sys.path[0], 'source', 'data', 'entity', 'plant.json') f = open(file_path) data = json.load(f) f.close() @@ -171,6 +172,6 @@ pg.init() pg.display.set_caption(c.ORIGINAL_CAPTION) SCREEN = pg.display.set_mode(c.SCREEN_SIZE) -GFX = load_all_gfx(os.path.join("resources","graphics")) +GFX = load_all_gfx(os.path.join(sys.path[0] ,os.path.join("resources","graphics"))) ZOMBIE_RECT = loadZombieImageRect() PLANT_RECT = loadPlantImageRect()