修复僵尸会在上面有植物时把睡莲啃掉的bug

This commit is contained in:
星外之神 2022-04-22 14:40:48 +08:00
parent ccbfda85b5
commit b78e97b2b1
2 changed files with 9 additions and 7 deletions

View File

@ -299,7 +299,6 @@ class Zombie(pg.sprite.Sprite):
def setAttack(self, prey, is_plant=True): def setAttack(self, prey, is_plant=True):
self.prey = prey # prey can be plant or other zombies self.prey = prey # prey can be plant or other zombies
print(self.prey)
self.prey_is_plant = is_plant self.prey_is_plant = is_plant
self.state = c.ATTACK self.state = c.ATTACK
self.attack_timer = self.current_time self.attack_timer = self.current_time

View File

@ -648,7 +648,6 @@ class Level(tool.State):
elif plant.name == c.SPIKEWEED: elif plant.name == c.SPIKEWEED:
continue continue
# 在睡莲、花盆上有植物时应当优先攻击其上的植物 # 在睡莲、花盆上有植物时应当优先攻击其上的植物
# 这一段代码目前未能生效
elif plant.name in {c.LILYPAD, '花盆(未实现)'}: elif plant.name in {c.LILYPAD, '花盆(未实现)'}:
map_x, map_y = self.map.getMapIndex(plant.rect.centerx, plant.rect.bottom) map_x, map_y = self.map.getMapIndex(plant.rect.centerx, plant.rect.bottom)
if len(self.map.map[map_y][map_x][c.MAP_PLANT]) >= 2: if len(self.map.map[map_y][map_x][c.MAP_PLANT]) >= 2:
@ -656,12 +655,13 @@ class Level(tool.State):
for actualTargetPlant in self.plant_groups[i]: for actualTargetPlant in self.plant_groups[i]:
# 检测同一格的其他植物 # 检测同一格的其他植物
if self.map.getMapIndex(actualTargetPlant.rect.centerx, actualTargetPlant.rect.bottom) == (map_x, map_y): if self.map.getMapIndex(actualTargetPlant.rect.centerx, actualTargetPlant.rect.bottom) == (map_x, map_y):
if actualTargetPlant.name != c.LILYPAD: if actualTargetPlant.name != plant.name:
zombie.setAttack(actualTargetPlant) zombie.setAttack(actualTargetPlant)
continue break
zombie.setAttack(plant) else:
else: zombie.setAttack(plant)
self.refreshZombieAttack = False # 生效后需要解除刷新设置 else:
zombie.setAttack(plant)
for hypno_zombie in self.hypno_zombie_groups[i]: for hypno_zombie in self.hypno_zombie_groups[i]:
if hypno_zombie.health <= 0: if hypno_zombie.health <= 0:
@ -676,6 +676,9 @@ class Level(tool.State):
if hypno_zombie.state == c.WALK: if hypno_zombie.state == c.WALK:
hypno_zombie.setAttack(zombie, False) hypno_zombie.setAttack(zombie, False)
else:
self.refreshZombieAttack = False # 生效后需要解除刷新设置
def checkCarCollisions(self): def checkCarCollisions(self):
for car in self.cars: for car in self.cars:
for zombie in self.zombie_groups[car.map_y]: for zombie in self.zombie_groups[car.map_y]: