diff --git a/README.md b/README.md index 9aa2696..bd53c12 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ **本项目为个人python语言学习的练习项目,仅供个人学习和研究使用,不得用于其他用途。如果这个游戏侵犯了版权,请联系我删除** -* 已有的植物:向日葵,豌豆射手,坚果墙,寒冰射手,樱桃炸弹,三线射手,大嘴花,小喷菇,土豆雷,地刺,胆小菇,倭瓜,火爆辣椒,阳光菇,寒冰菇,魅惑菇,火炬树桩,睡莲,杨桃,咖啡豆,海蘑菇 +* 已有的植物:向日葵,豌豆射手,坚果墙,寒冰射手,樱桃炸弹,三线射手,大嘴花,小喷菇,土豆雷,地刺,胆小菇,倭瓜,火爆辣椒,阳光菇,寒冰菇,魅惑菇,火炬树桩,睡莲,杨桃,咖啡豆,海蘑菇,高坚果,缠绕水草 * 已有的僵尸:普通僵尸,旗帜僵尸,路障僵尸,铁桶僵尸,读报僵尸,橄榄球僵尸,鸭子救生圈僵尸,铁门僵尸 * 使用 JSON 文件记录关卡信息数据 * 支持选择植物卡片 diff --git a/resources/graphics/Cards/card_tangleklep.png b/resources/graphics/Cards/card_tangleklep.png new file mode 100644 index 0000000..d59175b Binary files /dev/null and b/resources/graphics/Cards/card_tangleklep.png differ diff --git a/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_0.png b/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_0.png new file mode 100644 index 0000000..a9cae7a Binary files /dev/null and b/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_0.png differ diff --git a/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_1.png b/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_1.png new file mode 100644 index 0000000..9b0f082 Binary files /dev/null and b/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_1.png differ diff --git a/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_2.png b/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_2.png new file mode 100644 index 0000000..4dce0d9 Binary files /dev/null and b/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_2.png differ diff --git a/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_3.png b/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_3.png new file mode 100644 index 0000000..e4b2e8f Binary files /dev/null and b/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_3.png differ diff --git a/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_4.png b/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_4.png new file mode 100644 index 0000000..3753b06 Binary files /dev/null and b/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_4.png differ diff --git a/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_5.png b/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_5.png new file mode 100644 index 0000000..a16b417 Binary files /dev/null and b/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_5.png differ diff --git a/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_6.png b/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_6.png new file mode 100644 index 0000000..506c13d Binary files /dev/null and b/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_6.png differ diff --git a/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_7.png b/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_7.png new file mode 100644 index 0000000..776555f Binary files /dev/null and b/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_7.png differ diff --git a/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_8.png b/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_8.png new file mode 100644 index 0000000..b04d686 Binary files /dev/null and b/resources/graphics/Plants/TangleKlep/TangleKlep/TangleKlep_8.png differ diff --git a/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_0.png b/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_0.png new file mode 100644 index 0000000..1908940 Binary files /dev/null and b/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_0.png differ diff --git a/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_1.png b/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_1.png new file mode 100644 index 0000000..5bed9fc Binary files /dev/null and b/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_1.png differ diff --git a/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_2.png b/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_2.png new file mode 100644 index 0000000..5bed9fc Binary files /dev/null and b/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_2.png differ diff --git a/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_3.png b/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_3.png new file mode 100644 index 0000000..ed49db9 Binary files /dev/null and b/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_3.png differ diff --git a/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_4.png b/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_4.png new file mode 100644 index 0000000..77d00ba Binary files /dev/null and b/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_4.png differ diff --git a/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_5.png b/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_5.png new file mode 100644 index 0000000..a788aaf Binary files /dev/null and b/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_5.png differ diff --git a/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_6.png b/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_6.png new file mode 100644 index 0000000..4e6891a Binary files /dev/null and b/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_6.png differ diff --git a/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_7.png b/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_7.png new file mode 100644 index 0000000..1d79c7f Binary files /dev/null and b/resources/graphics/Plants/TangleKlep/TangleKlepSplash/TangleKlepSplash_7.png differ diff --git a/source/component/map.py b/source/component/map.py index 4f069ce..e9c676d 100755 --- a/source/component/map.py +++ b/source/component/map.py @@ -49,7 +49,7 @@ class Map(): return False if self.map[map_y][map_x][c.MAP_PLOT_TYPE] == c.MAP_GRASS: # 草地 # 首先需要判断植物是否是水生植物,水生植物不能种植在陆地上 - if plantName not in {c.LILYPAD, c.SEASHROOM, '缠绕水草(未实现)'}: # 这里的集合也可以换成存储在某一文件中的常数的表达 + if plantName not in {c.LILYPAD, c.SEASHROOM, c.TANGLEKLEP}: # 这里的集合也可以换成存储在某一文件中的常数的表达 if not self.map[map_y][map_x][c.MAP_PLANT]: # 没有植物肯定可以种植 return True elif ((self.map[map_y][map_x][c.MAP_PLANT] | {'花盆(未实现)', '南瓜头(未实现)'} == {'花盆(未实现)', '南瓜头(未实现)'}) @@ -61,7 +61,7 @@ class Map(): return False elif self.map[map_y][map_x][c.MAP_PLOT_TYPE] == c.MAP_TILE: # 屋顶 # 首先需要判断植物是否是水生植物,水生植物不能种植在陆地上 - if plantName not in {c.LILYPAD, c.SEASHROOM, '缠绕水草(未实现)'}: # 这里的集合也可以换成存储在某一文件中的常数的表达 + if plantName not in {c.LILYPAD, c.SEASHROOM, c.TANGLEKLEP}: # 这里的集合也可以换成存储在某一文件中的常数的表达 if '花盆(未实现)' in self.map[map_y][map_x][c.MAP_PLANT]: if ((self.map[map_y][map_x][c.MAP_PLANT] | {'花盆(未实现)', '南瓜头(未实现)'} == {'花盆(未实现)', '南瓜头(未实现)'}) and (plantName not in self.map[map_y][map_x][c.MAP_PLANT])): # 例外植物:集合中填花盆和南瓜头,只要这里没有这种植物就能种植;判断方法:并集 @@ -76,7 +76,7 @@ class Map(): else: return False elif self.map[map_y][map_x][c.MAP_PLOT_TYPE] == c.MAP_WATER: # 水里 - if plantName in {c.LILYPAD, c.SEASHROOM, '缠绕水草(未实现)'}: # 是水生植物 + if plantName in {c.LILYPAD, c.SEASHROOM, c.TANGLEKLEP}: # 是水生植物 if not self.map[map_y][map_x][c.MAP_PLANT]: # 只有无植物时才能在水里种植水生植物 return True else: diff --git a/source/component/menubar.py b/source/component/menubar.py index 0a67ad2..67a928b 100755 --- a/source/component/menubar.py +++ b/source/component/menubar.py @@ -65,6 +65,10 @@ plantInfo = (# 元组 (植物名称, 卡片名称, 阳光, 冷却时间) c.CARD_SQUASH, 50, 30000), + (c.TANGLEKLEP, + c.CARD_TANGLEKLEP, + 325, + 7500), (c.THREEPEASHOOTER, c.CARD_THREEPEASHOOTER, 325, diff --git a/source/component/plant.py b/source/component/plant.py index 9f6751c..afbe1ec 100755 --- a/source/component/plant.py +++ b/source/component/plant.py @@ -1252,4 +1252,46 @@ class TallNut(Plant): self.cracked1 = True elif not self.cracked2 and self.health <= c.TALLNUT_CRACKED2_HEALTH: self.changeFrames(self.cracked2_frames) - self.cracked2 = True \ No newline at end of file + self.cracked2 = True + + +class TangleKlep(Plant): + def __init__(self, x, y): + Plant.__init__(self, x, y, c.TANGLEKLEP, c.PLANT_HEALTH, None) + self.load_images() + self.splashing = False + + def load_images(self): + self.idle_frames = [] + self.splash_frames = [] + + idle_name = self.name + splash_name = self.name + 'Splash' + + frame_list = [self.idle_frames, self.splash_frames] + name_list = [idle_name, splash_name] + + for i, name in enumerate(name_list): + self.loadFrames(frame_list[i], name, 1, c.WHITE) + + self.frames = self.idle_frames + + def canAttack(self, zombie): + if pg.sprite.collide_circle_ratio(0.7)(zombie, self): + return True + return False + + def setAttack(self, zombie, zombie_group): + self.attack_zombie = zombie + self.zombie_group = zombie_group + self.state = c.ATTACK + + def attacking(self): + if not self.splashing: + self.splashing = True + self.changeFrames(self.splash_frames) + self.zombie_group.remove(self.attack_zombie) + self.attack_zombie.kill() + # 这里必须用elif排除尚未进入splash阶段,以免误触 + elif (self.frame_index + 1) >= self.frame_num: + self.health = 0 \ No newline at end of file diff --git a/source/constants.py b/source/constants.py index 3edadc6..88b1e7f 100755 --- a/source/constants.py +++ b/source/constants.py @@ -206,6 +206,7 @@ STARFRUIT = 'StarFruit' COFFEEBEAN = 'CoffeeBean' SEASHROOM = 'SeaShroom' TALLNUT = 'TallNut' +TANGLEKLEP = 'TangleKlep' # 植物生命值 PLANT_HEALTH = 300 @@ -254,6 +255,7 @@ CARD_STARFRUIT = 'card_starfruit' CARD_COFFEEBEAN = 'card_coffeebean' CARD_SEASHROOM = 'card_seashroom' CARD_TALLNUT = 'card_tallnut' +CARD_TANGLEKLEP = 'card_tangleklep' # 子弹信息 # 子弹类型 diff --git a/source/state/level.py b/source/state/level.py index ad78d1c..03b7fa6 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -788,6 +788,8 @@ class Level(tool.State): new_plant = plant.SeaShroom(x, y, self.bullet_groups[map_y]) elif self.plant_name == c.TALLNUT: new_plant = plant.TallNut(x, y) + elif self.plant_name == c.TANGLEKLEP: + new_plant = plant.TangleKlep(x, y) if new_plant.can_sleep and self.background_type in {c.BACKGROUND_DAY, c.BACKGROUND_POOL, c.BACKGROUND_ROOF, c.BACKGROUND_WALLNUTBOWLING, c.BACKGROUND_SINGLE, c.BACKGROUND_TRIPLE}: new_plant.setSleep() @@ -1105,8 +1107,12 @@ class Level(tool.State): plant.setAttack() elif (plant.state == c.ATTACK and not can_attack): plant.setIdle() - elif(plant.name == c.WALLNUTBOWLING or - plant.name == c.REDWALLNUTBOWLING): + elif plant.name == c.TANGLEKLEP: + for zombie in self.zombie_groups[i]: + if plant.canAttack(zombie): + plant.setAttack(zombie, self.zombie_groups[i]) + break + elif plant.name in {c.WALLNUTBOWLING, c.REDWALLNUTBOWLING}: pass else: can_attack = False