From e8e31470d03c3f7ef6df596ce2189435ab5a8ba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BD=AA?= <30586666+callmebg@users.noreply.github.com> Date: Wed, 21 Oct 2020 15:56:15 +0800 Subject: [PATCH] change the dictionary --- main.py | 2 ++ {source => resources}/data/entity/plant.json | 0 {source => resources}/data/entity/zombie.json | 0 {source => resources}/data/map/level_0.json | 0 {source => resources}/data/map/level_1.json | 0 {source => resources}/data/map/level_2.json | 0 {source => resources}/data/map/level_3.json | 0 {source => resources}/data/map/level_4.json | 0 {source => resources}/data/map/level_5.json | 0 source/component/menubar.py | 2 -- source/constants.py | 2 -- source/main.py | 3 ++- source/state/level.py | 2 +- source/state/mainmenu.py | 2 -- source/tool.py | 8 +++----- 15 files changed, 8 insertions(+), 13 deletions(-) rename {source => resources}/data/entity/plant.json (100%) rename {source => resources}/data/entity/zombie.json (100%) rename {source => resources}/data/map/level_0.json (100%) rename {source => resources}/data/map/level_1.json (100%) rename {source => resources}/data/map/level_2.json (100%) rename {source => resources}/data/map/level_3.json (100%) rename {source => resources}/data/map/level_4.json (100%) rename {source => resources}/data/map/level_5.json (100%) diff --git a/main.py b/main.py index 9421809..a75e9ba 100644 --- a/main.py +++ b/main.py @@ -2,5 +2,7 @@ import pygame as pg from source.main import main if __name__=='__main__': + # do everything in this main function main() + # don't forget quit for release all resource pg.quit() \ No newline at end of file diff --git a/source/data/entity/plant.json b/resources/data/entity/plant.json similarity index 100% rename from source/data/entity/plant.json rename to resources/data/entity/plant.json diff --git a/source/data/entity/zombie.json b/resources/data/entity/zombie.json similarity index 100% rename from source/data/entity/zombie.json rename to resources/data/entity/zombie.json diff --git a/source/data/map/level_0.json b/resources/data/map/level_0.json similarity index 100% rename from source/data/map/level_0.json rename to resources/data/map/level_0.json diff --git a/source/data/map/level_1.json b/resources/data/map/level_1.json similarity index 100% rename from source/data/map/level_1.json rename to resources/data/map/level_1.json diff --git a/source/data/map/level_2.json b/resources/data/map/level_2.json similarity index 100% rename from source/data/map/level_2.json rename to resources/data/map/level_2.json diff --git a/source/data/map/level_3.json b/resources/data/map/level_3.json similarity index 100% rename from source/data/map/level_3.json rename to resources/data/map/level_3.json diff --git a/source/data/map/level_4.json b/resources/data/map/level_4.json similarity index 100% rename from source/data/map/level_4.json rename to resources/data/map/level_4.json diff --git a/source/data/map/level_5.json b/resources/data/map/level_5.json similarity index 100% rename from source/data/map/level_5.json rename to resources/data/map/level_5.json diff --git a/source/component/menubar.py b/source/component/menubar.py index 56054a5..b06e8d2 100644 --- a/source/component/menubar.py +++ b/source/component/menubar.py @@ -1,5 +1,3 @@ -__author__ = 'marble_xu' - import random import pygame as pg from .. import tool diff --git a/source/constants.py b/source/constants.py index 0c4e2b6..09bfc9c 100644 --- a/source/constants.py +++ b/source/constants.py @@ -1,5 +1,3 @@ -__author__ = 'marble_xu' - START_LEVEL_NUM = 1 ORIGINAL_CAPTION = 'Plant VS Zombies Game' diff --git a/source/main.py b/source/main.py index 92fcdc1..7734e25 100644 --- a/source/main.py +++ b/source/main.py @@ -1,9 +1,10 @@ -__author__ = 'marble_xu' +__author__ = 'wcb' from . import tool from . import constants as c from .state import mainmenu, screen, level +# create a standard game def main(): game = tool.Control() state_dict = {c.MAIN_MENU: mainmenu.Menu(), diff --git a/source/state/level.py b/source/state/level.py index 133cc28..eda3bbe 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -24,7 +24,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('resources', 'data', 'map', map_file) f = open(file_path) self.map_data = json.load(f) f.close() diff --git a/source/state/mainmenu.py b/source/state/mainmenu.py index 6ac345f..98c96b7 100644 --- a/source/state/mainmenu.py +++ b/source/state/mainmenu.py @@ -1,5 +1,3 @@ -__author__ = 'marble_xu' - import pygame as pg from .. import tool from .. import constants as c diff --git a/source/tool.py b/source/tool.py index 1a319c8..0fdf565 100644 --- a/source/tool.py +++ b/source/tool.py @@ -1,5 +1,3 @@ -__author__ = 'marble_xu' - import os import json from abc import abstractmethod @@ -100,7 +98,7 @@ def load_image_frames(directory, image_name, colorkey, accept): tmp = {} # image_name is "Peashooter", pic name is 'Peashooter_1', get the index 1 index_start = len(image_name) + 1 - frame_num = 0; + frame_num = 0 for pic in os.listdir(directory): name, ext = os.path.splitext(pic) if ext.lower() in accept: @@ -154,14 +152,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('resources', '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('resources', 'data', 'entity', 'plant.json') f = open(file_path) data = json.load(f) f.close()