From b78e97b2b1c3ace207e5dea87fa849a5238cfac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=A4=96=E4=B9=8B=E7=A5=9E?= Date: Fri, 22 Apr 2022 14:40:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=83=B5=E5=B0=B8=E4=BC=9A?= =?UTF-8?q?=E5=9C=A8=E4=B8=8A=E9=9D=A2=E6=9C=89=E6=A4=8D=E7=89=A9=E6=97=B6?= =?UTF-8?q?=E6=8A=8A=E7=9D=A1=E8=8E=B2=E5=95=83=E6=8E=89=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/component/zombie.py | 1 - source/state/level.py | 15 +++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) 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]: