From c68cc7c4d552e6d6cd094a6afd2522b817cc76b5 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, 20 May 2022 14:50:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=A4=A7=E5=98=B4=E8=8A=B1?= =?UTF-8?q?=E8=AE=BE=E5=AE=9A=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=8E=89=E5=A4=B4?= =?UTF-8?q?=E5=83=B5=E5=B0=B8=E5=8F=AF=E4=BB=A5=E5=90=B8=E5=BC=95=E8=B1=8C?= =?UTF-8?q?=E8=B1=86=E7=B1=BB=E6=A4=8D=E7=89=A9=E6=94=BB=E5=87=BB=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/component/plant.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/source/component/plant.py b/source/component/plant.py index 38d0f1c..b36c9c1 100755 --- a/source/component/plant.py +++ b/source/component/plant.py @@ -320,7 +320,7 @@ class Plant(pg.sprite.Sprite): self.image.set_alpha(255) def canAttack(self, zombie): - if (self.state != c.SLEEP and zombie.state != c.DIE and (not zombie.lostHead) and + if (self.state != c.SLEEP and zombie.state != c.DIE and self.rect.x <= zombie.rect.right and zombie.rect.left <= c.SCREEN_WIDTH): return True return False @@ -595,6 +595,7 @@ class Chomper(Plant): self.digest_interval = 15000 self.attack_zombie = None self.zombie_group = None + self.shouldDiggest = False def loadImages(self, name, scale): self.idle_frames = [] @@ -621,7 +622,7 @@ class Chomper(Plant): return False elif (self.state == c.IDLE and zombie.state != c.DIGEST and self.rect.x <= zombie.rect.centerx and (not zombie.lostHead) and - (self.rect.x + c.GRID_X_SIZE*2.6 >= zombie.rect.centerx)): + (self.rect.x + c.GRID_X_SIZE*2.7 >= zombie.rect.centerx)): return True return False @@ -643,9 +644,15 @@ class Chomper(Plant): if self.frame_index == (self.frame_num - 3): # 播放吞的音效 pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "bigchomp.ogg")).play() + if self.attack_zombie.alive(): + self.shouldDiggest = True self.attack_zombie.kill() if (self.frame_index + 1) == self.frame_num: - self.setDigest() + if self.shouldDiggest: + self.setDigest() + self.shouldDiggest = False + else: + self.setIdle() def digest(self): if self.digest_timer == 0: