diff --git a/source/component/zombie.py b/source/component/zombie.py index a486839..f7b1f29 100755 --- a/source/component/zombie.py +++ b/source/component/zombie.py @@ -299,7 +299,6 @@ class Zombie(pg.sprite.Sprite): def setAttack(self, prey, is_plant=True): self.prey = prey # prey can be plant or other zombies - print(self.prey) self.prey_is_plant = is_plant self.state = c.ATTACK self.attack_timer = self.current_time diff --git a/source/state/level.py b/source/state/level.py index 75db34d..4259c81 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -648,7 +648,6 @@ class Level(tool.State): elif plant.name == c.SPIKEWEED: continue # 在睡莲、花盆上有植物时应当优先攻击其上的植物 - # 这一段代码目前未能生效 elif plant.name in {c.LILYPAD, '花盆(未实现)'}: 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: @@ -656,12 +655,13 @@ class Level(tool.State): for actualTargetPlant in self.plant_groups[i]: # 检测同一格的其他植物 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) - continue - zombie.setAttack(plant) - else: - self.refreshZombieAttack = False # 生效后需要解除刷新设置 + break + else: + zombie.setAttack(plant) + else: + zombie.setAttack(plant) for hypno_zombie in self.hypno_zombie_groups[i]: if hypno_zombie.health <= 0: @@ -676,6 +676,9 @@ class Level(tool.State): if hypno_zombie.state == c.WALK: hypno_zombie.setAttack(zombie, False) + else: + self.refreshZombieAttack = False # 生效后需要解除刷新设置 + def checkCarCollisions(self): for car in self.cars: for zombie in self.zombie_groups[car.map_y]: