diff --git a/README.md b/README.md index 6cafb79..93fc2d9 100644 --- a/README.md +++ b/README.md @@ -96,10 +96,27 @@ python main.py - 对于`opus`编码,需要添加`libogg-0.dll`,`libopus-0.dll`和`libopusfile-0.dll` - 以添加`opus`和`vorbis`编码的背景音乐支持为例,编译需执行以下命令: -``` cmd +``` powershell git clone https://github.com/wszqkzqk/pypvz.git cd pypvz -nuitka --mingw64 --standalone --onefile --show-progress --show-memory --output-dir=out --windows-icon-from-ico=pypvz.ico --include-data-dir=resources=resources --include-data-file=C:\Users\17265\AppData\Local\Programs\Python\Python310\Lib\site-packages\pygame\libogg-0.dll=libogg-0.dll --include-data-file=C:\Users\17265\AppData\Local\Programs\Python\Python310\Lib\site-packages\pygame\libopus-0.dll=libopus-0.dll --include-data-file=C:\Users\17265\AppData\Local\Programs\Python\Python310\Lib\site-packages\pygame\libopusfile-0.dll=libopusfile-0.dll --include-data-file=C:\Users\17265\AppData\Local\Programs\Python\Python310\Lib\site-packages\pygame\libvorbisfile-3.dll=libvorbisfile-3.dll --include-data-file=C:\Users\17265\AppData\Local\Programs\Python\Python310\Lib\site-packages\pygame\libvorbis-0.dll=libvorbis-0.dll --windows-disable-console --windows-product-name=pypvz --windows-company-name=null --windows-file-description="pypvz" --windows-product-version=0.6.9.0 main.py +nuitka --mingw64 --standalone ` + --onefile ` + --show-progress ` + --show-memory ` + --output-dir=out ` + --windows-icon-from-ico=pypvz.ico ` + --include-data-dir=resources=resources ` + --include-data-file=C:\Users\17265\AppData\Local\Programs\Python\Python310\Lib\site-packages\pygame\libogg-0.dll=libogg-0.dll ` + --include-data-file=C:\Users\17265\AppData\Local\Programs\Python\Python310\Lib\site-packages\pygame\libopus-0.dll=libopus-0.dll ` + --include-data-file=C:\Users\17265\AppData\Local\Programs\Python\Python310\Lib\site-packages\pygame\libopusfile-0.dll=libopusfile-0.dll ` + --include-data-file=C:\Users\17265\AppData\Local\Programs\Python\Python310\Lib\site-packages\pygame\libvorbisfile-3.dll=libvorbisfile-3.dll ` + --include-data-file=C:\Users\17265\AppData\Local\Programs\Python\Python310\Lib\site-packages\pygame\libvorbis-0.dll=libvorbis-0.dll ` + --windows-disable-console ` + --windows-product-name=pypvz ` + --windows-company-name=null ` + --windows-file-description="pypvz" ` + --windows-product-version=0.6.9.0 ` + main.py ``` * 其中`C:\Users\17265\AppData\Local\Programs\Python\Python310\Lib\site-packages\pygame\xxx.dll`应当替换为`xxx.dll`实际所在路径 diff --git a/resources/graphics/Cards/card_garlic.png b/resources/graphics/Cards/card_garlic.png new file mode 100644 index 0000000..27e5520 Binary files /dev/null and b/resources/graphics/Cards/card_garlic.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic/Garlic_0.png b/resources/graphics/Plants/Garlic/Garlic/Garlic_0.png new file mode 100644 index 0000000..d28ace9 Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic/Garlic_0.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic/Garlic_1.png b/resources/graphics/Plants/Garlic/Garlic/Garlic_1.png new file mode 100644 index 0000000..2e301a2 Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic/Garlic_1.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic/Garlic_10.png b/resources/graphics/Plants/Garlic/Garlic/Garlic_10.png new file mode 100644 index 0000000..9baad3e Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic/Garlic_10.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic/Garlic_11.png b/resources/graphics/Plants/Garlic/Garlic/Garlic_11.png new file mode 100644 index 0000000..ccecfaa Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic/Garlic_11.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic/Garlic_2.png b/resources/graphics/Plants/Garlic/Garlic/Garlic_2.png new file mode 100644 index 0000000..7a75811 Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic/Garlic_2.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic/Garlic_3.png b/resources/graphics/Plants/Garlic/Garlic/Garlic_3.png new file mode 100644 index 0000000..1d98e4e Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic/Garlic_3.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic/Garlic_4.png b/resources/graphics/Plants/Garlic/Garlic/Garlic_4.png new file mode 100644 index 0000000..b9b5306 Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic/Garlic_4.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic/Garlic_5.png b/resources/graphics/Plants/Garlic/Garlic/Garlic_5.png new file mode 100644 index 0000000..3d8584d Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic/Garlic_5.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic/Garlic_6.png b/resources/graphics/Plants/Garlic/Garlic/Garlic_6.png new file mode 100644 index 0000000..12dc513 Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic/Garlic_6.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic/Garlic_7.png b/resources/graphics/Plants/Garlic/Garlic/Garlic_7.png new file mode 100644 index 0000000..0f2789f Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic/Garlic_7.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic/Garlic_8.png b/resources/graphics/Plants/Garlic/Garlic/Garlic_8.png new file mode 100644 index 0000000..dd27bc3 Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic/Garlic_8.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic/Garlic_9.png b/resources/graphics/Plants/Garlic/Garlic/Garlic_9.png new file mode 100644 index 0000000..68b8ccb Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic/Garlic_9.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_0.png b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_0.png new file mode 100644 index 0000000..ea442d7 Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_0.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_1.png b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_1.png new file mode 100644 index 0000000..7768392 Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_1.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_10.png b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_10.png new file mode 100644 index 0000000..94f46a4 Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_10.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_11.png b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_11.png new file mode 100644 index 0000000..fb0323e Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_11.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_2.png b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_2.png new file mode 100644 index 0000000..146e24b Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_2.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_3.png b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_3.png new file mode 100644 index 0000000..1035f2b Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_3.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_4.png b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_4.png new file mode 100644 index 0000000..c1aa561 Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_4.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_5.png b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_5.png new file mode 100644 index 0000000..9c82a23 Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_5.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_6.png b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_6.png new file mode 100644 index 0000000..46edfd0 Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_6.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_7.png b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_7.png new file mode 100644 index 0000000..f541ee4 Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_7.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_8.png b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_8.png new file mode 100644 index 0000000..0cdb12a Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_8.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_9.png b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_9.png new file mode 100644 index 0000000..453b0e1 Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked1/Garlic_cracked1_9.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_0.png b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_0.png new file mode 100644 index 0000000..4390f67 Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_0.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_1.png b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_1.png new file mode 100644 index 0000000..983b1ed Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_1.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_10.png b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_10.png new file mode 100644 index 0000000..8686baa Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_10.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_11.png b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_11.png new file mode 100644 index 0000000..247c046 Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_11.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_2.png b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_2.png new file mode 100644 index 0000000..6461627 Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_2.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_3.png b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_3.png new file mode 100644 index 0000000..0f4ce27 Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_3.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_4.png b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_4.png new file mode 100644 index 0000000..7eadf2b Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_4.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_5.png b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_5.png new file mode 100644 index 0000000..7826f8c Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_5.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_6.png b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_6.png new file mode 100644 index 0000000..ac06bd4 Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_6.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_7.png b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_7.png new file mode 100644 index 0000000..59185f4 Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_7.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_8.png b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_8.png new file mode 100644 index 0000000..fa6e3fc Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_8.png differ diff --git a/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_9.png b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_9.png new file mode 100644 index 0000000..2c76998 Binary files /dev/null and b/resources/graphics/Plants/Garlic/Garlic_cracked2/Garlic_cracked2_9.png differ diff --git a/source/component/map.py b/source/component/map.py index 6d2ede9..89e994b 100755 --- a/source/component/map.py +++ b/source/component/map.py @@ -12,22 +12,27 @@ class Map(): if self.background_type in c.POOL_EQUIPPED_BACKGROUNDS: self.width = c.GRID_POOL_X_LEN self.height = c.GRID_POOL_Y_LEN + self.gridHeightSize = c.GRID_POOL_Y_SIZE self.map = [[(deepcopy(c.MAP_STATE_EMPTY), deepcopy(c.MAP_STATE_WATER))[y in {2, 3}] 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.gridHeightSize = c.GRID_ROOF_Y_SIZE self.map = [[deepcopy(c.MAP_STATE_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.gridHeightSize = c.GRID_Y_SIZE self.map = [[(deepcopy(c.MAP_STATE_UNAVAILABLE), deepcopy(c.MAP_STATE_EMPTY))[y == 2] 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.gridHeightSize = c.GRID_Y_SIZE self.map = [[(deepcopy(c.MAP_STATE_UNAVAILABLE), deepcopy(c.MAP_STATE_EMPTY))[y in {1, 2, 3}] 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.gridHeightSize = c.GRID_Y_SIZE self.map = [[deepcopy(c.MAP_STATE_EMPTY) for x in range(self.width)] for y in range(self.height)] def isValid(self, map_x, map_y): diff --git a/source/component/plant.py b/source/component/plant.py index 200786f..7d91866 100755 --- a/source/component/plant.py +++ b/source/component/plant.py @@ -1780,3 +1780,27 @@ class IceFrozenPlot(Plant): self.health = 0 +class Garlic(Plant): + def __init__(self, x, y): + Plant.__init__(self, x, y, c.GARLIC, c.GARLIC_HEALTH, None) + self.load_images() + self.cracked1 = False + self.cracked2 = False + + def load_images(self): + self.cracked1_frames = [] + self.cracked2_frames = [] + + cracked1_frames_name = self.name + '_cracked1' + cracked2_frames_name = self.name + '_cracked2' + + self.loadFrames(self.cracked1_frames, cracked1_frames_name, 1) + self.loadFrames(self.cracked2_frames, cracked2_frames_name, 1) + + def idling(self): + if (not self.cracked1) and self.health <= c.GARLIC_CRACKED1_HEALTH: + self.changeFrames(self.cracked1_frames) + self.cracked1 = True + elif (not self.cracked2) and self.health <= c.GARLIC_CRACKED2_HEALTH: + self.changeFrames(self.cracked2_frames) + self.cracked2 = True diff --git a/source/component/zombie.py b/source/component/zombie.py index 5eb92c1..63fe4e1 100755 --- a/source/component/zombie.py +++ b/source/component/zombie.py @@ -20,6 +20,10 @@ class Zombie(pg.sprite.Sprite): self.rect = self.image.get_rect() self.rect.x = x self.rect.bottom = y + # 大蒜换行移动像素值,< 0时向上,= 0时不变,> 0时向上 + self.targetYChange = 0 + self.originalY = y + self.toChangeGroup = False self.helmetHealth = helmetHealth self.helmetType2Health = helmetType2Health @@ -191,13 +195,45 @@ class Zombie(pg.sprite.Sprite): if self.helmetType2Health <= 0 and self.helmetType2: self.changeFrames(self.walk_frames) self.helmetType2 = False - if (self.current_time - self.walk_timer) > (c.ZOMBIE_WALK_INTERVAL * self.getTimeRatio()): + + if ((self.current_time - self.walk_timer) > (c.ZOMBIE_WALK_INTERVAL * self.getTimeRatio()) + and self.handleGarlicYChange()): self.walk_timer = self.current_time if self.is_hypno: self.rect.x += 1 else: self.rect.x -= 1 + def handleGarlicYChange(self): + if self.targetYChange < 0: + self.setWalk() + if self.rect.bottom > self.originalY + self.targetYChange: # 注意这里加的是负数 + self.rect.bottom -= 3 + # 过半时换行 + if ((self.toChangeGroup) and + (self.rect.bottom >= self.originalY + 0.5*self.targetYChange)): + self.level.zombie_groups[self.mapY].remove(self) + self.level.zombie_groups[self.targetMapY].add(self) + else: + self.rect.bottom = self.originalY + self.targetYChange + self.targetYChange = 0 + return None + elif self.targetYChange > 0: + self.setWalk() + if self.rect.bottom < self.originalY + self.targetYChange: # 注意这里加的是负数 + self.rect.bottom += 3 + # 过半时换行 + if ((self.toChangeGroup) and + (self.rect.bottom <= self.originalY + 0.5*self.targetYChange)): + self.level.zombie_groups[self.mapY].remove(self) + self.level.zombie_groups[self.targetMapY].add(self) + else: + self.rect.bottom = self.originalY + self.targetYChange + self.targetYChange = 0 + return None + else: + return True + def attacking(self): if self.checkToDie(self.losthead_attack_frames): return @@ -216,6 +252,8 @@ class Zombie(pg.sprite.Sprite): if self.prey.health > 0: if self.prey_is_plant: self.prey.setDamage(self.damage, self) + if self.prey.name == c.GARLIC: + self.setWalk() else: self.prey.setDamage(self.damage) @@ -677,7 +715,8 @@ class NewspaperZombie(Zombie): self.helmetType2 = False # 触发报纸撕裂音效 pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "newspaperRip.ogg")).play() - if (self.current_time - self.walk_timer) > (c.ZOMBIE_WALK_INTERVAL * self.getTimeRatio()): + if ((self.current_time - self.walk_timer) > (c.ZOMBIE_WALK_INTERVAL * self.getTimeRatio()) + and self.handleGarlicYChange()): self.walk_timer = self.current_time if self.frames == self.lostnewspaper_frames: pass @@ -1160,7 +1199,8 @@ class SnorkelZombie(Zombie): if self.swimming: self.changeFrames(self.walk_frames) self.swimming = False - if (self.current_time - self.walk_timer) > (c.ZOMBIE_WALK_INTERVAL * self.getTimeRatio()): + if ((self.current_time - self.walk_timer) > (c.ZOMBIE_WALK_INTERVAL * self.getTimeRatio()) + and self.handleGarlicYChange()): self.walk_timer = self.current_time # 正在上浮或者下潜不用移动 if (self.frames == self.float_frames) or (self.frames == self.sink_frames): @@ -1219,7 +1259,6 @@ class SnorkelZombie(Zombie): def setWalk(self): self.state = c.WALK self.animate_interval = self.walk_animate_interval + self.swimming = True + self.changeFrames(self.sink_frames) - if self.rect.right <= c.MAP_POOL_FRONT_X: - self.swimming = True - self.changeFrames(self.sink_frames) diff --git a/source/constants.py b/source/constants.py index 52461a1..3dee972 100755 --- a/source/constants.py +++ b/source/constants.py @@ -242,6 +242,7 @@ HOLE = 'Hole' GRAVE = 'Grave' GRAVEBUSTER = 'GraveBuster' FUMESHROOM = 'FumeShroom' +GARLIC = 'Garlic' # 植物集体属性集合 @@ -302,7 +303,7 @@ PLANT_NON_CHECK_ATTACK_STATE = ( # 这里运用了集合运算 TORCHWOOD, SUNFLOWER, SUNSHROOM, COFFEEBEAN, GRAVEBUSTER, LILYPAD, - HYPNOSHROOM, + HYPNOSHROOM, GARLIC, } | # 非植物类 NON_PLANT_OBJECTS @@ -324,6 +325,9 @@ WALLNUT_CRACKED2_HEALTH = WALLNUT_HEALTH//3 TALLNUT_HEALTH = 8000 TALLNUT_CRACKED1_HEALTH = TALLNUT_HEALTH//3 * 2 TALLNUT_CRACKED2_HEALTH = TALLNUT_HEALTH//3 +GARLIC_HEALTH = 450 +GARLIC_CRACKED1_HEALTH = GARLIC_HEALTH//3 * 2 +GARLIC_CRACKED2_HEALTH = GARLIC_HEALTH//3 # 坚果保龄球攻击伤害 WALLNUT_BOWLING_DAMAGE = 550 @@ -367,6 +371,7 @@ CARD_TANGLEKLEP = 'card_tangleklep' CARD_DOOMSHROOM = 'card_doomshroom' CARD_GRAVEBUSTER = 'card_gravebuster' CARD_FUMESHROOM = 'card_fumeshroom' +CARD_GARLIC = 'card_garlic' # 植物卡片信息汇总(包括植物名称, 卡片名称, 阳光, 冷却时间) @@ -479,6 +484,10 @@ PLANT_CARD_INFO = (# 元组 (植物名称, 卡片名称, 阳光, 冷却时间) CARD_COFFEEBEAN, 75, 7500), + (GARLIC, + CARD_GARLIC, + 50, + 7500), # 应当保证这两个在一般模式下不可选的特殊植物恒在最后 (WALLNUTBOWLING, CARD_WALLNUT, diff --git a/source/state/level.py b/source/state/level.py index b225f2a..e4411e5 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -41,7 +41,7 @@ class Level(tool.State): f = open(file_path) self.map_data = json.load(f) f.close() - except Exception: + except: print("成功通关!") if self.game_info[c.GAME_MODE] == c.MODE_LITTLEGAME: self.game_info[c.LEVEL_NUM] = c.START_LEVEL_NUM @@ -918,6 +918,8 @@ class Level(tool.State): new_plant = plant.GraveBuster(x, y, self.plant_groups[map_y], self.map, map_x) elif self.plant_name == c.FUMESHROOM: new_plant = plant.FumeShroom(x, y, self.bullet_groups[map_y], self.zombie_groups[map_y]) + elif self.plant_name == c.GARLIC: + new_plant = plant.Garlic(x, y) if new_plant.can_sleep and self.background_type in c.DAYTIME_BACKGROUNDS: @@ -1043,7 +1045,6 @@ class Level(tool.State): # 被攻击对象是植物时才可能刷新 if zombie.prey_is_plant: # 新植物种在被攻击植物同一格时才可能刷新 - mapX, mapY = self.map.getMapIndex(zombie.prey.rect.centerx, zombie.prey.rect.centery) if (mapX, mapY) == self.newPlantAndPositon[1]: # 如果被攻击植物是睡莲和花盆,同一格种了植物必然刷新 # 如果被攻击植物不是睡莲和花盆,同一格种了南瓜头才刷新 @@ -1131,6 +1132,22 @@ class Level(tool.State): elif targetPlant.name == c.REDWALLNUTBOWLING: if targetPlant.state == c.IDLE: targetPlant.setAttack() + elif targetPlant.name == c.GARLIC: + zombie.setAttack(targetPlant) + # 向吃过大蒜的僵尸传入level + zombie.level = self + zombie.toChangeGroup = True + zombie.mapY = i + if i == 0: + _move = 1 + elif i == self.map_y_len - 1: + _move = -1 + else: + _move = random.randint(0, 1)*2 - 1 + if self.map.map[i][0][c.MAP_PLOT_TYPE] != self.map.map[i + _move][0][c.MAP_PLOT_TYPE]: + _move = -_move + zombie.targetMapY = i + _move + zombie.targetYChange = _move * self.map.gridHeightSize else: zombie.setAttack(targetPlant) diff --git a/source/tool.py b/source/tool.py index 2d2c042..a36b91d 100755 --- a/source/tool.py +++ b/source/tool.py @@ -205,7 +205,7 @@ pg.display.set_caption(c.ORIGINAL_CAPTION) # 设置标题 SCREEN = pg.display.set_mode(c.SCREEN_SIZE) # 设置初始屏幕 try: # 设置窗口图标,仅对非Nuitka时生效,Nuitka不需要包括额外的图标文件,自动跳过这一过程即可 pg.display.set_icon(pg.image.load(os.path.join(os.path.dirname(os.path.dirname(__file__)), c.ORIGINAL_LOGO))) -except Exception: +except: pass GFX = load_all_gfx(os.path.join(os.path.dirname(os.path.dirname(__file__)) ,os.path.join("resources","graphics")))