From e010251b00b1ed60e2aebb302740c83634c93c8a Mon Sep 17 00:00:00 2001 From: wszqkzqk Date: Sat, 6 Aug 2022 15:36:47 +0800 Subject: [PATCH 01/32] =?UTF-8?q?=E5=B9=B3=E8=A1=A1=E9=9A=BE=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/state/level.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/state/level.py b/source/state/level.py index cf3013e..9a41d24 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -126,7 +126,7 @@ class Level(tool.State): zombie_list.append(c.FLAG_ZOMBIE) zombie_volume -= c.CREATE_ZOMBIE_DICT[c.FLAG_ZOMBIE][0] - # 传送带模式应当增大僵尸容量 + # 保龄球模式应当增大僵尸容量 if (self.bar_type != c.CHOOSEBAR_STATIC): zombie_volume += 2 @@ -265,7 +265,7 @@ class Level(tool.State): c.SOUND_ZOMBIE_COMING.play() return if (self.wave_num % 10 != 9): - if ((current_time - self.wave_time >= 25000 + random.randint(0, 6000)) or (self.bar_type != c.CHOOSEBAR_STATIC and current_time - self.wave_time >= 12500 + random.randint(0, 3000))): + if ((current_time - self.wave_time >= 25000 + random.randint(0, 6000)) or (self.bar_type == c.CHOOSEBAR_BOWLING and current_time - self.wave_time >= 12500 + random.randint(0, 3000))): self.wave_num += 1 self.wave_time = current_time self.wave_zombies = self.waves[self.wave_num - 1] From 98463e524b5e051b8b017b6aec2028c38237013a Mon Sep 17 00:00:00 2001 From: wszqkzqk Date: Sat, 6 Aug 2022 15:39:39 +0800 Subject: [PATCH 02/32] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A2=93=E7=A2=91?= =?UTF-8?q?=E5=90=9E=E5=99=AC=E8=80=85=E5=8F=AF=E4=BB=A5=E7=A7=8D=E6=A4=8D?= =?UTF-8?q?=E5=9C=A8=E5=A2=93=E7=A2=91=E5=90=9E=E5=99=AC=E8=80=85=E4=B8=8A?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/component/map.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/component/map.py b/source/component/map.py index 206905a..93003e1 100755 --- a/source/component/map.py +++ b/source/component/map.py @@ -55,7 +55,7 @@ class Map(): else: return False if plant_name == c.GRAVEBUSTER: - if (c.GRAVE in self.map[map_y][map_x][c.MAP_PLANT]): + if (c.GRAVE in self.map[map_y][map_x][c.MAP_PLANT] and (plant_name not in self.map[map_y][map_x][c.MAP_PLANT])): return True else: return False @@ -420,9 +420,9 @@ LITTLE_GAME_MAP_DATA = ( c.NUM_FLAGS:3, c.CARD_POOL: { c.PUFFSHROOM: 100, c.SCAREDYSHROOM: 100, - c.ICESHROOM: 100, + c.ICESHROOM: 70, c.HYPNOSHROOM: 100, - c.DOOMSHROOM: 100, + c.DOOMSHROOM: 50, c.GRAVEBUSTER: 100, c.FUMESHROOM: 200}, c.GRADE_GRAVES:3 From 1c96110e289b3bc0c140f21e4d777d8b2878bce4 Mon Sep 17 00:00:00 2001 From: wszqkzqk Date: Mon, 8 Aug 2022 09:05:41 +0800 Subject: [PATCH 03/32] =?UTF-8?q?=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pypvz.py | 2 +- source/constants.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pypvz.py b/pypvz.py index 89e0b5a..f56f05e 100755 --- a/pypvz.py +++ b/pypvz.py @@ -11,7 +11,7 @@ from source import tool from source import constants as c from source.state import mainmenu, screen, level -if __name__=="__main__": +if __name__ == "__main__": # 日志设置 if not os.path.exists(os.path.dirname(c.USERLOG_PATH)): os.makedirs(os.path.dirname(c.USERLOG_PATH)) diff --git a/source/constants.py b/source/constants.py index 987710d..7579e88 100755 --- a/source/constants.py +++ b/source/constants.py @@ -9,12 +9,14 @@ 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") # 游戏图片资源路径 PATH_IMG_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "resources", "graphics") # 游戏音乐文件夹路径 PATH_MUSIC_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "resources","music") +# 窗口图标 +ORIGINAL_LOGO = os.path.join(os.path.dirname(os.path.dirname(__file__)), "pypvz-exec-logo.png") +# 字体路径 +FONT_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "resources", "DroidSansFallback.ttf") # 窗口标题 ORIGINAL_CAPTION = "pypvz" @@ -29,8 +31,6 @@ SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 SCREEN_SIZE = (SCREEN_WIDTH, SCREEN_HEIGHT) -# 字体路径 -FONT_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "resources", "DroidSansFallback.ttf") # 选卡数量 # 最大数量 @@ -231,7 +231,7 @@ CARD_MOVE_TIME = 60 CAR = "car" SUN = "Sun" -# plant子类非植物对象 +# plant子类非植物对象(这里的是不包括阳光、子弹的拟植物对象) NON_PLANT_OBJECTS = { HOLE := "Hole", ICEFROZENPLOT := "IceFrozenPlot", From 6edaf34d116184d7db60f8b03596b89d8266dc53 Mon Sep 17 00:00:00 2001 From: wszqkzqk Date: Mon, 8 Aug 2022 10:38:45 +0800 Subject: [PATCH 04/32] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/tool.py | 68 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/source/tool.py b/source/tool.py index 29014a6..5bf0dd9 100755 --- a/source/tool.py +++ b/source/tool.py @@ -1,9 +1,11 @@ +import logging import os import json from abc import abstractmethod import pygame as pg from pygame.locals import * from . import constants as c +logger = logging.getLogger("main") # 状态机 抽象基类 class State(): @@ -66,33 +68,54 @@ class Control(): # 存在存档即导入 with open(c.USERDATA_PATH) as f: userdata = json.load(f) - self.game_info = {} - # 导入数据,保证了可运行性,但是放弃了数据向后兼容性,即假如某些变量在以后改名,在导入时可能会被重置 - need_to_rewrite = False - for key in c.INIT_USERDATA: - if key in userdata: - self.game_info[key] = userdata[key] - else: - self.game_info[key] = c.INIT_USERDATA[key] - need_to_rewrite = True - if need_to_rewrite: - with open(c.USERDATA_PATH, "w") as f: - savedata = json.dumps(self.game_info, sort_keys=True, indent=4) - f.write(savedata) - except: - if not os.path.exists(os.path.dirname(c.USERDATA_PATH)): - os.makedirs(os.path.dirname(c.USERDATA_PATH)) - with open(c.USERDATA_PATH, "w") as f: - savedata = json.dumps(c.INIT_USERDATA, sort_keys=True, indent=4) - f.write(savedata) - self.game_info = c.INIT_USERDATA.copy() # 内部全是不可变对象,浅拷贝即可 + except FileNotFoundError: + self.setupUserData() + except PermissionError: + logger.warning("用户存档文件不可读!本程序将自动设置存档文件为可读状态!\n") + # Python权限规则和Unix不一样,420表示unix的655,Windows自动忽略不支持项 + os.chmod(c.USERDATA_PATH, 420) + try: + with open(c.USERDATA_PATH) as f: + userdata = json.load(f) + except json.JSONDecodeError: + logger.warning("用户存档解码错误!现在将使用新建的初始化存档!\n") + self.setupUserData() + else: + self.applyUserData(userdata) + except json.JSONDecodeError: + logger.warning("用户存档解码错误!现在将使用新建的初始化存档!\n") + self.setupUserData() + else: # 未引发异常时执行的操作 + self.applyUserData(userdata) # 存档内不包含即时游戏时间信息,需要新建 self.game_info[c.CURRENT_TIME] = 0 # 50为目前的基础帧率,乘以倍率即是游戏帧率 self.fps = 50 * self.game_info[c.GAME_RATE] - + def setupUserData(self): + if not os.path.exists(os.path.dirname(c.USERDATA_PATH)): + os.makedirs(os.path.dirname(c.USERDATA_PATH)) + with open(c.USERDATA_PATH, "w") as f: + savedata = json.dumps(c.INIT_USERDATA, sort_keys=True, indent=4) + f.write(savedata) + self.game_info = c.INIT_USERDATA.copy() # 内部全是不可变对象,浅拷贝即可 + + def applyUserData(self, userdata): + self.game_info = {} + # 导入数据,保证了可运行性,但是放弃了数据向后兼容性,即假如某些变量在以后改名,在导入时可能会被重置 + need_to_rewrite = False + for key in c.INIT_USERDATA: + if key in userdata: + self.game_info[key] = userdata[key] + else: + self.game_info[key] = c.INIT_USERDATA[key] + need_to_rewrite = True + if need_to_rewrite: + with open(c.USERDATA_PATH, "w") as f: + savedata = json.dumps(self.game_info, sort_keys=True, indent=4) + f.write(savedata) + def setup_states(self, state_dict, start_state): self.state_dict = state_dict self.state_name = start_state @@ -137,8 +160,7 @@ class Control(): self.mouse_pos = pg.mouse.get_pos() self.mouse_click[0], _, self.mouse_click[1] = pg.mouse.get_pressed() # self.mouse_click[0]表示左键,self.mouse_click[1]表示右键 - print( f"点击位置: ({self.mouse_pos[0]:3}, {self.mouse_pos[1]:3})", - f"左右键点击情况: {self.mouse_click}") + print(f"点击位置: ({self.mouse_pos[0]:3}, {self.mouse_pos[1]:3}) 左右键点击情况: {self.mouse_click}") def run(self): From 7e93949f9128e4fb6cd4c1cfd829117065a6d723 Mon Sep 17 00:00:00 2001 From: wszqkzqk Date: Mon, 8 Aug 2022 10:49:18 +0800 Subject: [PATCH 05/32] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/tool.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/source/tool.py b/source/tool.py index 5bf0dd9..221f5f2 100755 --- a/source/tool.py +++ b/source/tool.py @@ -62,7 +62,7 @@ class Control(): self.state_dict = {} self.state_name = None self.state = None - # 这里需要考虑多种情况,如文件不存在、文件不可读、文件不符合JSON语法要求,这些情况目前暂定统一进行新建文件操作 + # 这里需要考虑多种情况,如文件不存在、文件不可读、文件不符合JSON语法要求 # 因此仍然采用try-except实现而非if-else实现 try: # 存在存档即导入 @@ -71,19 +71,19 @@ class Control(): except FileNotFoundError: self.setupUserData() except PermissionError: - logger.warning("用户存档文件不可读!本程序将自动设置存档文件为可读状态!\n") + logger.warning("用户存档文件不可读!程序将自动设置存档文件为可读状态!\n") # Python权限规则和Unix不一样,420表示unix的655,Windows自动忽略不支持项 os.chmod(c.USERDATA_PATH, 420) try: with open(c.USERDATA_PATH) as f: userdata = json.load(f) except json.JSONDecodeError: - logger.warning("用户存档解码错误!现在将使用新建的初始化存档!\n") + logger.warning("用户存档解码错误!程序将新建初始存档!\n") self.setupUserData() else: self.applyUserData(userdata) except json.JSONDecodeError: - logger.warning("用户存档解码错误!现在将使用新建的初始化存档!\n") + logger.warning("用户存档解码错误!程序将新建初始存档!\n") self.setupUserData() else: # 未引发异常时执行的操作 self.applyUserData(userdata) @@ -95,7 +95,9 @@ class Control(): def setupUserData(self): if not os.path.exists(os.path.dirname(c.USERDATA_PATH)): - os.makedirs(os.path.dirname(c.USERDATA_PATH)) + os.makedirs(os.path.dirname(c.USERDATA_PATH)) + else: + logger.warning("已有游戏数据目录但未找到游戏存档文件,请检查存档是否丢失!程序将新建初始存档!\n") with open(c.USERDATA_PATH, "w") as f: savedata = json.dumps(c.INIT_USERDATA, sort_keys=True, indent=4) f.write(savedata) From f3b602a30e5b577f1e1d3f4baa940e1503128da4 Mon Sep 17 00:00:00 2001 From: wszqkzqk Date: Mon, 8 Aug 2022 10:55:13 +0800 Subject: [PATCH 06/32] =?UTF-8?q?=E9=81=BF=E5=85=8D=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E7=9A=84=E6=AD=A7=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/tool.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/source/tool.py b/source/tool.py index 221f5f2..cb48806 100755 --- a/source/tool.py +++ b/source/tool.py @@ -33,8 +33,8 @@ class State(): # 工具:范围判断函数,用于判断点击 def inArea(self, rect, x, y): - if (x >= rect.x and x <= rect.right and - y >= rect.y and y <= rect.bottom): + if (rect.x <= x <= rect.right and + rect.y <= y <= rect.bottom): return True else: return False @@ -96,8 +96,6 @@ class Control(): def setupUserData(self): if not os.path.exists(os.path.dirname(c.USERDATA_PATH)): os.makedirs(os.path.dirname(c.USERDATA_PATH)) - else: - logger.warning("已有游戏数据目录但未找到游戏存档文件,请检查存档是否丢失!程序将新建初始存档!\n") with open(c.USERDATA_PATH, "w") as f: savedata = json.dumps(c.INIT_USERDATA, sort_keys=True, indent=4) f.write(savedata) From 44ccabd74de8e19b4c5dc2baa5207bec54fc6850 Mon Sep 17 00:00:00 2001 From: wszqkzqk Date: Mon, 8 Aug 2022 12:12:36 +0800 Subject: [PATCH 07/32] =?UTF-8?q?=E6=8D=95=E6=8D=89=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E6=97=B6=E6=9D=83=E9=99=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/tool.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/tool.py b/source/tool.py index cb48806..6094bd9 100755 --- a/source/tool.py +++ b/source/tool.py @@ -68,6 +68,7 @@ class Control(): # 存在存档即导入 with open(c.USERDATA_PATH) as f: userdata = json.load(f) + self.applyUserData(userdata) # 写入时也可能发生权限问题,因此放到try语句中 except FileNotFoundError: self.setupUserData() except PermissionError: @@ -85,8 +86,6 @@ class Control(): except json.JSONDecodeError: logger.warning("用户存档解码错误!程序将新建初始存档!\n") self.setupUserData() - else: # 未引发异常时执行的操作 - self.applyUserData(userdata) # 存档内不包含即时游戏时间信息,需要新建 self.game_info[c.CURRENT_TIME] = 0 From 1c52ea88f4036a47717dc4307a2e3b4ecabaaf60 Mon Sep 17 00:00:00 2001 From: wszqkzqk Date: Mon, 8 Aug 2022 12:21:13 +0800 Subject: [PATCH 08/32] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E6=9D=83=E9=99=90?= =?UTF-8?q?=E5=A4=84=E7=90=86=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pypvz.py | 1 + source/tool.py | 15 +++------------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/pypvz.py b/pypvz.py index f56f05e..58be596 100755 --- a/pypvz.py +++ b/pypvz.py @@ -18,6 +18,7 @@ if __name__ == "__main__": logger = logging.getLogger("main") formatter = logging.Formatter("%(asctime)s - %(levelname)s: %(message)s") fileHandler = RotatingFileHandler(c.USERLOG_PATH, "a", 1024*1024, 0, "utf-8") + os.chmod(c.USERLOG_PATH, 420) # 设置日志文件权限,Unix为644,Windows为可读、可写 fileHandler.setFormatter(formatter) streamHandler = logging.StreamHandler() streamHandler.setFormatter(formatter) diff --git a/source/tool.py b/source/tool.py index 6094bd9..6e3bc36 100755 --- a/source/tool.py +++ b/source/tool.py @@ -66,23 +66,14 @@ class Control(): # 因此仍然采用try-except实现而非if-else实现 try: # 存在存档即导入 + # 自动修复读写权限 + # Python权限规则和Unix不一样,420表示unix的644,Windows自动忽略不支持项 + os.chmod(c.USERDATA_PATH, 420) with open(c.USERDATA_PATH) as f: userdata = json.load(f) self.applyUserData(userdata) # 写入时也可能发生权限问题,因此放到try语句中 except FileNotFoundError: self.setupUserData() - except PermissionError: - logger.warning("用户存档文件不可读!程序将自动设置存档文件为可读状态!\n") - # Python权限规则和Unix不一样,420表示unix的655,Windows自动忽略不支持项 - os.chmod(c.USERDATA_PATH, 420) - try: - with open(c.USERDATA_PATH) as f: - userdata = json.load(f) - except json.JSONDecodeError: - logger.warning("用户存档解码错误!程序将新建初始存档!\n") - self.setupUserData() - else: - self.applyUserData(userdata) except json.JSONDecodeError: logger.warning("用户存档解码错误!程序将新建初始存档!\n") self.setupUserData() From 10711a5509c0dc2295918ef9a3c02235c9023eb9 Mon Sep 17 00:00:00 2001 From: wszqkzqk Date: Mon, 8 Aug 2022 12:29:14 +0800 Subject: [PATCH 09/32] =?UTF-8?q?=E5=87=8F=E5=B0=91try=E5=8C=85=E6=8B=AC?= =?UTF-8?q?=E7=9A=84=E8=AF=AD=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/tool.py | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/source/tool.py b/source/tool.py index 6e3bc36..b370c71 100755 --- a/source/tool.py +++ b/source/tool.py @@ -62,21 +62,31 @@ class Control(): self.state_dict = {} self.state_name = None self.state = None - # 这里需要考虑多种情况,如文件不存在、文件不可读、文件不符合JSON语法要求 - # 因此仍然采用try-except实现而非if-else实现 try: # 存在存档即导入 - # 自动修复读写权限 - # Python权限规则和Unix不一样,420表示unix的644,Windows自动忽略不支持项 + # 先自动修复读写权限(Python权限规则和Unix不一样,420表示unix的644,Windows自动忽略不支持项) os.chmod(c.USERDATA_PATH, 420) with open(c.USERDATA_PATH) as f: userdata = json.load(f) - self.applyUserData(userdata) # 写入时也可能发生权限问题,因此放到try语句中 except FileNotFoundError: self.setupUserData() except json.JSONDecodeError: logger.warning("用户存档解码错误!程序将新建初始存档!\n") self.setupUserData() + else: # 没有引发异常才执行 + self.game_info = {} + # 导入数据,保证了可运行性,但是放弃了数据向后兼容性,即假如某些变量在以后改名,在导入时可能会被重置 + need_to_rewrite = False + for key in c.INIT_USERDATA: + if key in userdata: + self.game_info[key] = userdata[key] + else: + self.game_info[key] = c.INIT_USERDATA[key] + need_to_rewrite = True + if need_to_rewrite: + with open(c.USERDATA_PATH, "w") as f: + savedata = json.dumps(self.game_info, sort_keys=True, indent=4) + f.write(savedata) # 存档内不包含即时游戏时间信息,需要新建 self.game_info[c.CURRENT_TIME] = 0 @@ -91,21 +101,6 @@ class Control(): f.write(savedata) self.game_info = c.INIT_USERDATA.copy() # 内部全是不可变对象,浅拷贝即可 - def applyUserData(self, userdata): - self.game_info = {} - # 导入数据,保证了可运行性,但是放弃了数据向后兼容性,即假如某些变量在以后改名,在导入时可能会被重置 - need_to_rewrite = False - for key in c.INIT_USERDATA: - if key in userdata: - self.game_info[key] = userdata[key] - else: - self.game_info[key] = c.INIT_USERDATA[key] - need_to_rewrite = True - if need_to_rewrite: - with open(c.USERDATA_PATH, "w") as f: - savedata = json.dumps(self.game_info, sort_keys=True, indent=4) - f.write(savedata) - def setup_states(self, state_dict, start_state): self.state_dict = state_dict self.state_name = start_state From f37f05b72648af77e7725befc7c32db8dbed57ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=A4=96=E4=B9=8B=E7=A5=9E?= Date: Mon, 8 Aug 2022 16:27:48 +0800 Subject: [PATCH 10/32] =?UTF-8?q?=E6=94=B9=E7=94=A8=E6=8E=A8=E5=AF=BC?= =?UTF-8?q?=E5=BC=8F=E4=BB=A5=E4=BE=BFpylance=E6=98=8E=E7=A1=AE=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/component/menubar.py | 4 +--- source/constants.py | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/source/component/menubar.py b/source/component/menubar.py index 19acedd..c990700 100755 --- a/source/component/menubar.py +++ b/source/component/menubar.py @@ -22,9 +22,7 @@ def getSunValueImage(sun_value): return image def getCardPool(data): - card_pool = {} - for cardName in data: - card_pool[c.PLANT_CARD_INFO[c.PLANT_CARD_INDEX[cardName]]] = data[cardName] + card_pool = {c.PLANT_CARD_INFO[c.PLANT_CARD_INDEX[card_name]]: data[card_name] for card_name in data} return card_pool class Card(): diff --git a/source/constants.py b/source/constants.py index 7579e88..df09fea 100755 --- a/source/constants.py +++ b/source/constants.py @@ -376,9 +376,7 @@ PLANT_CARD_INFO = (# 元组 (植物名称, 卡片名称, 阳光, 冷却时间) ) # 卡片中的植物名称与索引序号的对应关系,指定名称以得到索引值 -PLANT_CARD_INDEX={} -for i, item in enumerate(PLANT_CARD_INFO): - PLANT_CARD_INDEX[item[PLANT_NAME_INDEX]] = i +PLANT_CARD_INDEX={item[PLANT_NAME_INDEX]: index for (index, item) in enumerate(PLANT_CARD_INFO)} # 指定了哪些卡可选(排除坚果保龄球特殊植物) CARDS_TO_CHOOSE = range(len(PLANT_CARD_INFO) - 3) From 2376922a77692c2f82425af3338933cd87f1b263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=A4=96=E4=B9=8B=E7=A5=9E?= Date: Mon, 8 Aug 2022 17:34:15 +0800 Subject: [PATCH 11/32] =?UTF-8?q?=E6=8C=87=E5=AE=9A=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/tool.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/tool.py b/source/tool.py index b370c71..30b6dc6 100755 --- a/source/tool.py +++ b/source/tool.py @@ -41,7 +41,7 @@ class State(): # 工具:用户数据保存函数 def saveUserData(self): - with open(c.USERDATA_PATH, "w") as f: + with open(c.USERDATA_PATH, "w", encoding="utf-8") as f: userdata = {} for i in self.game_info: if i in c.INIT_USERDATA: @@ -66,7 +66,7 @@ class Control(): # 存在存档即导入 # 先自动修复读写权限(Python权限规则和Unix不一样,420表示unix的644,Windows自动忽略不支持项) os.chmod(c.USERDATA_PATH, 420) - with open(c.USERDATA_PATH) as f: + with open(c.USERDATA_PATH, encoding="utf-8") as f: userdata = json.load(f) except FileNotFoundError: self.setupUserData() @@ -84,7 +84,7 @@ class Control(): self.game_info[key] = c.INIT_USERDATA[key] need_to_rewrite = True if need_to_rewrite: - with open(c.USERDATA_PATH, "w") as f: + with open(c.USERDATA_PATH, "w", encoding="utf-8") as f: savedata = json.dumps(self.game_info, sort_keys=True, indent=4) f.write(savedata) # 存档内不包含即时游戏时间信息,需要新建 @@ -96,7 +96,7 @@ class Control(): def setupUserData(self): if not os.path.exists(os.path.dirname(c.USERDATA_PATH)): os.makedirs(os.path.dirname(c.USERDATA_PATH)) - with open(c.USERDATA_PATH, "w") as f: + with open(c.USERDATA_PATH, "w", encoding="utf-8") as f: savedata = json.dumps(c.INIT_USERDATA, sort_keys=True, indent=4) f.write(savedata) self.game_info = c.INIT_USERDATA.copy() # 内部全是不可变对象,浅拷贝即可 From baeb003f5fee2d6f16ac24f2a31eb4a63870e02a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=A4=96=E4=B9=8B=E7=A5=9E?= Date: Mon, 8 Aug 2022 18:26:46 +0800 Subject: [PATCH 12/32] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8D=A1=E7=89=87?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/component/menubar.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/source/component/menubar.py b/source/component/menubar.py index c990700..9a17f63 100755 --- a/source/component/menubar.py +++ b/source/component/menubar.py @@ -83,7 +83,7 @@ class Card(): # 有关是否满足冷却与阳光条件的图片形式 time = current_time - self.frozen_timer if time < self.frozen_time: #cool down status - image = pg.Surface([self.rect.w, self.rect.h]) + image = pg.Surface((self.rect.w, self.rect.h)) # 黑底 # 在冷却时间不足且阳光也不足时,叠加两者效果显示,即同时改变透明度与图像覆盖 if self.sun_cost > sun_value: image.set_alpha(192) @@ -98,8 +98,11 @@ class Card(): image = self.orig_image.copy() image.set_alpha(192) elif self.clicked: - image = self.orig_image.copy() - image.set_alpha(128) + image = pg.Surface((self.rect.w, self.rect.h)) # 黑底 + chosen_image = self.orig_image.copy() + chosen_image.set_alpha(128) + + image.blit(chosen_image, (0,0), (0, 0, self.rect.w, self.rect.h)) else: image = self.orig_image return image @@ -355,14 +358,21 @@ class MoveCard(): # 新增卡片时显示图片 if self.rect.w < self.orig_rect.w: #create a part card image image = pg.Surface([self.rect.w, self.rect.h]) + if self.clicked: + self.orig_image.set_alpha(128) + else: + self.orig_image.set_alpha(255) image.blit(self.orig_image, (0, 0), (0, 0, self.rect.w, self.rect.h)) self.rect.w += 1 else: - image = self.orig_image - if self.clicked: - image.set_alpha(192) - else: - image.set_alpha(255) + if self.clicked: + image = pg.Surface([self.rect.w, self.rect.h]) # 黑底 + self.orig_image.set_alpha(128) + + image.blit(self.orig_image, (0,0), (0, 0, self.rect.w, self.rect.h)) + else: + self.orig_image.set_alpha(255) + image = self.orig_image return image def update(self, left_x, current_time): From 544560c49e301e41146c8e883e5563712218b9ba Mon Sep 17 00:00:00 2001 From: wszqkzqk Date: Mon, 8 Aug 2022 23:08:03 +0800 Subject: [PATCH 13/32] =?UTF-8?q?=E9=87=8D=E6=9E=84=E8=A1=A8=E8=BE=BE?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/component/map.py | 42 +++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/source/component/map.py b/source/component/map.py index 93003e1..35beed4 100755 --- a/source/component/map.py +++ b/source/component/map.py @@ -10,27 +10,50 @@ class Map(): self.width = c.GRID_POOL_X_LEN self.height = c.GRID_POOL_Y_LEN self.grid_height_size = c.GRID_POOL_Y_SIZE - self.map = [[(self.initMapGrid(c.MAP_GRASS), self.initMapGrid(c.MAP_WATER))[y in {2, 3}] for x in range(self.width)] for y in range(self.height)] + self.map = [ [self.initMapGrid(c.MAP_WATER) if 2 <= y <= 3 + else self.initMapGrid(c.MAP_GRASS) + for x in range(self.width) + ] + for y in range(self.height) + ] elif self.background_type in c.ON_ROOF_BACKGROUNDS: self.width = c.GRID_ROOF_X_LEN self.height = c.GRID_ROOF_Y_LEN self.grid_height_size = c.GRID_ROOF_Y_SIZE - self.map = [[self.initMapGrid(c.MAP_TILE) for x in range(self.width)] for y in range(self.height)] + self.map = [ [self.initMapGrid(c.MAP_TILE) + for x in range(self.width) + ] + for y in range(self.height) + ] elif self.background_type == c.BACKGROUND_SINGLE: self.width = c.GRID_X_LEN self.height = c.GRID_Y_LEN self.grid_height_size = c.GRID_Y_SIZE - self.map = [[(self.initMapGrid(c.MAP_UNAVAILABLE), self.initMapGrid(c.MAP_GRASS))[y == 2] for x in range(self.width)] for y in range(self.height)] + self.map = [ [self.initMapGrid(c.MAP_GRASS) if y ==2 + else self.initMapGrid(c.MAP_UNAVAILABLE) + for x in range(self.width) + ] + for y in range(self.height) + ] elif self.background_type == c.BACKGROUND_TRIPLE: self.width = c.GRID_X_LEN self.height = c.GRID_Y_LEN self.grid_height_size = c.GRID_Y_SIZE - self.map = [[(self.initMapGrid(c.MAP_UNAVAILABLE), self.initMapGrid(c.MAP_GRASS))[y in {1, 2, 3}] for x in range(self.width)] for y in range(self.height)] + self.map = [ [self.initMapGrid(c.MAP_GRASS) if 1 <= y <= 3 + else self.initMapGrid(c.MAP_UNAVAILABLE) + for x in range(self.width) + ] + for y in range(self.height) + ] else: self.width = c.GRID_X_LEN self.height = c.GRID_Y_LEN self.grid_height_size = c.GRID_Y_SIZE - self.map = [[self.initMapGrid(c.MAP_GRASS) for x in range(self.width)] for y in range(self.height)] + self.map = [ [self.initMapGrid(c.MAP_GRASS) + for x in range(self.width) + ] + for y in range(self.height) + ] def isValid(self, map_x, map_y): if (map_x < 0 or map_x >= self.width or @@ -50,12 +73,14 @@ class Map(): def isAvailable(self, map_x, map_y, plant_name): # 咖啡豆和墓碑吞噬者的判别最为特殊 if plant_name == c.COFFEEBEAN: - if self.map[map_y][map_x][c.MAP_SLEEP] and (plant_name not in self.map[map_y][map_x][c.MAP_PLANT]): + if (self.map[map_y][map_x][c.MAP_SLEEP] + and (plant_name not in self.map[map_y][map_x][c.MAP_PLANT])): return True else: return False if plant_name == c.GRAVEBUSTER: - if (c.GRAVE in self.map[map_y][map_x][c.MAP_PLANT] and (plant_name not in self.map[map_y][map_x][c.MAP_PLANT])): + if (c.GRAVE in self.map[map_y][map_x][c.MAP_PLANT] + and (plant_name not in self.map[map_y][map_x][c.MAP_PLANT])): return True else: return False @@ -70,7 +95,8 @@ class Map(): elif (all((i in {"花盆(未实现)", c.PUMPKINHEAD}) for i in self.map[map_y][map_x][c.MAP_PLANT]) and (plant_name not in self.map[map_y][map_x][c.MAP_PLANT])): # 例外植物:集合中填花盆和南瓜头,只要这里没有这种植物就能种植 return True - elif (plant_name == c.PUMPKINHEAD) and (c.PUMPKINHEAD not in self.map[map_y][map_x][c.MAP_PLANT]): # 没有南瓜头就能种南瓜头 + elif ((plant_name == c.PUMPKINHEAD) + and (c.PUMPKINHEAD not in self.map[map_y][map_x][c.MAP_PLANT])): # 没有南瓜头就能种南瓜头 return True else: return False From 9e01c018e4701d6eacb3a6678cff78c630a15045 Mon Sep 17 00:00:00 2001 From: wszqkzqk Date: Mon, 8 Aug 2022 23:59:17 +0800 Subject: [PATCH 14/32] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E7=BC=A0=E7=BB=95?= =?UTF-8?q?=E6=B5=B7=E8=8D=89=E6=94=BB=E5=87=BB=E8=8C=83=E5=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/component/map.py | 6 ++++-- source/component/plant.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/source/component/map.py b/source/component/map.py index 35beed4..b4243d2 100755 --- a/source/component/map.py +++ b/source/component/map.py @@ -112,7 +112,8 @@ class Map(): return False else: return True - elif (plant_name == c.PUMPKINHEAD) and (c.PUMPKINHEAD not in self.map[map_y][map_x][c.MAP_PLANT]): # 有花盆且没有南瓜头就能种南瓜头 + elif ((plant_name == c.PUMPKINHEAD) + and (c.PUMPKINHEAD not in self.map[map_y][map_x][c.MAP_PLANT])): # 有花盆且没有南瓜头就能种南瓜头 return True else: return False @@ -136,7 +137,8 @@ class Map(): return False else: return True - elif (plant_name == c.PUMPKINHEAD) and (c.PUMPKINHEAD not in self.map[map_y][map_x][c.MAP_PLANT]): # 在睡莲上且没有南瓜头就能种南瓜头 + elif ((plant_name == c.PUMPKINHEAD) + and (c.PUMPKINHEAD not in self.map[map_y][map_x][c.MAP_PLANT])): # 在睡莲上且没有南瓜头就能种南瓜头 return True else: return False diff --git a/source/component/plant.py b/source/component/plant.py index d3bf123..8c85334 100755 --- a/source/component/plant.py +++ b/source/component/plant.py @@ -1474,7 +1474,7 @@ class TangleKlep(Plant): def canAttack(self, zombie): if zombie.state != c.DIE and (not zombie.losthead): # 这里碰撞应当比碰撞一般更容易,就设置成圆形或矩形模式,不宜采用mask - if pg.sprite.collide_circle_ratio(0.7)(zombie, self): + if pg.sprite.collide_rect_ratio(1)(zombie, self): return True return False From b7b69cec612fc49e5afb30344c5906b9d4cd2571 Mon Sep 17 00:00:00 2001 From: wszqkzqk Date: Tue, 9 Aug 2022 05:46:06 +0800 Subject: [PATCH 15/32] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E5=8D=A1=E7=89=87?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/component/menubar.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/source/component/menubar.py b/source/component/menubar.py index 9a17f63..52bd69b 100755 --- a/source/component/menubar.py +++ b/source/component/menubar.py @@ -56,8 +56,8 @@ class Card(): def checkMouseClick(self, mouse_pos): x, y = mouse_pos - if(x >= self.rect.x and x <= self.rect.right and - y >= self.rect.y and y <= self.rect.bottom): + if (self.rect.x <= x <= self.rect.right and + self.rect.y <= y <= self.rect.bottom): return True return False @@ -84,27 +84,27 @@ class Card(): time = current_time - self.frozen_timer if time < self.frozen_time: #cool down status image = pg.Surface((self.rect.w, self.rect.h)) # 黑底 - # 在冷却时间不足且阳光也不足时,叠加两者效果显示,即同时改变透明度与图像覆盖 - if self.sun_cost > sun_value: - image.set_alpha(192) - frozen_image = self.orig_image.copy() + frozen_image = self.orig_image frozen_image.set_alpha(128) frozen_height = (self.frozen_time - time)/self.frozen_time * self.rect.h image.blit(frozen_image, (0,0), (0, 0, self.rect.w, frozen_height)) + self.orig_image.set_alpha(192) image.blit(self.orig_image, (0,frozen_height), (0, frozen_height, self.rect.w, self.rect.h - frozen_height)) elif self.sun_cost > sun_value: #disable status - image = self.orig_image.copy() - image.set_alpha(192) + image = pg.Surface((self.rect.w, self.rect.h)) # 黑底 + self.orig_image.set_alpha(192) + image.blit(self.orig_image, (0,0), (0, 0, self.rect.w, self.rect.h)) elif self.clicked: image = pg.Surface((self.rect.w, self.rect.h)) # 黑底 - chosen_image = self.orig_image.copy() + chosen_image = self.orig_image chosen_image.set_alpha(128) image.blit(chosen_image, (0,0), (0, 0, self.rect.w, self.rect.h)) else: image = self.orig_image + image.set_alpha(255) return image def update(self, sun_value, current_time): From 08ec7e2d0015c57f341fe7a6f55e8016d2500c30 Mon Sep 17 00:00:00 2001 From: wszqkzqk Date: Tue, 9 Aug 2022 11:01:57 +0800 Subject: [PATCH 16/32] =?UTF-8?q?=E5=B9=B3=E8=A1=A1=E9=9A=BE=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/component/map.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/component/map.py b/source/component/map.py index b4243d2..87b6d40 100755 --- a/source/component/map.py +++ b/source/component/map.py @@ -276,7 +276,8 @@ LEVEL_MAP_DATA = ( c.INIT_SUN_NAME: 50, c.SHOVEL: 1, c.SPAWN_ZOMBIES:c.SPAWN_ZOMBIES_AUTO, - c.INCLUDED_ZOMBIES: (c.NORMAL_ZOMBIE, c.CONEHEAD_ZOMBIE, c.POLE_VAULTING_ZOMBIE, c.BUCKETHEAD_ZOMBIE), + c.INCLUDED_ZOMBIES: ( c.NORMAL_ZOMBIE, c.CONEHEAD_ZOMBIE, + c.POLE_VAULTING_ZOMBIE, c.BUCKETHEAD_ZOMBIE), c.NUM_FLAGS:3 }, # 第6关 目前夜晚第一关 @@ -473,7 +474,7 @@ LITTLE_GAME_MAP_DATA = ( c.SPIKEWEED: 100, c.SQUASH: 100, c.JALAPENO: 50, - c.THREEPEASHOOTER: 300,} + c.THREEPEASHOOTER: 400,} }, # 第5关 坚果保龄球2 { From 777e937d986d4ffe7bc7492c02275cc6a5df625b Mon Sep 17 00:00:00 2001 From: wszqkzqk Date: Tue, 9 Aug 2022 20:23:47 +0800 Subject: [PATCH 17/32] =?UTF-8?q?=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/component/plant.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/source/component/plant.py b/source/component/plant.py index 8c85334..a4e4a59 100755 --- a/source/component/plant.py +++ b/source/component/plant.py @@ -1279,18 +1279,20 @@ class TorchWood(Plant): def idling(self): for i in self.bullet_group: - if i.name == c.BULLET_PEA: - if i.passed_torchwood_x != self.rect.centerx: - if abs(i.rect.centerx - self.rect.centerx) <= 20: - self.bullet_group.add(Bullet(i.rect.x, i.rect.y, i.dest_y, - c.BULLET_FIREBALL, c.BULLET_DAMAGE_FIREBALL_BODY, effect=c.BULLET_EFFECT_UNICE, passed_torchwood_x=self.rect.centerx)) - i.kill() - elif i.name == c.BULLET_PEA_ICE: - if i.passed_torchwood_x != self.rect.centerx: - if abs(i.rect.centerx - self.rect.centerx) <= 20: - self.bullet_group.add(Bullet(i.rect.x, i.rect.y, i.dest_y, - c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, effect=None, passed_torchwood_x=self.rect.centerx)) - i.kill() + if (i.name == c.BULLET_PEA + and i.passed_torchwood_x != self.rect.centerx + and abs(i.rect.centerx - self.rect.centerx) <= 20): + self.bullet_group.add(Bullet(i.rect.x, i.rect.y, i.dest_y, + c.BULLET_FIREBALL, c.BULLET_DAMAGE_FIREBALL_BODY, + effect=c.BULLET_EFFECT_UNICE, passed_torchwood_x=self.rect.centerx)) + i.kill() + elif (i.name == c.BULLET_PEA_ICE + and i.passed_torchwood_x != self.rect.centerx + and abs(i.rect.centerx - self.rect.centerx)): + self.bullet_group.add(Bullet(i.rect.x, i.rect.y, i.dest_y, + c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, + effect=None, passed_torchwood_x=self.rect.centerx)) + i.kill() class StarFruit(Plant): def __init__(self, x, y, bullet_group, level): From da1eb139463c6a4390dd1576bb11babf500974c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=A4=96=E4=B9=8B=E7=A5=9E?= Date: Wed, 10 Aug 2022 10:30:08 +0800 Subject: [PATCH 18/32] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=AF=E8=AF=BB?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pypvz.py | 2 +- source/constants.py | 2 +- source/state/level.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pypvz.py b/pypvz.py index 58be596..dffe61c 100755 --- a/pypvz.py +++ b/pypvz.py @@ -17,7 +17,7 @@ if __name__ == "__main__": os.makedirs(os.path.dirname(c.USERLOG_PATH)) logger = logging.getLogger("main") formatter = logging.Formatter("%(asctime)s - %(levelname)s: %(message)s") - fileHandler = RotatingFileHandler(c.USERLOG_PATH, "a", 1024*1024, 0, "utf-8") + fileHandler = RotatingFileHandler(c.USERLOG_PATH, "a", 1_000_000, 0, "utf-8") os.chmod(c.USERLOG_PATH, 420) # 设置日志文件权限,Unix为644,Windows为可读、可写 fileHandler.setFormatter(formatter) streamHandler = logging.StreamHandler() diff --git a/source/constants.py b/source/constants.py index df09fea..ceae9c5 100755 --- a/source/constants.py +++ b/source/constants.py @@ -480,7 +480,7 @@ FUME = "Fume" # 子弹伤害 BULLET_DAMAGE_NORMAL = 20 BULLET_DAMAGE_FIREBALL_BODY = 27 # 这是火球本体的伤害,注意不是40,本体(27) + 溅射(13)才是40 -BULLET_DAMAGE_FIREBALL_RANGE = 13 +BULLET_DAMAGE_FIREBALL_RANGE = 13 # 原版溅射伤害会随着僵尸数量增多而减少,这里相当于做了一个增强 # 子弹效果 BULLET_EFFECT_ICE = "ice" BULLET_EFFECT_UNICE = "unice" diff --git a/source/state/level.py b/source/state/level.py index 9a41d24..1602ead 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -101,7 +101,7 @@ class Level(tool.State): # 按照规则生成每一波僵尸 - # 可以考虑将波刷新和一波中的僵尸生成分开 + # 将波刷新和一波中的僵尸生成分开 # useableZombie是指可用的僵尸种类的元组 # inevitableZombie指在本轮必然出现的僵尸,输入形式为字典: {波数1:(僵尸1, 僵尸2……), 波数2:(僵尸1, 僵尸2……)……} def createWaves(self, useable_zombies, num_flags, survival_rounds=0, inevitable_zombie_dict=None): @@ -126,7 +126,7 @@ class Level(tool.State): zombie_list.append(c.FLAG_ZOMBIE) zombie_volume -= c.CREATE_ZOMBIE_DICT[c.FLAG_ZOMBIE][0] - # 保龄球模式应当增大僵尸容量 + # 传送带模式应当增大僵尸容量 if (self.bar_type != c.CHOOSEBAR_STATIC): zombie_volume += 2 From 5f83d8c80561d1041bd80e42c10ee7f5eab94e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=A4=96=E4=B9=8B=E7=A5=9E?= Date: Wed, 10 Aug 2022 10:47:54 +0800 Subject: [PATCH 19/32] =?UTF-8?q?=E5=85=B3=E5=8D=A1=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 79d8a7a..6f8a8fe 100644 --- a/README.md +++ b/README.md @@ -87,10 +87,11 @@ python pypvz.py * 泳池模式:9~11 * 浓雾模式(暂时没有雾):12 * 小游戏模式: - * 坚果保龄球模式:1 + * 坚果保龄球:1 * 传送带模式(白天):2 * 传送带模式(黑夜):3 * 传送带模式(泳池):4 + * 坚果保龄球(II):5 * 目前暂时按照以上设定,未与原版相符 * 可以通过修改存档JSON文件中的`game rate`值来调节游戏速度倍率 From 23824233df2c5ad4b5502852b88f27811ddbaa85 Mon Sep 17 00:00:00 2001 From: wszqkzqk Date: Wed, 10 Aug 2022 20:26:30 +0800 Subject: [PATCH 20/32] =?UTF-8?q?=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/component/plant.py | 79 ++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 26 deletions(-) diff --git a/source/component/plant.py b/source/component/plant.py index a4e4a59..813137c 100755 --- a/source/component/plant.py +++ b/source/component/plant.py @@ -178,9 +178,12 @@ class Fume(pg.sprite.Sprite): # 杨桃的子弹 class StarBullet(Bullet): - def __init__(self, x, start_y, damage, direction, level, damage_type = c.ZOMBIE_DEAFULT_DAMAGE): # direction指星星飞行方向 - Bullet.__init__(self, x, start_y, start_y, c.BULLET_STAR, damage, damage_type = damage_type) - + def __init__( self, x, start_y, + damage, direction, + level, damage_type = c.ZOMBIE_DEAFULT_DAMAGE): # direction指星星飞行方向 + Bullet.__init__( self, x, start_y, + start_y, c.BULLET_STAR, + damage, damage_type = damage_type) self.level = level self.map_y = self.level.map.getMapIndex(self.rect.x, self.rect.centery)[1] self.direction = direction @@ -394,7 +397,8 @@ class SunFlower(Plant): self.sun_timer = self.current_time - (c.FLOWER_SUN_INTERVAL - 6000) elif (self.current_time - self.sun_timer) > c.FLOWER_SUN_INTERVAL: self.sun_group.add( - Sun(self.rect.centerx, self.rect.bottom, self.rect.right, self.rect.bottom + self.rect.h // 2)) + Sun( self.rect.centerx, self.rect.bottom, + self.rect.right, self.rect.bottom + self.rect.h // 2)) self.sun_timer = self.current_time @@ -697,8 +701,9 @@ class PuffShroom(Plant): def canAttack(self, zombie): if (zombie.name == c.SNORKELZOMBIE) and (zombie.frames == zombie.swim_frames): return False - if (self.rect.x <= zombie.rect.right and - (self.rect.x + c.GRID_X_SIZE * 4 >= zombie.rect.x) and (zombie.rect.left <= c.SCREEN_WIDTH + 10)): + if (self.rect.x <= zombie.rect.right + and (self.rect.x + c.GRID_X_SIZE * 4 >= zombie.rect.x) + and (zombie.rect.left <= c.SCREEN_WIDTH + 10)): return True return False @@ -796,7 +801,8 @@ class Squash(Plant): return True # 攻击状态 elif (self.state == c.ATTACK): - if pg.sprite.collide_rect_ratio(0.5)(zombie, self) or pg.sprite.collide_mask(zombie, self): + if (pg.sprite.collide_rect_ratio(0.5)(zombie, self) + or pg.sprite.collide_mask(zombie, self)): return True return False @@ -844,9 +850,12 @@ class Spikeweed(Plant): self.state = c.IDLE def canAttack(self, zombie): - # 地刺能不能扎的判据:僵尸中心与地刺中心的距离或僵尸包括了地刺中心和右端(平衡得到合理的攻击范围,"僵尸包括了地刺中心和右端"是为以后巨人做准备) + # 地刺能不能扎的判据: + # 僵尸中心与地刺中心的距离或僵尸包括了地刺中心和右端(平衡得到合理的攻击范围,"僵尸包括了地刺中心和右端"是为以后巨人做准备) # 暂时不能用碰撞判断,平衡性不好 - if ((-40 <= zombie.rect.centerx - self.rect.centerx <= 40) or (zombie.rect.left <= self.rect.x <= zombie.rect.right and zombie.rect.left <= self.rect.right <= zombie.rect.right)): + if ((-40 <= zombie.rect.centerx - self.rect.centerx <= 40) + or (zombie.rect.left <= self.rect.x <= zombie.rect.right + and zombie.rect.left <= self.rect.right <= zombie.rect.right)): return True return False @@ -1050,8 +1059,10 @@ class IceShroom(Plant): sleep_name = name + "Sleep" trap_name = name + "Trap" - frame_list = [self.idle_frames, self.snow_frames, self.sleep_frames, self.trap_frames] - name_list = [idle_name, snow_name, sleep_name, trap_name] + frame_list = [ self.idle_frames, self.snow_frames, + self.sleep_frames, self.trap_frames] + name_list = [ idle_name, snow_name, + sleep_name, trap_name] scale_list = [1, 1.5, 1, 1] for i, name in enumerate(name_list): @@ -1308,13 +1319,17 @@ class StarFruit(Plant): zombie_map_y = self.level.map.getMapIndex(zombie.rect.centerx, zombie.rect.bottom)[1] if (self.rect.x >= zombie.rect.x) and (self.map_y == zombie_map_y): # 对于同行且在杨桃后的僵尸 return True - # 斜向上,理想直线方程为:f(zombie.rect.x) = -0.75*(zombie.rect.x - (self.rect.right - 5)) + self.rect.y - 10 + # 斜向上,理想直线方程为: + # f(zombie.rect.x) = -0.75*(zombie.rect.x - (self.rect.right - 5)) + self.rect.y - 10 # 注意实际上为射线 - elif -100 <= (zombie.rect.y - (-0.75*(zombie.rect.x - (self.rect.right - 5)) + self.rect.y - 10)) <= 70 and (zombie.rect.left <= c.SCREEN_WIDTH) and (zombie.rect.x >= self.rect.x): + elif (-100 <= (zombie.rect.y - (-0.75*(zombie.rect.x - (self.rect.right - 5)) + self.rect.y - 10)) <= 70 + and (zombie.rect.left <= c.SCREEN_WIDTH) and (zombie.rect.x >= self.rect.x)): return True # 斜向下,理想直线方程为:f(zombie.rect.x) = zombie.rect.x + self.rect.y - self.rect.right - 15 # 注意实际上为射线 - elif abs(zombie.rect.y - (zombie.rect.x + self.rect.y - self.rect.right - 15)) <= 70 and (zombie.rect.left <= c.SCREEN_WIDTH) and (zombie.rect.x >= self.rect.x): + elif (abs(zombie.rect.y - (zombie.rect.x + self.rect.y - self.rect.right - 15)) <= 70 + and (zombie.rect.left <= c.SCREEN_WIDTH) + and (zombie.rect.x >= self.rect.x)): return True elif zombie.rect.left <= self.rect.x <= zombie.rect.right: return True @@ -1324,13 +1339,23 @@ class StarFruit(Plant): if self.shoot_timer == 0: self.shoot_timer = self.current_time - 700 elif (self.current_time - self.shoot_timer) >= 1400: - # 向后打的杨桃子弹无视铁门与报纸防具 - self.bullet_group.add(StarBullet(self.rect.left - 10, self.rect.y + 15, c.BULLET_DAMAGE_NORMAL, c.STAR_BACKWARD, self.level, damage_type = c.ZOMBIE_COMMON_DAMAGE)) + # pypvz特有设定:向后打的杨桃子弹无视铁门与报纸防具 + self.bullet_group.add(StarBullet( self.rect.left - 10, self.rect.y + 15, + c.BULLET_DAMAGE_NORMAL, c.STAR_BACKWARD, + self.level, damage_type = c.ZOMBIE_COMMON_DAMAGE)) # 其他方向的杨桃子弹伤害效果与豌豆等同 - self.bullet_group.add(StarBullet(self.rect.centerx - 20, self.rect.bottom - self.rect.h - 15, c.BULLET_DAMAGE_NORMAL, c.STAR_UPWARD, self.level)) - self.bullet_group.add(StarBullet(self.rect.centerx - 20, self.rect.bottom - 5, c.BULLET_DAMAGE_NORMAL, c.STAR_DOWNWARD, self.level)) - self.bullet_group.add(StarBullet(self.rect.right - 5, self.rect.bottom - 20, c.BULLET_DAMAGE_NORMAL, c.STAR_FORWARD_DOWN, self.level)) - self.bullet_group.add(StarBullet(self.rect.right - 5, self.rect.y - 10, c.BULLET_DAMAGE_NORMAL, c.STAR_FORWARD_UP, self.level)) + self.bullet_group.add(StarBullet( self.rect.centerx - 20, self.rect.bottom - self.rect.h - 15, + c.BULLET_DAMAGE_NORMAL, c.STAR_UPWARD, + self.level)) + self.bullet_group.add(StarBullet( self.rect.centerx - 20, self.rect.bottom - 5, + c.BULLET_DAMAGE_NORMAL, c.STAR_DOWNWARD, + self.level)) + self.bullet_group.add(StarBullet( self.rect.right - 5, self.rect.bottom - 20, + c.BULLET_DAMAGE_NORMAL, c.STAR_FORWARD_DOWN, + self.level)) + self.bullet_group.add(StarBullet( self.rect.right - 5, self.rect.y - 10, + c.BULLET_DAMAGE_NORMAL, c.STAR_FORWARD_UP, + self.level)) self.shoot_timer = self.current_time # 播放发射音效 c.SOUND_SHOOT.play() @@ -1358,8 +1383,8 @@ class CoffeeBean(Plant): for plant in self.plant_group: if plant.can_sleep: if plant.state == c.SLEEP: - plantMapX, _ = self.map.getMapIndex(plant.rect.centerx, plant.rect.bottom) - if plantMapX == self.map_x: + plant_map_x, _ = self.map.getMapIndex(plant.rect.centerx, plant.rect.bottom) + if plant_map_x == self.map_x: plant.state = c.IDLE plant.setIdle() plant.changeFrames(plant.idle_frames) @@ -1415,8 +1440,9 @@ class SeaShroom(Plant): def canAttack(self, zombie): if (zombie.name == c.SNORKELZOMBIE) and (zombie.frames == zombie.swim_frames): return False - if (self.rect.x <= zombie.rect.right and - (self.rect.x + c.GRID_X_SIZE * 4 >= zombie.rect.x) and (zombie.rect.left <= c.SCREEN_WIDTH + 10)): + if (self.rect.x <= zombie.rect.right + and (self.rect.x + c.GRID_X_SIZE * 4 >= zombie.rect.x) + and (zombie.rect.left <= c.SCREEN_WIDTH + 10)): return True return False @@ -1706,8 +1732,9 @@ class FumeShroom(Plant): def canAttack(self, zombie): if (zombie.name == c.SNORKELZOMBIE) and (zombie.frames == zombie.swim_frames): return False - if (self.rect.x <= zombie.rect.right and - (self.rect.x + c.GRID_X_SIZE * 5 >= zombie.rect.x) and (zombie.rect.left <= c.SCREEN_WIDTH + 10)): + if (self.rect.x <= zombie.rect.right + and (self.rect.x + c.GRID_X_SIZE * 5 >= zombie.rect.x) + and (zombie.rect.left <= c.SCREEN_WIDTH + 10)): return True return False From a0c8201d26e31e0bd6d1001676656be828bd8c5f Mon Sep 17 00:00:00 2001 From: wszqkzqk Date: Thu, 11 Aug 2022 10:42:30 +0800 Subject: [PATCH 21/32] =?UTF-8?q?=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/component/map.py | 8 ++++---- source/component/menubar.py | 26 ++++++++++++++------------ source/state/level.py | 4 +++- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/source/component/map.py b/source/component/map.py index 87b6d40..11af345 100755 --- a/source/component/map.py +++ b/source/component/map.py @@ -56,10 +56,10 @@ class Map(): ] def isValid(self, map_x, map_y): - if (map_x < 0 or map_x >= self.width or - map_y < 0 or map_y >= self.height): - return False - return True + if ((0 <= map_x < self.width) + and (0 <= map_y < self.height)): + return True + return False # 地图单元格状态 # 注意是可变对象,不能直接引用 diff --git a/source/component/menubar.py b/source/component/menubar.py index 52bd69b..96cf58d 100755 --- a/source/component/menubar.py +++ b/source/component/menubar.py @@ -22,7 +22,8 @@ def getSunValueImage(sun_value): return image def getCardPool(data): - card_pool = {c.PLANT_CARD_INFO[c.PLANT_CARD_INDEX[card_name]]: data[card_name] for card_name in data} + card_pool = {c.PLANT_CARD_INFO[c.PLANT_CARD_INDEX[card_name]]: data[card_name] + for card_name in data} return card_pool class Card(): @@ -36,7 +37,8 @@ class Card(): self.sun_cost_img = font.render(str(c.PLANT_CARD_INFO[index][c.SUN_INDEX]), True, c.BLACK) self.sun_cost_img_rect = self.sun_cost_img.get_rect() sun_cost_img_x = 32 - self.sun_cost_img_rect.w - self.orig_image.blit(self.sun_cost_img, (sun_cost_img_x, 52, self.sun_cost_img_rect.w, self.sun_cost_img_rect.h)) + self.orig_image.blit(self.sun_cost_img, + (sun_cost_img_x, 52, self.sun_cost_img_rect.w, self.sun_cost_img_rect.h)) self.index = index self.sun_cost = c.PLANT_CARD_INFO[index][c.SUN_INDEX] @@ -86,7 +88,7 @@ class Card(): image = pg.Surface((self.rect.w, self.rect.h)) # 黑底 frozen_image = self.orig_image frozen_image.set_alpha(128) - frozen_height = (self.frozen_time - time)/self.frozen_time * self.rect.h + frozen_height = ((self.frozen_time - time)/self.frozen_time) * self.rect.h image.blit(frozen_image, (0,0), (0, 0, self.rect.w, frozen_height)) self.orig_image.set_alpha(192) @@ -177,8 +179,8 @@ class MenuBar(): def checkMenuBarClick(self, mouse_pos): x, y = mouse_pos - if (x >= self.rect.x and x <= self.rect.right and - y >= self.rect.y and y <= self.rect.bottom): + if (self.rect.x <= x <= self.rect.right and + self.rect.y <= y <= self.rect.bottom): return True return False @@ -299,8 +301,8 @@ class Panel(): return False x, y = mouse_pos - if (x >= self.button_rect.x and x <= self.button_rect.right and - y >= self.button_rect.y and y <= self.button_rect.bottom): + if (self.button_rect.x <= x <= self.button_rect.right and + self.button_rect.y <= y <= self.button_rect.bottom): return True return False @@ -349,8 +351,8 @@ class MoveCard(): def checkMouseClick(self, mouse_pos): x, y = mouse_pos - if (x >= self.rect.x and x <= self.rect.right and - y >= self.rect.y and y <= self.rect.bottom): + if (self.rect.x <= x <= self.rect.right and + self.rect.y <= y <= self.rect.bottom): return True return False @@ -426,7 +428,7 @@ class MoveBar(): card.update(left_x, self.current_time) left_x = card.rect.right + 1 - if(self.current_time - self.create_timer) > c.MOVEBAR_CARD_FRESH_TIME: + if (self.current_time - self.create_timer) > c.MOVEBAR_CARD_FRESH_TIME: if self.createCard(): self.create_timer = self.current_time @@ -440,8 +442,8 @@ class MoveBar(): def checkMenuBarClick(self, mouse_pos): x, y = mouse_pos - if (x >= self.rect.x and x <= self.rect.right and - y >= self.rect.y and y <= self.rect.bottom): + if (self.rect.x <= x <= self.rect.right and + self.rect.y <= y <= self.rect.bottom): return True return False diff --git a/source/state/level.py b/source/state/level.py index 1602ead..3b2c848 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -26,6 +26,7 @@ class Level(tool.State): # 导入地图参数 self.loadMap() self.map = map.Map(self.map_data[c.BACKGROUND_TYPE]) + self.map_x_len = self.map.width self.map_y_len = self.map.height self.setupBackground() self.initState() @@ -1115,7 +1116,8 @@ class Level(tool.State): zombie.health = 0 c.SOUND_BOWLING_IMPACT.play() elif not zombie.jumping: - zombie.jump_map_x, zombie.jump_map_y = min(c.GRID_X_LEN - 1, zombie.prey_map_x), min(self.map_y_len - 1, zombie.prey_map_y) + zombie.jump_map_x = min(self.map_x_len - 1, zombie.prey_map_x) + zombie.jump_map_y = min(self.map_y_len - 1, zombie.prey_map_y) jump_x = target_plant.rect.x - c.GRID_X_SIZE * 0.6 if c.TALLNUT in self.map.map[zombie.jump_map_y][zombie.jump_map_x][c.MAP_PLANT]: zombie.setJump(False, jump_x) From f38e415add63146a9fb48d2869a800f4b070f2de 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, 11 Aug 2022 16:11:11 +0800 Subject: [PATCH 22/32] =?UTF-8?q?=E5=B0=86screen=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E4=B8=BA=E6=8A=BD=E8=B1=A1=E5=9F=BA=E7=B1=BB=EF=BC=9B=E9=87=8D?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/component/map.py | 8 ++++---- source/component/menubar.py | 26 ++++++++++++++------------ source/state/level.py | 4 +++- source/state/screen.py | 2 ++ 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/source/component/map.py b/source/component/map.py index 87b6d40..11af345 100755 --- a/source/component/map.py +++ b/source/component/map.py @@ -56,10 +56,10 @@ class Map(): ] def isValid(self, map_x, map_y): - if (map_x < 0 or map_x >= self.width or - map_y < 0 or map_y >= self.height): - return False - return True + if ((0 <= map_x < self.width) + and (0 <= map_y < self.height)): + return True + return False # 地图单元格状态 # 注意是可变对象,不能直接引用 diff --git a/source/component/menubar.py b/source/component/menubar.py index 52bd69b..96cf58d 100755 --- a/source/component/menubar.py +++ b/source/component/menubar.py @@ -22,7 +22,8 @@ def getSunValueImage(sun_value): return image def getCardPool(data): - card_pool = {c.PLANT_CARD_INFO[c.PLANT_CARD_INDEX[card_name]]: data[card_name] for card_name in data} + card_pool = {c.PLANT_CARD_INFO[c.PLANT_CARD_INDEX[card_name]]: data[card_name] + for card_name in data} return card_pool class Card(): @@ -36,7 +37,8 @@ class Card(): self.sun_cost_img = font.render(str(c.PLANT_CARD_INFO[index][c.SUN_INDEX]), True, c.BLACK) self.sun_cost_img_rect = self.sun_cost_img.get_rect() sun_cost_img_x = 32 - self.sun_cost_img_rect.w - self.orig_image.blit(self.sun_cost_img, (sun_cost_img_x, 52, self.sun_cost_img_rect.w, self.sun_cost_img_rect.h)) + self.orig_image.blit(self.sun_cost_img, + (sun_cost_img_x, 52, self.sun_cost_img_rect.w, self.sun_cost_img_rect.h)) self.index = index self.sun_cost = c.PLANT_CARD_INFO[index][c.SUN_INDEX] @@ -86,7 +88,7 @@ class Card(): image = pg.Surface((self.rect.w, self.rect.h)) # 黑底 frozen_image = self.orig_image frozen_image.set_alpha(128) - frozen_height = (self.frozen_time - time)/self.frozen_time * self.rect.h + frozen_height = ((self.frozen_time - time)/self.frozen_time) * self.rect.h image.blit(frozen_image, (0,0), (0, 0, self.rect.w, frozen_height)) self.orig_image.set_alpha(192) @@ -177,8 +179,8 @@ class MenuBar(): def checkMenuBarClick(self, mouse_pos): x, y = mouse_pos - if (x >= self.rect.x and x <= self.rect.right and - y >= self.rect.y and y <= self.rect.bottom): + if (self.rect.x <= x <= self.rect.right and + self.rect.y <= y <= self.rect.bottom): return True return False @@ -299,8 +301,8 @@ class Panel(): return False x, y = mouse_pos - if (x >= self.button_rect.x and x <= self.button_rect.right and - y >= self.button_rect.y and y <= self.button_rect.bottom): + if (self.button_rect.x <= x <= self.button_rect.right and + self.button_rect.y <= y <= self.button_rect.bottom): return True return False @@ -349,8 +351,8 @@ class MoveCard(): def checkMouseClick(self, mouse_pos): x, y = mouse_pos - if (x >= self.rect.x and x <= self.rect.right and - y >= self.rect.y and y <= self.rect.bottom): + if (self.rect.x <= x <= self.rect.right and + self.rect.y <= y <= self.rect.bottom): return True return False @@ -426,7 +428,7 @@ class MoveBar(): card.update(left_x, self.current_time) left_x = card.rect.right + 1 - if(self.current_time - self.create_timer) > c.MOVEBAR_CARD_FRESH_TIME: + if (self.current_time - self.create_timer) > c.MOVEBAR_CARD_FRESH_TIME: if self.createCard(): self.create_timer = self.current_time @@ -440,8 +442,8 @@ class MoveBar(): def checkMenuBarClick(self, mouse_pos): x, y = mouse_pos - if (x >= self.rect.x and x <= self.rect.right and - y >= self.rect.y and y <= self.rect.bottom): + if (self.rect.x <= x <= self.rect.right and + self.rect.y <= y <= self.rect.bottom): return True return False diff --git a/source/state/level.py b/source/state/level.py index 1602ead..3b2c848 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -26,6 +26,7 @@ class Level(tool.State): # 导入地图参数 self.loadMap() self.map = map.Map(self.map_data[c.BACKGROUND_TYPE]) + self.map_x_len = self.map.width self.map_y_len = self.map.height self.setupBackground() self.initState() @@ -1115,7 +1116,8 @@ class Level(tool.State): zombie.health = 0 c.SOUND_BOWLING_IMPACT.play() elif not zombie.jumping: - zombie.jump_map_x, zombie.jump_map_y = min(c.GRID_X_LEN - 1, zombie.prey_map_x), min(self.map_y_len - 1, zombie.prey_map_y) + zombie.jump_map_x = min(self.map_x_len - 1, zombie.prey_map_x) + zombie.jump_map_y = min(self.map_y_len - 1, zombie.prey_map_y) jump_x = target_plant.rect.x - c.GRID_X_SIZE * 0.6 if c.TALLNUT in self.map.map[zombie.jump_map_y][zombie.jump_map_x][c.MAP_PLANT]: zombie.setJump(False, jump_x) diff --git a/source/state/screen.py b/source/state/screen.py index 6837c0c..ea8fd6c 100644 --- a/source/state/screen.py +++ b/source/state/screen.py @@ -1,5 +1,6 @@ import os import pygame as pg +from abc import abstractmethod from .. import tool from .. import constants as c @@ -7,6 +8,7 @@ class Screen(tool.State): def __init__(self): tool.State.__init__(self) + @abstractmethod def startup(self, current_time, persist): pass From f46585264d260e83cfd495dbe3f51bcf6db7456a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=A4=96=E4=B9=8B=E7=A5=9E?= Date: Sun, 14 Aug 2022 10:53:40 +0800 Subject: [PATCH 23/32] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=93=B2=E5=AD=90?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E5=AF=BC=E8=87=B4=E7=9A=84=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E8=B6=8A=E7=95=8Cbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/state/level.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/state/level.py b/source/state/level.py index 3b2c848..f8d711f 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -632,6 +632,9 @@ class Level(tool.State): def shovelRemovePlant(self, mouse_pos): x, y = mouse_pos map_x, map_y = self.map.getMapIndex(x, y) + if ((map_y < 0) or (map_y >= self.map.height) + or (map_x < 0) or (map_x >= self.map.width)): + return for i in self.plant_groups[map_y]: if (x >= i.rect.x and x <= i.rect.right and y >= i.rect.y and y <= i.rect.bottom): @@ -1469,6 +1472,9 @@ class Level(tool.State): # 铲子接近植物时会高亮提示 map_x, map_y = self.map.getMapIndex(x, y) surface.blit(self.shovel, self.shovel_rect) + if ((map_y < 0) or (map_y >= self.map.height) + or (map_x < 0) or (map_x >= self.map.width)): + return for i in self.plant_groups[map_y]: if (x >= i.rect.x and x <= i.rect.right and y >= i.rect.y and y <= i.rect.bottom): From cf20f9733f2bf2c2ece63c0174ed8737763a88c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=A4=96=E4=B9=8B=E7=A5=9E?= Date: Sun, 14 Aug 2022 10:58:12 +0800 Subject: [PATCH 24/32] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9B=B4=E5=A4=9A?= =?UTF-8?q?=E7=9A=84=E5=9C=B0=E5=9B=BE=E8=B6=8A=E7=95=8Cbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/state/level.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/source/state/level.py b/source/state/level.py index f8d711f..46f38bf 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -333,8 +333,8 @@ class Level(tool.State): return self.before_pause_time def initBowlingMap(self): - for x in range(3, self.map.width): - for y in range(self.map.height): + for x in range(3, self.map_x_len): + for y in range(self.map_y_len): self.map.setMapGridType(x, y, c.MAP_UNAVAILABLE) # 将坚果保龄球红线右侧设置为不可种植任何植物 def initState(self): @@ -632,8 +632,8 @@ class Level(tool.State): def shovelRemovePlant(self, mouse_pos): x, y = mouse_pos map_x, map_y = self.map.getMapIndex(x, y) - if ((map_y < 0) or (map_y >= self.map.height) - or (map_x < 0) or (map_x >= self.map.width)): + if ((map_y < 0) or (map_y >= self.map_y_len) + or (map_x < 0) or (map_x >= self.map_x_len)): return for i in self.plant_groups[map_y]: if (x >= i.rect.x and x <= i.rect.right and @@ -1085,7 +1085,7 @@ class Level(tool.State): # 默认为最右侧的一个植物 target_plant = max(attackable_common_plants, key=lambda i: i.rect.x) map_x, map_y = self.map.getMapIndex(target_plant.rect.centerx, target_plant.rect.centery) - if not (map_x >= self.map.width or map_y >= self.map.height): + if (0 <= map_x < self.map_x_len and 0 <= map_y < self.map_y_len): if c.PUMPKINHEAD in self.map.map[map_y][map_x][c.MAP_PLANT]: for actual_target_plant in self.plant_groups[i]: # 检测同一格的其他植物 @@ -1472,8 +1472,8 @@ class Level(tool.State): # 铲子接近植物时会高亮提示 map_x, map_y = self.map.getMapIndex(x, y) surface.blit(self.shovel, self.shovel_rect) - if ((map_y < 0) or (map_y >= self.map.height) - or (map_x < 0) or (map_x >= self.map.width)): + if ((map_y < 0) or (map_y >= self.map_y_len) + or (map_x < 0) or (map_x >= self.map_x_len)): return for i in self.plant_groups[map_y]: if (x >= i.rect.x and x <= i.rect.right and From 57501a8f222dc2ea53c5f2eeca1dd3b35f2b78cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=A4=96=E4=B9=8B=E7=A5=9E?= Date: Sun, 14 Aug 2022 11:03:55 +0800 Subject: [PATCH 25/32] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E8=B6=8A=E7=95=8C?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/state/level.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/source/state/level.py b/source/state/level.py index 46f38bf..be0370e 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -632,8 +632,7 @@ class Level(tool.State): def shovelRemovePlant(self, mouse_pos): x, y = mouse_pos map_x, map_y = self.map.getMapIndex(x, y) - if ((map_y < 0) or (map_y >= self.map_y_len) - or (map_x < 0) or (map_x >= self.map_x_len)): + if not self.map.isValid(map_x, map_y): return for i in self.plant_groups[map_y]: if (x >= i.rect.x and x <= i.rect.right and @@ -1085,7 +1084,7 @@ class Level(tool.State): # 默认为最右侧的一个植物 target_plant = max(attackable_common_plants, key=lambda i: i.rect.x) map_x, map_y = self.map.getMapIndex(target_plant.rect.centerx, target_plant.rect.centery) - if (0 <= map_x < self.map_x_len and 0 <= map_y < self.map_y_len): + if self.map.isValid(map_x, map_y): if c.PUMPKINHEAD in self.map.map[map_y][map_x][c.MAP_PLANT]: for actual_target_plant in self.plant_groups[i]: # 检测同一格的其他植物 @@ -1472,8 +1471,7 @@ class Level(tool.State): # 铲子接近植物时会高亮提示 map_x, map_y = self.map.getMapIndex(x, y) surface.blit(self.shovel, self.shovel_rect) - if ((map_y < 0) or (map_y >= self.map_y_len) - or (map_x < 0) or (map_x >= self.map_x_len)): + if not self.map.isValid(map_x, map_y): return for i in self.plant_groups[map_y]: if (x >= i.rect.x and x <= i.rect.right and From 8ce2ccf734c7049e4cc6bb4786a213a8cfe5e6be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=A4=96=E4=B9=8B=E7=A5=9E?= Date: Tue, 30 Aug 2022 15:06:03 +0800 Subject: [PATCH 26/32] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/component/plant.py | 12 ++++++------ source/constants.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/component/plant.py b/source/component/plant.py index 813137c..60d88fe 100755 --- a/source/component/plant.py +++ b/source/component/plant.py @@ -1606,9 +1606,9 @@ class DoomShroom(Plant): # 用于描述毁灭菇的坑 class Hole(Plant): - def __init__(self, x, y, plotType): + def __init__(self, x, y, plot_type): # 指定区域类型这一句必须放在前面,否则加载图片判断将会失败 - self.plotType = plotType + self.plot_type = plot_type Plant.__init__(self, x, y, c.HOLE, c.INF, None) self.timer = 0 self.shallow = False @@ -1638,9 +1638,9 @@ class Hole(Plant): for i, name in enumerate(name_list): self.loadFrames(frame_list[i], name) - if self.plotType == c.MAP_TILE: + if self.plot_type == c.MAP_TILE: self.frames = self.roof_frames - elif self.plotType == c.MAP_WATER: + elif self.plot_type == c.MAP_WATER: self.frames = self.water_frames else: self.frames = self.idle_frames @@ -1649,9 +1649,9 @@ class Hole(Plant): if self.timer == 0: self.timer = self.current_time elif (not self.shallow) and (self.current_time - self.timer >= 90000): - if self.plotType == c.MAP_TILE: + if self.plot_type == c.MAP_TILE: self.frames = self.roof2_frames - elif self.plotType == c.MAP_WATER: + elif self.plot_type == c.MAP_WATER: self.frames = self.water2_frames else: self.frames = self.idle2_frames diff --git a/source/constants.py b/source/constants.py index ceae9c5..6eef56c 100755 --- a/source/constants.py +++ b/source/constants.py @@ -180,7 +180,7 @@ SURVIVAL_ROUNDS = "survival_rounds" # 地图单元格属性 MAP_PLANT = "plantnames" MAP_SLEEP = "sleep" # 有没有休眠的蘑菇,作是否能种植咖啡豆的判断 -MAP_PLOT_TYPE = "plotType" +MAP_PLOT_TYPE = "plot_type" # 地图单元格区域类型 MAP_GRASS = "grass" MAP_WATER = "water" From 2235f687dce278e85ba125e533910ab561f4bd63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=A4=96=E4=B9=8B=E7=A5=9E?= Date: Tue, 13 Sep 2022 16:02:12 +0800 Subject: [PATCH 27/32] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E9=80=89=E4=B8=AD?= =?UTF-8?q?=E5=8D=A1=E7=89=87=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/component/menubar.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/component/menubar.py b/source/component/menubar.py index 96cf58d..28774fd 100755 --- a/source/component/menubar.py +++ b/source/component/menubar.py @@ -74,9 +74,12 @@ class Card(): def setSelect(self, can_select): self.select = can_select if can_select: + self.image = self.orig_image self.image.set_alpha(255) else: - self.image.set_alpha(128) + self.orig_image.set_alpha(64) + self.image = pg.Surface((self.rect.w, self.rect.h)) # 黑底 + self.image.blit(self.orig_image, (0,0), (0, 0, self.rect.w, self.rect.h)) def setFrozenTime(self, current_time): self.frozen_timer = current_time @@ -286,7 +289,7 @@ class Panel(): c.SOUND_TAPPING_CARD.play() break - def addCard(self, card): + def addCard(self, card:Card): card.setSelect(False) y = 8 x = 77 + self.selected_num * c.BAR_CARD_X_INTERNAL From 37d8b29f603e8465cf09f2607f590aacebe7b9f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=A4=96=E4=B9=8B=E7=A5=9E?= Date: Tue, 13 Sep 2022 17:22:46 +0800 Subject: [PATCH 28/32] =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E5=85=B3=E5=8D=A1=E4=B8=8D=E6=8E=A8=E8=8D=90=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E7=9A=84=E5=8D=A1=E7=89=87=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/component/menubar.py | 59 +++++++++++++++++++++++++++++++------ source/constants.py | 11 +++++++ source/state/level.py | 2 +- 3 files changed, 62 insertions(+), 10 deletions(-) diff --git a/source/component/menubar.py b/source/component/menubar.py index 28774fd..65e1372 100755 --- a/source/component/menubar.py +++ b/source/component/menubar.py @@ -27,26 +27,35 @@ def getCardPool(data): return card_pool class Card(): - def __init__(self, x, y, index, scale=0.5): - self.loadFrame(c.PLANT_CARD_INFO[index][c.CARD_INDEX], scale) + def __init__(self, x:int, y:int, index:int, scale:float=0.5, not_recommend=0): + self.info = c.PLANT_CARD_INFO[index] + self.loadFrame(self.info[c.CARD_INDEX], scale) self.rect = self.orig_image.get_rect() self.rect.x = x self.rect.y = y # 绘制植物阳光消耗大小 font = pg.font.Font(c.FONT_PATH, 12) - self.sun_cost_img = font.render(str(c.PLANT_CARD_INFO[index][c.SUN_INDEX]), True, c.BLACK) + self.sun_cost_img = font.render(str(self.info[c.SUN_INDEX]), True, c.BLACK) self.sun_cost_img_rect = self.sun_cost_img.get_rect() sun_cost_img_x = 32 - self.sun_cost_img_rect.w self.orig_image.blit(self.sun_cost_img, (sun_cost_img_x, 52, self.sun_cost_img_rect.w, self.sun_cost_img_rect.h)) self.index = index - self.sun_cost = c.PLANT_CARD_INFO[index][c.SUN_INDEX] - self.frozen_time = c.PLANT_CARD_INFO[index][c.FROZEN_TIME_INDEX] + self.sun_cost = self.info[c.SUN_INDEX] + self.frozen_time = self.info[c.FROZEN_TIME_INDEX] self.frozen_timer = -self.frozen_time self.refresh_timer = 0 self.select = True self.clicked = False + self.not_recommend = not_recommend + if self.not_recommend: + self.orig_image.set_alpha(128) + self.image = pg.Surface((self.rect.w, self.rect.h)) # 黑底 + self.image.blit(self.orig_image, (0,0), (0, 0, self.rect.w, self.rect.h)) + else: + self.image = self.orig_image + self.image.set_alpha(255) def loadFrame(self, name, scale): frame = tool.GFX[name] @@ -74,8 +83,13 @@ class Card(): def setSelect(self, can_select): self.select = can_select if can_select: - self.image = self.orig_image - self.image.set_alpha(255) + if self.not_recommend: + self.orig_image.set_alpha(128) + self.image = pg.Surface((self.rect.w, self.rect.h)) # 黑底 + self.image.blit(self.orig_image, (0,0), (0, 0, self.rect.w, self.rect.h)) + else: + self.image = self.orig_image + self.image.set_alpha(255) else: self.orig_image.set_alpha(64) self.image = pg.Surface((self.rect.w, self.rect.h)) # 黑底 @@ -217,10 +231,11 @@ class MenuBar(): # 关卡模式选植物的界面 class Panel(): - def __init__(self, card_list, sun_value): + def __init__(self, card_list, sun_value, background_type=c.BACKGROUND_DAY): self.loadImages(sun_value) self.selected_cards = [] self.selected_num = 0 + self.background_type = background_type self.setupCards(card_list) def loadFrame(self, name): @@ -261,7 +276,20 @@ class Panel(): x = c.PANEL_X_START - c.PANEL_X_INTERNAL y += c.PANEL_Y_INTERNAL x += c.PANEL_X_INTERNAL - self.card_list.append(Card(x, y, index, 0.5)) + plant_name = c.PLANT_CARD_INFO[index][c.PLANT_NAME_INDEX] + if (plant_name in c.CAN_SLEEP_PLANTS + and self.background_type in c.DAYTIME_BACKGROUNDS): + not_recommend = c.REASON_WILL_SLEEP + elif (plant_name == c.GRAVEBUSTER + and self.background_type != c.BACKGROUND_NIGHT): + not_recommend = c.REASON_OTHER + elif (plant_name in c.WATER_PLANTS + and self.background_type not in c.POOL_EQUIPPED_BACKGROUNDS): + not_recommend = c.REASON_OTHER + # 还有屋顶场景,以及其他植物没有实现的植物没有写进来 + else: + not_recommend = 0 + self.card_list.append(Card(x, y, index, 0.5, not_recommend)) def checkCardClick(self, mouse_pos): delete_card = None @@ -277,6 +305,13 @@ class Panel(): self.selected_num -= 1 # 播放点击音效 c.SOUND_TAPPING_CARD.play() + if delete_card.info[c.PLANT_NAME_INDEX] == c.COFFEEBEAN: + for i in self.card_list: + if i.info[c.PLANT_NAME_INDEX] in c.CAN_SLEEP_PLANTS: + i.not_recommend = 1 + i.orig_image.set_alpha(128) + i.image = pg.Surface((i.rect.w, i.rect.h)) # 黑底 + i.image.blit(i.orig_image, (0,0), (0, 0, i.rect.w, i.rect.h)) if self.selected_num >= c.CARD_MAX_NUM: return @@ -287,6 +322,12 @@ class Panel(): self.addCard(card) # 播放点击音效 c.SOUND_TAPPING_CARD.play() + if card.info[c.PLANT_NAME_INDEX] == c.COFFEEBEAN: + for i in self.card_list: + if i.not_recommend == c.REASON_WILL_SLEEP: + i.not_recommend = 0 + i.image = i.orig_image + i.image.set_alpha(255) break def addCard(self, card:Card): diff --git a/source/constants.py b/source/constants.py index 6eef56c..b62c79d 100755 --- a/source/constants.py +++ b/source/constants.py @@ -443,6 +443,17 @@ ASH_PLANTS_AND_ICESHROOM = { ICESHROOM, } +# 白天要睡觉的植物 +CAN_SLEEP_PLANTS = { + PUFFSHROOM, SUNSHROOM, + FUMESHROOM, HYPNOSHROOM, + SCAREDYSHROOM, ICESHROOM, + DOOMSHROOM, SEASHROOM, +} + +# 选卡不推荐选择理由 +REASON_WILL_SLEEP = 1 +REASON_OTHER = 3 # 植物生命值 PLANT_HEALTH = 300 diff --git a/source/state/level.py b/source/state/level.py index be0370e..be808ae 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -355,7 +355,7 @@ class Level(tool.State): def initChoose(self): self.state = c.CHOOSE - self.panel = menubar.Panel(c.CARDS_TO_CHOOSE, self.map_data[c.INIT_SUN_NAME]) + self.panel = menubar.Panel(c.CARDS_TO_CHOOSE, self.map_data[c.INIT_SUN_NAME], self.background_type) # 播放选卡音乐 pg.mixer.music.stop() From 60911bebdd5e9fd7801e4676ed08f8355f4d7b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=A4=96=E4=B9=8B=E7=A5=9E?= Date: Tue, 13 Sep 2022 21:21:20 +0800 Subject: [PATCH 29/32] =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=86=97=E4=BD=99=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/component/plant.py | 11 +---------- source/state/level.py | 3 ++- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/source/component/plant.py b/source/component/plant.py index 60d88fe..53daeeb 100755 --- a/source/component/plant.py +++ b/source/component/plant.py @@ -241,7 +241,6 @@ class Plant(pg.sprite.Sprite): self.health = health self.state = c.IDLE self.bullet_group = bullet_group - self.can_sleep = False self.animate_timer = 0 self.animate_interval = 70 # 帧播放间隔 self.hit_timer = 0 @@ -670,7 +669,6 @@ class Chomper(Plant): class PuffShroom(Plant): def __init__(self, x, y, bullet_group): Plant.__init__(self, x, y, c.PUFFSHROOM, c.PLANT_HEALTH, bullet_group) - self.can_sleep = True self.shoot_timer = 0 def loadImages(self, name, scale): @@ -945,7 +943,6 @@ class Jalapeno(Plant): class ScaredyShroom(Plant): def __init__(self, x, y, bullet_group): Plant.__init__(self, x, y, c.SCAREDYSHROOM, c.PLANT_HEALTH, bullet_group) - self.can_sleep = True self.shoot_timer = 0 self.cry_x_range = c.GRID_X_SIZE * 1.5 @@ -999,7 +996,6 @@ class ScaredyShroom(Plant): class SunShroom(Plant): def __init__(self, x, y, sun_group): Plant.__init__(self, x, y, c.SUNSHROOM, c.PLANT_HEALTH, None) - self.can_sleep = True self.animate_interval = 140 self.sun_timer = 0 self.sun_group = sun_group @@ -1043,7 +1039,6 @@ class SunShroom(Plant): class IceShroom(Plant): def __init__(self, x, y): Plant.__init__(self, x, y, c.ICESHROOM, c.PLANT_HEALTH, None) - self.can_sleep = True self.orig_pos = (x, y) self.start_boom = False self.boomed = False @@ -1114,7 +1109,6 @@ class IceShroom(Plant): class HypnoShroom(Plant): def __init__(self, x, y): Plant.__init__(self, x, y, c.HYPNOSHROOM, c.PLANT_HEALTH, None) - self.can_sleep = True self.animate_interval = 80 self.zombie_to_hypno = None @@ -1381,7 +1375,7 @@ class CoffeeBean(Plant): if self.frame_index >= self.frame_num: self.map_content[c.MAP_SLEEP] = False for plant in self.plant_group: - if plant.can_sleep: + if plant.name in c.CAN_SLEEP_PLANTS: if plant.state == c.SLEEP: plant_map_x, _ = self.map.getMapIndex(plant.rect.centerx, plant.rect.bottom) if plant_map_x == self.map_x: @@ -1409,7 +1403,6 @@ class CoffeeBean(Plant): class SeaShroom(Plant): def __init__(self, x, y, bullet_group): Plant.__init__(self, x, y, c.SEASHROOM, c.PLANT_HEALTH, bullet_group) - self.can_sleep = True self.shoot_timer = 0 def loadImages(self, name, scale): @@ -1532,7 +1525,6 @@ class TangleKlep(Plant): class DoomShroom(Plant): def __init__(self, x, y, map_plant_set, explode_y_range): Plant.__init__(self, x, y, c.DOOMSHROOM, c.PLANT_HEALTH, None) - self.can_sleep = True self.map_plant_set = map_plant_set self.bomb_timer = 0 self.explode_y_range = explode_y_range @@ -1707,7 +1699,6 @@ class GraveBuster(Plant): class FumeShroom(Plant): def __init__(self, x, y, bullet_group, zombie_group): Plant.__init__(self, x, y, c.FUMESHROOM, c.PLANT_HEALTH, bullet_group) - self.can_sleep = True self.shoot_timer = 0 self.show_attack_frames = True self.zombie_group = zombie_group diff --git a/source/state/level.py b/source/state/level.py index be808ae..2dca7cc 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -927,7 +927,8 @@ class Level(tool.State): new_plant = plant.GiantWallNut(x, y) - if new_plant.can_sleep and self.background_type in c.DAYTIME_BACKGROUNDS: + if ((new_plant.name in c.CAN_SLEEP_PLANTS) + and (self.background_type in c.DAYTIME_BACKGROUNDS)): new_plant.setSleep() mushroom_sleep = True else: From f496e576fd8d38b6decf3cf7ea74d3ff5012d3d9 Mon Sep 17 00:00:00 2001 From: wszqkzqk Date: Wed, 14 Sep 2022 07:41:05 +0800 Subject: [PATCH 30/32] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E4=B8=8D=E6=8E=A8?= =?UTF-8?q?=E8=8D=90=E7=9A=84=E9=80=BB=E8=BE=91=E9=A1=BA=E5=BA=8F=EF=BC=8C?= =?UTF-8?q?=E9=98=B2=E6=AD=A2=E6=B5=B7=E8=98=91=E8=8F=87=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=BD=92=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/component/menubar.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/component/menubar.py b/source/component/menubar.py index 65e1372..5683de3 100755 --- a/source/component/menubar.py +++ b/source/component/menubar.py @@ -277,15 +277,15 @@ class Panel(): y += c.PANEL_Y_INTERNAL x += c.PANEL_X_INTERNAL plant_name = c.PLANT_CARD_INFO[index][c.PLANT_NAME_INDEX] - if (plant_name in c.CAN_SLEEP_PLANTS - and self.background_type in c.DAYTIME_BACKGROUNDS): - not_recommend = c.REASON_WILL_SLEEP + if (plant_name in c.WATER_PLANTS + and self.background_type not in c.POOL_EQUIPPED_BACKGROUNDS): + not_recommend = c.REASON_OTHER elif (plant_name == c.GRAVEBUSTER and self.background_type != c.BACKGROUND_NIGHT): not_recommend = c.REASON_OTHER - elif (plant_name in c.WATER_PLANTS - and self.background_type not in c.POOL_EQUIPPED_BACKGROUNDS): - not_recommend = c.REASON_OTHER + elif (plant_name in c.CAN_SLEEP_PLANTS + and self.background_type in c.DAYTIME_BACKGROUNDS): + not_recommend = c.REASON_WILL_SLEEP # 还有屋顶场景,以及其他植物没有实现的植物没有写进来 else: not_recommend = 0 From 5baf11a3f1bcf1087e113da194a46a79e20e88b9 Mon Sep 17 00:00:00 2001 From: wszqkzqk Date: Wed, 14 Sep 2022 07:49:05 +0800 Subject: [PATCH 31/32] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=A0=87=E5=BF=97?= =?UTF-8?q?=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/component/menubar.py | 8 ++++---- source/constants.py | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/source/component/menubar.py b/source/component/menubar.py index 5683de3..4e119a1 100755 --- a/source/component/menubar.py +++ b/source/component/menubar.py @@ -83,7 +83,7 @@ class Card(): def setSelect(self, can_select): self.select = can_select if can_select: - if self.not_recommend: + if self.not_recommend % 2: self.orig_image.set_alpha(128) self.image = pg.Surface((self.rect.w, self.rect.h)) # 黑底 self.image.blit(self.orig_image, (0,0), (0, 0, self.rect.w, self.rect.h)) @@ -307,8 +307,8 @@ class Panel(): c.SOUND_TAPPING_CARD.play() if delete_card.info[c.PLANT_NAME_INDEX] == c.COFFEEBEAN: for i in self.card_list: - if i.info[c.PLANT_NAME_INDEX] in c.CAN_SLEEP_PLANTS: - i.not_recommend = 1 + if i.not_recommend == c.REASON_SLEEP_BUT_COFFEE_BEAN: + i.not_recommend = c.REASON_WILL_SLEEP i.orig_image.set_alpha(128) i.image = pg.Surface((i.rect.w, i.rect.h)) # 黑底 i.image.blit(i.orig_image, (0,0), (0, 0, i.rect.w, i.rect.h)) @@ -325,7 +325,7 @@ class Panel(): if card.info[c.PLANT_NAME_INDEX] == c.COFFEEBEAN: for i in self.card_list: if i.not_recommend == c.REASON_WILL_SLEEP: - i.not_recommend = 0 + i.not_recommend = c.REASON_SLEEP_BUT_COFFEE_BEAN i.image = i.orig_image i.image.set_alpha(255) break diff --git a/source/constants.py b/source/constants.py index b62c79d..e27a7f8 100755 --- a/source/constants.py +++ b/source/constants.py @@ -453,6 +453,7 @@ CAN_SLEEP_PLANTS = { # 选卡不推荐选择理由 REASON_WILL_SLEEP = 1 +REASON_SLEEP_BUT_COFFEE_BEAN = 2 REASON_OTHER = 3 # 植物生命值 From 3f22446a85afd11ade72b66b24f98b50c731aaf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=A4=96=E4=B9=8B=E7=A5=9E?= Date: Wed, 14 Sep 2022 07:56:51 +0800 Subject: [PATCH 32/32] =?UTF-8?q?=E5=88=97=E5=85=A5=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E9=9D=A2=E5=90=91=E5=AF=B9=E8=B1=A1=E5=AE=9E=E7=8E=B0=E7=9A=84?= =?UTF-8?q?=E8=AE=A1=E5=88=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/constants.py | 1 + 1 file changed, 1 insertion(+) diff --git a/source/constants.py b/source/constants.py index e27a7f8..66d8c54 100755 --- a/source/constants.py +++ b/source/constants.py @@ -383,6 +383,7 @@ CARDS_TO_CHOOSE = range(len(PLANT_CARD_INFO) - 3) # 植物集体属性集合 +# 也许以后有必要的可以重新加入到对象的属性中 # 在生效时不用与僵尸进行碰撞检测的对象(即生效时不可发生被僵尸啃食的事件) SKIP_ZOMBIE_COLLISION_CHECK_WHEN_WORKING = { # 注意爆炸坚果的触发也是啃食类碰撞,因此只能算作爆炸后不检测