加入缠绕水草

This commit is contained in:
星外之神 2022-05-08 00:46:04 +08:00
parent f51424811b
commit 69848b39e3
24 changed files with 61 additions and 7 deletions

View File

@ -4,7 +4,7 @@
**本项目为个人python语言学习的练习项目仅供个人学习和研究使用不得用于其他用途。如果这个游戏侵犯了版权请联系我删除**
* 已有的植物:向日葵,豌豆射手,坚果墙,寒冰射手,樱桃炸弹,三线射手,大嘴花,小喷菇,土豆雷,地刺,胆小菇,倭瓜,火爆辣椒,阳光菇,寒冰菇,魅惑菇,火炬树桩,睡莲,杨桃,咖啡豆,海蘑菇
* 已有的植物:向日葵,豌豆射手,坚果墙,寒冰射手,樱桃炸弹,三线射手,大嘴花,小喷菇,土豆雷,地刺,胆小菇,倭瓜,火爆辣椒,阳光菇,寒冰菇,魅惑菇,火炬树桩,睡莲,杨桃,咖啡豆,海蘑菇,高坚果,缠绕水草
* 已有的僵尸:普通僵尸,旗帜僵尸,路障僵尸,铁桶僵尸,读报僵尸,橄榄球僵尸,鸭子救生圈僵尸,铁门僵尸
* 使用 JSON 文件记录关卡信息数据
* 支持选择植物卡片

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -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:

View File

@ -65,6 +65,10 @@ plantInfo = (# 元组 (植物名称, 卡片名称, 阳光, 冷却时间)
c.CARD_SQUASH,
50,
30000),
(c.TANGLEKLEP,
c.CARD_TANGLEKLEP,
325,
7500),
(c.THREEPEASHOOTER,
c.CARD_THREEPEASHOOTER,
325,

View File

@ -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
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

View File

@ -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'
# 子弹信息
# 子弹类型

View File

@ -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