From 60911bebdd5e9fd7801e4676ed08f8355f4d7b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=A4=96=E4=B9=8B=E7=A5=9E?= Date: Tue, 13 Sep 2022 21:21:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=83=A8=E5=88=86=E5=86=97?= =?UTF-8?q?=E4=BD=99=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/component/plant.py | 11 +---------- source/state/level.py | 3 ++- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/source/component/plant.py b/source/component/plant.py index 60d88fe..53daeeb 100755 --- a/source/component/plant.py +++ b/source/component/plant.py @@ -241,7 +241,6 @@ class Plant(pg.sprite.Sprite): self.health = health self.state = c.IDLE self.bullet_group = bullet_group - self.can_sleep = False self.animate_timer = 0 self.animate_interval = 70 # 帧播放间隔 self.hit_timer = 0 @@ -670,7 +669,6 @@ class Chomper(Plant): class PuffShroom(Plant): def __init__(self, x, y, bullet_group): Plant.__init__(self, x, y, c.PUFFSHROOM, c.PLANT_HEALTH, bullet_group) - self.can_sleep = True self.shoot_timer = 0 def loadImages(self, name, scale): @@ -945,7 +943,6 @@ class Jalapeno(Plant): class ScaredyShroom(Plant): def __init__(self, x, y, bullet_group): Plant.__init__(self, x, y, c.SCAREDYSHROOM, c.PLANT_HEALTH, bullet_group) - self.can_sleep = True self.shoot_timer = 0 self.cry_x_range = c.GRID_X_SIZE * 1.5 @@ -999,7 +996,6 @@ class ScaredyShroom(Plant): class SunShroom(Plant): def __init__(self, x, y, sun_group): Plant.__init__(self, x, y, c.SUNSHROOM, c.PLANT_HEALTH, None) - self.can_sleep = True self.animate_interval = 140 self.sun_timer = 0 self.sun_group = sun_group @@ -1043,7 +1039,6 @@ class SunShroom(Plant): class IceShroom(Plant): def __init__(self, x, y): Plant.__init__(self, x, y, c.ICESHROOM, c.PLANT_HEALTH, None) - self.can_sleep = True self.orig_pos = (x, y) self.start_boom = False self.boomed = False @@ -1114,7 +1109,6 @@ class IceShroom(Plant): class HypnoShroom(Plant): def __init__(self, x, y): Plant.__init__(self, x, y, c.HYPNOSHROOM, c.PLANT_HEALTH, None) - self.can_sleep = True self.animate_interval = 80 self.zombie_to_hypno = None @@ -1381,7 +1375,7 @@ class CoffeeBean(Plant): if self.frame_index >= self.frame_num: self.map_content[c.MAP_SLEEP] = False for plant in self.plant_group: - if plant.can_sleep: + if plant.name in c.CAN_SLEEP_PLANTS: if plant.state == c.SLEEP: plant_map_x, _ = self.map.getMapIndex(plant.rect.centerx, plant.rect.bottom) if plant_map_x == self.map_x: @@ -1409,7 +1403,6 @@ class CoffeeBean(Plant): class SeaShroom(Plant): def __init__(self, x, y, bullet_group): Plant.__init__(self, x, y, c.SEASHROOM, c.PLANT_HEALTH, bullet_group) - self.can_sleep = True self.shoot_timer = 0 def loadImages(self, name, scale): @@ -1532,7 +1525,6 @@ class TangleKlep(Plant): class DoomShroom(Plant): def __init__(self, x, y, map_plant_set, explode_y_range): Plant.__init__(self, x, y, c.DOOMSHROOM, c.PLANT_HEALTH, None) - self.can_sleep = True self.map_plant_set = map_plant_set self.bomb_timer = 0 self.explode_y_range = explode_y_range @@ -1707,7 +1699,6 @@ class GraveBuster(Plant): class FumeShroom(Plant): def __init__(self, x, y, bullet_group, zombie_group): Plant.__init__(self, x, y, c.FUMESHROOM, c.PLANT_HEALTH, bullet_group) - self.can_sleep = True self.shoot_timer = 0 self.show_attack_frames = True self.zombie_group = zombie_group diff --git a/source/state/level.py b/source/state/level.py index be808ae..2dca7cc 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -927,7 +927,8 @@ class Level(tool.State): new_plant = plant.GiantWallNut(x, y) - if new_plant.can_sleep and self.background_type in c.DAYTIME_BACKGROUNDS: + if ((new_plant.name in c.CAN_SLEEP_PLANTS) + and (self.background_type in c.DAYTIME_BACKGROUNDS)): new_plant.setSleep() mushroom_sleep = True else: