加入墓碑和墓碑吞噬者

This commit is contained in:
星外之神 2022-05-08 21:55:58 +08:00
parent d30eeb725e
commit adad151a8e
53 changed files with 102 additions and 9 deletions

View File

@ -1,5 +1,5 @@
{
"background_type":2,
"background_type":1,
"init_sun_value":5000,
"shovel":1,
"spawn_zombies":"list",

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -41,14 +41,21 @@ class Map():
# 由于紫卡植物需要移除以前的植物,所以可用另外定义一个函数
# 注意咖啡豆生效后需要同时将植物的睡眠状态和格子的睡眠记录改变
def isAvailable(self, map_x, map_y, plantName):
# 咖啡豆的判别最为特殊
if (c.HOLE in self.map[map_y][map_x][c.MAP_PLANT]) or (c.ICE_FROZEN_PLOT in self.map[map_y][map_x][c.MAP_PLANT]):
return False
# 咖啡豆和墓碑吞噬者的判别最为特殊
if plantName == c.COFFEEBEAN:
if self.map[map_y][map_x][c.MAP_SLEEP] and (plantName not in self.map[map_y][map_x][c.MAP_PLANT]):
return True
else:
return False
if plantName == c.GRAVEBUSTER:
if (c.GRAVE in self.map[map_y][map_x][c.MAP_PLANT]):
return True
else:
return False
if ((c.HOLE in self.map[map_y][map_x][c.MAP_PLANT]) or
(c.ICE_FROZEN_PLOT in self.map[map_y][map_x][c.MAP_PLANT]) or
(c.GRAVE in self.map[map_y][map_x][c.MAP_PLANT])):
return False
if self.map[map_y][map_x][c.MAP_PLOT_TYPE] == c.MAP_GRASS: # 草地
# 首先需要判断植物是否是水生植物,水生植物不能种植在陆地上
if plantName not in {c.LILYPAD, c.SEASHROOM, c.TANGLEKLEP}: # 这里的集合也可以换成存储在某一文件中的常数的表达

View File

@ -45,6 +45,10 @@ plantInfo = (# 元组 (植物名称, 卡片名称, 阳光, 冷却时间)
c.CARD_SUNSHROOM,
25,
7500),
(c.GRAVEBUSTER,
c.CARD_GRAVEBUSTER,
75,
7500),
(c.HYPNOSHROOM,
c.CARD_HYPNOSHROOM,
75,

View File

@ -923,6 +923,8 @@ class IceShroom(Plant):
return
self.animate_timer = self.current_time
else:
if self.state != c.SLEEP:
self.health = c.INF
if (self.current_time - self.animate_timer) > 100:
self.frame_index += 1
if self.frame_index >= self.frame_num:
@ -1432,3 +1434,43 @@ class Hole(Plant):
self.shallow = True
elif self.current_time - self.timer >= 180000:
self.health = 0
class Grave(Plant):
def __init__(self, x, y):
Plant.__init__(self, x, y, c.GRAVE, c.INF, None)
self.frame_index = randint(0, self.frame_num - 1)
self.image = self.frames[self.frame_index]
def animation(self):
pass
class GraveBuster(Plant):
def __init__(self, x, y, plant_group, map, map_x):
Plant.__init__(self, x, y, c.GRAVEBUSTER, c.PLANT_HEALTH, None)
self.map = map
self.map_x = map_x
self.plant_group = plant_group
self.animate_interval = 100
def animation(self):
if (self.current_time - self.animate_timer) > self.animate_interval:
self.frame_index += 1
if self.frame_index >= self.frame_num:
self.frame_index = self.frame_num - 1
for item in self.plant_group:
if item.name == c.GRAVE:
itemMapX, _ = self.map.getMapIndex(item.rect.centerx, item.rect.bottom)
if itemMapX == self.map_x:
item.health = 0
self.health = 0
self.animate_timer = self.current_time
self.image = self.frames[self.frame_index]
if (self.current_time - self.highlightTime < 200):
self.image.set_alpha(150)
elif ((self.current_time - self.hit_timer) < 200):
self.image.set_alpha(192)
else:
self.image.set_alpha(255)

View File

@ -104,6 +104,13 @@ BACKGROUND_WALLNUTBOWLING = 6
BACKGROUND_SINGLE = 7
BACKGROUND_TRIPLE = 8
# 夜晚地图的墓碑数量等级
GRADE_GRAVES = 'grade_graves'
GRADE0_GRAVES = 0 # 无墓碑
GRADE1_GRAVES = 1 # 少量墓碑
GRADE2_GRAVES = 2 # 中等数量墓碑
GRADE3_GRAVES = 3 # 大量墓碑
# 僵尸生成方式
SPAWN_ZOMBIES = 'spawn_zombies'
SPAWN_ZOMBIES_AUTO = 'auto'
@ -207,6 +214,9 @@ TANGLEKLEP = 'TangleKlep'
DOOMSHROOM = 'DoomShroom'
ICE_FROZEN_PLOT = 'IceFrozenPlot'
HOLE = 'Hole'
GRAVE = 'Grave'
GRAVEBUSTER = 'GraveBuster'
# 植物生命值
PLANT_HEALTH = 300
@ -257,6 +267,7 @@ CARD_SEASHROOM = 'card_seashroom'
CARD_TALLNUT = 'card_tallnut'
CARD_TANGLEKLEP = 'card_tangleklep'
CARD_DOOMSHROOM = 'card_doomshroom'
CARD_GRAVEBUSTER = 'card_gravebuster'
# 子弹信息
# 子弹类型

View File

@ -385,6 +385,33 @@ class Level(tool.State):
self.setupHugeWaveApprochingImage()
self.showHugeWaveApprochingTime = -2000 # 防止设置为0时刚刚打开游戏就已经启动红字
if self.map_data[c.BACKGROUND_TYPE] == c.BACKGROUND_NIGHT:
if c.GRADE_GRAVES in self.map_data:
gradeGraves = self.map_data[c.GRADE_GRAVES]
# 缺省为少量墓碑
else:
gradeGraves = c.GRADE1_GRAVES
if gradeGraves == c.GRADE1_GRAVES:
graveVolume = 4
elif gradeGraves == c.GRADE2_GRAVES:
graveVolume = 7
elif gradeGraves >= c.GRADE3_GRAVES:
graveVolume = 11
else:
graveVolume = 0
graveSet = set()
while len(graveSet) < graveVolume:
mapX = randint(4, 8) # 注意是从0开始编号
mapY = randint(0, 4)
graveSet.add((mapX, mapY))
if graveSet:
for i in graveSet:
mapX, mapY = i
posX, posY = self.map.getMapGridPos(mapX, mapY)
self.plant_groups[mapY].add(plant.Grave(posX, posY))
self.map.map[mapY][mapX][c.MAP_PLANT].add(c.GRAVE)
# 小菜单
def setupLittleMenu(self):
@ -491,7 +518,7 @@ class Level(tool.State):
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):
if i.name in {c.HOLE, c.ICE_FROZEN_PLOT}:
if i.name in {c.HOLE, c.ICE_FROZEN_PLOT, c.GRAVE}:
continue
# 优先移除花盆、睡莲上的植物而非花盆、睡莲本身
if len(self.map.map[map_y][map_x][c.MAP_PLANT]) >= 2:
@ -794,6 +821,8 @@ class Level(tool.State):
new_plant = plant.TangleKlep(x, y)
elif self.plant_name == c.DOOMSHROOM:
new_plant = plant.DoomShroom(x, y, self.map.map[map_y][map_x])
elif self.plant_name == c.GRAVEBUSTER:
new_plant = plant.GraveBuster(x, y, self.plant_groups[map_y], self.map, map_x)
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}:
@ -930,7 +959,7 @@ class Level(tool.State):
elif plant.name in {c.LILYPAD, "花盆(未实现)"}:
attackableBackupPlant.append(plant)
# 注意要剔除掉两个“假植物”,以及不能被啃的地刺
elif plant.name not in {c.HOLE, c.ICE_FROZEN_PLOT, c.SPIKEWEED}:
elif plant.name not in {c.HOLE, c.ICE_FROZEN_PLOT, c.GRAVE, c.SPIKEWEED}:
attackableCommonPlants.append(plant)
else:
if attackableCommonPlants:
@ -1043,7 +1072,7 @@ class Level(tool.State):
self.boomZombies(targetPlant.rect.centerx, map_y, targetPlant.explode_y_range,
targetPlant.explode_x_range, effect=c.BULLET_EFFECT_UNICE)
elif targetPlant.name == c.ICESHROOM and targetPlant.state != c.SLEEP:
self.freezeZombies(plant)
self.freezeZombies(targetPlant)
elif targetPlant.name == c.HYPNOSHROOM and targetPlant.state != c.SLEEP:
zombie = targetPlant.kill_zombie
zombie.setHypno()
@ -1235,7 +1264,7 @@ class Level(tool.State):
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):
if i.name in {c.HOLE, c.ICE_FROZEN_PLOT}:
if i.name in {c.HOLE, c.ICE_FROZEN_PLOT, c.GRAVE}:
continue
# 优先选中睡莲、花盆上的植物
if len(self.map.map[map_y][map_x][c.MAP_PLANT]) >= 2: