From 63e36df9303344d17a056fbddee43cb175c90688 Mon Sep 17 00:00:00 2001 From: wszqkzqk Date: Fri, 4 Nov 2022 11:16:35 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9D=A2=E5=90=91=E5=AF=B9=E8=B1=A1=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/component/plant.py | 16 ++++++++++++++++ source/constants.py | 18 +++--------------- source/state/level.py | 2 +- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/source/component/plant.py b/source/component/plant.py index 53daeeb..3c75f04 100755 --- a/source/component/plant.py +++ b/source/component/plant.py @@ -247,6 +247,8 @@ class Plant(pg.sprite.Sprite): # 被铲子指向时间 self.highlight_time = 0 + self.attack_check = c.CHECK_ATTACK_ALWAYS + def loadFrames(self, frames, name, scale=1, color=c.BLACK): frame_list = tool.GFX[name] if name in c.PLANT_RECT: @@ -390,6 +392,7 @@ class SunFlower(Plant): Plant.__init__(self, x, y, c.SUNFLOWER, c.PLANT_HEALTH, None) self.sun_timer = 0 self.sun_group = sun_group + self.attack_check = c.CHECK_ATTACK_NEVER def idling(self): if self.sun_timer == 0: @@ -515,6 +518,7 @@ class WallNut(Plant): self.load_images() self.cracked1 = False self.cracked2 = False + self.attack_check = c.CHECK_ATTACK_NEVER def load_images(self): self.cracked1_frames = [] @@ -1111,6 +1115,7 @@ class HypnoShroom(Plant): Plant.__init__(self, x, y, c.HYPNOSHROOM, c.PLANT_HEALTH, None) self.animate_interval = 80 self.zombie_to_hypno = None + self.attack_check = c.CHECK_ATTACK_NEVER def loadImages(self, name, scale): self.idle_frames = [] @@ -1145,6 +1150,7 @@ class WallNutBowling(Plant): self.vel_x = random.randint(12, 15) self.vel_y = 0 self.disable_hit_y = -1 + self.attack_check = c.CHECK_ATTACK_NEVER def loadImages(self, name, scale): self.loadFrames(self.frames, name, 1) @@ -1277,10 +1283,12 @@ class RedWallNutBowling(Plant): class LilyPad(Plant): def __init__(self, x, y): Plant.__init__(self, x, y, c.LILYPAD, c.PLANT_HEALTH, None) + self.attack_check = c.CHECK_ATTACK_NEVER class TorchWood(Plant): def __init__(self, x, y, bullet_group): Plant.__init__(self, x, y, c.TORCHWOOD, c.PLANT_HEALTH, bullet_group) + self.attack_check = c.CHECK_ATTACK_NEVER def idling(self): for i in self.bullet_group: @@ -1367,6 +1375,7 @@ class CoffeeBean(Plant): self.map_content = map_content self.map = map self.map_x = map_x + self.attack_check = c.CHECK_ATTACK_NEVER def animation(self): if (self.current_time - self.animate_timer) > self.animate_interval: @@ -1451,6 +1460,7 @@ class TallNut(Plant): self.load_images() self.cracked1 = False self.cracked2 = False + self.attack_check = c.CHECK_ATTACK_NEVER def load_images(self): self.cracked1_frames = [] @@ -1604,6 +1614,7 @@ class Hole(Plant): Plant.__init__(self, x, y, c.HOLE, c.INF, None) self.timer = 0 self.shallow = False + self.attack_check = c.CHECK_ATTACK_NEVER def loadImages(self, name, scale): self.idle_frames = [] @@ -1658,6 +1669,7 @@ class Grave(Plant): self.frame_index = random.randint(0, self.frame_num - 1) self.image = self.frames[self.frame_index] self.mask = pg.mask.from_surface(self.image) + self.attack_check = c.CHECK_ATTACK_NEVER def animation(self): pass @@ -1670,6 +1682,7 @@ class GraveBuster(Plant): self.map_x = map_x self.plant_group = plant_group self.animate_interval = 100 + self.attack_check = c.CHECK_ATTACK_NEVER # 播放吞噬音效 c.SOUND_GRAVEBUSTER_CHOMP.play() @@ -1778,6 +1791,7 @@ class IceFrozenPlot(Plant): def __init__(self, x, y): Plant.__init__(self, x, y, c.ICEFROZENPLOT, c.INF, None) self.timer = 0 + self.attack_check = c.CHECK_ATTACK_NEVER def idling(self): if self.timer == 0: @@ -1818,6 +1832,7 @@ class PumpkinHead(Plant): self.cracked1 = False self.cracked2 = False self.animate_interval = 160 + self.attack_check = c.CHECK_ATTACK_NEVER def load_images(self): self.cracked1_frames = [] @@ -1847,6 +1862,7 @@ class GiantWallNut(Plant): self.move_timer = 0 self.move_interval = 70 self.vel_x = random.randint(15, 18) + self.attack_check = c.CHECK_ATTACK_NEVER def idling(self): if self.move_timer == 0: diff --git a/source/constants.py b/source/constants.py index 2e7a596..9e4804e 100755 --- a/source/constants.py +++ b/source/constants.py @@ -421,21 +421,9 @@ WATER_PLANTS = { TANGLEKLEP, } -# 不用使用通用方法检验攻击状态的植物 -PLANT_NON_CHECK_ATTACK_STATE = ( # 这里运用了集合运算 - {# 单独指定攻击状态的植物 - WALLNUTBOWLING, - # 没有攻击状态的植物 - WALLNUT, TALLNUT, - TORCHWOOD, SUNFLOWER, - SUNSHROOM, COFFEEBEAN, - GRAVEBUSTER, LILYPAD, - HYPNOSHROOM, GARLIC, - PUMPKINHEAD, GIANTWALLNUT, - } | - # 非植物类 - NON_PLANT_OBJECTS - ) +# 攻击状态检查类型 +CHECK_ATTACK_NEVER = 0 +CHECK_ATTACK_ALWAYS = 1 # 范围爆炸植物,即灰烬植物与寒冰菇 ASH_PLANTS_AND_ICESHROOM = { diff --git a/source/state/level.py b/source/state/level.py index 2dca7cc..9e01739 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -1268,7 +1268,7 @@ class Level(tool.State): def checkPlant(self, target_plant, i): zombie_len = len(self.zombie_groups[i]) # 不用检查攻击状况的情况 - if target_plant.name in c.PLANT_NON_CHECK_ATTACK_STATE: + if not target_plant.attack_check: pass elif target_plant.name == c.THREEPEASHOOTER: if target_plant.state == c.IDLE: