diff --git a/resources/graphics/Cards/card_torchwood.png b/resources/graphics/Cards/card_torchwood.png new file mode 100644 index 0000000..49318f1 Binary files /dev/null and b/resources/graphics/Cards/card_torchwood.png differ diff --git a/resources/graphics/Plants/TorchWood/TorchWood_0.png b/resources/graphics/Plants/TorchWood/TorchWood_0.png index 64facc2..ede1635 100644 Binary files a/resources/graphics/Plants/TorchWood/TorchWood_0.png and b/resources/graphics/Plants/TorchWood/TorchWood_0.png differ diff --git a/resources/graphics/Plants/TorchWood/TorchWood_1.png b/resources/graphics/Plants/TorchWood/TorchWood_1.png index 6a3ad59..ef347ca 100644 Binary files a/resources/graphics/Plants/TorchWood/TorchWood_1.png and b/resources/graphics/Plants/TorchWood/TorchWood_1.png differ diff --git a/resources/graphics/Plants/TorchWood/TorchWood_2.png b/resources/graphics/Plants/TorchWood/TorchWood_2.png index 6ed2654..2041e76 100644 Binary files a/resources/graphics/Plants/TorchWood/TorchWood_2.png and b/resources/graphics/Plants/TorchWood/TorchWood_2.png differ diff --git a/resources/graphics/Plants/TorchWood/TorchWood_3.png b/resources/graphics/Plants/TorchWood/TorchWood_3.png index 72eef44..2564ce2 100644 Binary files a/resources/graphics/Plants/TorchWood/TorchWood_3.png and b/resources/graphics/Plants/TorchWood/TorchWood_3.png differ diff --git a/resources/graphics/Plants/TorchWood/TorchWood_4.png b/resources/graphics/Plants/TorchWood/TorchWood_4.png index b330b8a..58e92d6 100644 Binary files a/resources/graphics/Plants/TorchWood/TorchWood_4.png and b/resources/graphics/Plants/TorchWood/TorchWood_4.png differ diff --git a/resources/graphics/Plants/TorchWood/TorchWood_5.png b/resources/graphics/Plants/TorchWood/TorchWood_5.png index 3fdc9dc..140c088 100644 Binary files a/resources/graphics/Plants/TorchWood/TorchWood_5.png and b/resources/graphics/Plants/TorchWood/TorchWood_5.png differ diff --git a/source/component/menubar.py b/source/component/menubar.py index 289f9de..d68f404 100755 --- a/source/component/menubar.py +++ b/source/component/menubar.py @@ -76,20 +76,20 @@ plantDict = {# 字典 植物名称:(卡片名称, 阳光, 冷却时间) 7500)} ''' -card_name_list = [c.CARD_SUNFLOWER, c.CARD_PEASHOOTER, c.CARD_SNOWPEASHOOTER, c.CARD_WALLNUT, +card_name_list = (c.CARD_SUNFLOWER, c.CARD_PEASHOOTER, c.CARD_SNOWPEASHOOTER, c.CARD_WALLNUT, c.CARD_CHERRYBOMB, c.CARD_THREEPEASHOOTER, c.CARD_REPEATERPEA, c.CARD_CHOMPER, c.CARD_PUFFSHROOM, c.CARD_POTATOMINE, c.CARD_SQUASH, c.CARD_SPIKEWEED, c.CARD_JALAPENO, c.CARD_SCAREDYSHROOM, c.CARD_SUNSHROOM, c.CARD_ICESHROOM, - c.CARD_HYPNOSHROOM, c.CARD_LILYPAD, c.CARD_WALLNUT, c.CARD_REDWALLNUT] -plant_name_list = [c.SUNFLOWER, c.PEASHOOTER, c.SNOWPEASHOOTER, c.WALLNUT, + c.CARD_HYPNOSHROOM, c.CARD_LILYPAD, c.CARD_TORCHWOOD, c.CARD_WALLNUT, c.CARD_REDWALLNUT) +plant_name_list = (c.SUNFLOWER, c.PEASHOOTER, c.SNOWPEASHOOTER, c.WALLNUT, c.CHERRYBOMB, c.THREEPEASHOOTER, c.REPEATERPEA, c.CHOMPER, c.PUFFSHROOM, c.POTATOMINE, c.SQUASH, c.SPIKEWEED, c.JALAPENO, c.SCAREDYSHROOM, c.SUNSHROOM, c.ICESHROOM, - c.HYPNOSHROOM, c.LILYPAD, c.WALLNUTBOWLING, c.REDWALLNUTBOWLING] -plant_sun_list = [50, 100, 175, 50, 150, 325, 200, 150, 0, 25, 50, 100, 125, 25, 25, 75, 75, 25, 0, 0] -plant_frozen_time_list = [7500, 7500, 7500, 30000, 50000, 7500, 7500, 7500, 7500, 30000, - 30000, 7500, 50000, 7500, 7500, 50000, 30000, 7500, 0, 0] -all_card_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17] + c.HYPNOSHROOM, c.LILYPAD, c.TORCHWOOD, c.WALLNUTBOWLING, c.REDWALLNUTBOWLING) +plant_sun_list = (50, 100, 175, 50, 150, 325, 200, 150, 0, 25, 50, 100, 125, 25, 25, 75, 75, 25, 0, 0) +plant_frozen_time_list = (7500, 7500, 7500, 30000, 50000, 7500, 7500, 7500, 7500, 30000, + 30000, 7500, 50000, 7500, 7500, 50000, 30000, 7500, 7500, 0, 0) +all_card_list = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18) def getSunValueImage(sun_value): diff --git a/source/component/plant.py b/source/component/plant.py index 96fc3fc..77d2c59 100755 --- a/source/component/plant.py +++ b/source/component/plant.py @@ -36,7 +36,7 @@ class Car(pg.sprite.Sprite): class Bullet(pg.sprite.Sprite): - def __init__(self, x, start_y, dest_y, name, damage, ice): + def __init__(self, x, start_y, dest_y, name, damage, effect=False, passedTorchWood=None): pg.sprite.Sprite.__init__(self) self.name = name @@ -51,9 +51,10 @@ class Bullet(pg.sprite.Sprite): self.y_vel = 4 if (dest_y > start_y) else -4 self.x_vel = 10 self.damage = damage - self.ice = ice + self.effect = effect self.state = c.FLY self.current_time = 0 + self.passedTorchWood = passedTorchWood # 记录最近通过的火炬树横坐标,如果没有缺省为None def loadFrames(self, frames, name): frame_list = tool.GFX[name] @@ -211,7 +212,7 @@ class Plant(pg.sprite.Sprite): def canAttack(self, zombie): if (self.state != c.SLEEP and zombie.state != c.DIE and (not zombie.lostHead) and self.rect.x <= zombie.rect.right): - return True + return True return False def setAttack(self): @@ -297,7 +298,7 @@ class PeaShooter(Plant): def attacking(self): if (self.current_time - self.shoot_timer) > 1400: self.bullet_group.add(Bullet(self.rect.right - 15, self.rect.y, self.rect.y, - c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False)) + c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, effect=False)) self.shoot_timer = self.current_time @@ -313,12 +314,12 @@ class RepeaterPea(Plant): if (self.current_time - self.shoot_timer > 1400): self.firstShot = True self.bullet_group.add(Bullet(self.rect.right - 15, self.rect.y, self.rect.y, - c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False)) + c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, effect=False)) self.shoot_timer = self.current_time elif self.firstShot and (self.current_time - self.shoot_timer) > 100: self.firstShot = False self.bullet_group.add(Bullet(self.rect.right - 15, self.rect.y, self.rect.y, - c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False)) + c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, effect=False)) class ThreePeaShooter(Plant): @@ -337,7 +338,7 @@ class ThreePeaShooter(Plant): continue dest_y = self.rect.y + (i - 1) * c.GRID_Y_SIZE + offset_y self.bullet_groups[tmp_y].add(Bullet(self.rect.right - 15, self.rect.y, dest_y, - c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, False)) + c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, effect=False)) self.shoot_timer = self.current_time @@ -349,7 +350,7 @@ class SnowPeaShooter(Plant): def attacking(self): if (self.current_time - self.shoot_timer) > 1400: self.bullet_group.add(Bullet(self.rect.right - 15, self.rect.y, self.rect.y, - c.BULLET_PEA_ICE, c.BULLET_DAMAGE_NORMAL, True)) + c.BULLET_PEA_ICE, c.BULLET_DAMAGE_NORMAL, effect=c.BULLET_EFFECT_ICE)) self.shoot_timer = self.current_time @@ -507,7 +508,7 @@ class PuffShroom(Plant): def attacking(self): if (self.current_time - self.shoot_timer) > 1400: self.bullet_group.add(Bullet(self.rect.right, self.rect.y + 10, self.rect.y + 10, - c.BULLET_MUSHROOM, c.BULLET_DAMAGE_NORMAL, False)) + c.BULLET_MUSHROOM, c.BULLET_DAMAGE_NORMAL, effect=False)) self.shoot_timer = self.current_time def canAttack(self, zombie): @@ -760,7 +761,7 @@ class ScaredyShroom(Plant): def attacking(self): if (self.current_time - self.shoot_timer) > 1400: self.bullet_group.add(Bullet(self.rect.right - 15, self.rect.y + 40, self.rect.y + 40, - c.BULLET_MUSHROOM, c.BULLET_DAMAGE_NORMAL, False)) + c.BULLET_MUSHROOM, c.BULLET_DAMAGE_NORMAL, effect=False)) self.shoot_timer = self.current_time @@ -1035,4 +1036,21 @@ class RedWallNutBowling(Plant): class LilyPad(Plant): def __init__(self, x, y): - Plant.__init__(self, x, y, c.LILYPAD, c.PLANT_HEALTH, None) \ No newline at end of file + Plant.__init__(self, x, y, c.LILYPAD, c.PLANT_HEALTH, None) + +class TorchWood(Plant): + def __init__(self, x, y, bullet_group): + Plant.__init__(self, x, y, c.TORCHWOOD, c.PLANT_HEALTH, bullet_group) + + def idling(self): + for i in self.bullet_group: + if i.passedTorchWood != self.rect.x: + if -10 <= i.rect.x - self.rect.x <= 20: + if i.name == c.BULLET_PEA: + self.bullet_group.add(Bullet(i.rect.x, i.rect.y, i.rect.y, + c.BULLET_FIREBALL, c.BULLET_DAMAGE_FIREBALL_BODY, effect=c.BULLET_EFFECT_UNICE, passedTorchWood=self.rect.x)) + i.kill() + elif i.name == c.BULLET_PEA_ICE: + self.bullet_group.add(Bullet(i.rect.x, i.rect.y, i.rect.y, + c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, effect=False, passedTorchWood=self.rect.x)) + i.kill() diff --git a/source/component/zombie.py b/source/component/zombie.py index 4b5a869..f7b1f29 100755 --- a/source/component/zombie.py +++ b/source/component/zombie.py @@ -200,14 +200,21 @@ class Zombie(pg.sprite.Sprite): if (self.current_time - self.ice_slow_timer) > c.ICE_SLOW_TIME: self.ice_slow_ratio = 1 - def setDamage(self, damage, ice=False, damageType=c.ZOMBIE_COMMON_DAMAGE): + def setDamage(self, damage, effect=False, damageType=c.ZOMBIE_COMMON_DAMAGE): # 冰冻减速效果 - if ice: + if effect == c.BULLET_EFFECT_ICE: if damageType == c.ZOMBIE_DEAFULT_DAMAGE: # 寒冰射手不能穿透二类防具进行减速 if not self.helmetType2: self.setIceSlow() else: self.setIceSlow() + # 解冻 + elif effect == c.BULLET_EFFECT_UNICE: + if damageType == c.ZOMBIE_DEAFULT_DAMAGE: # 寒冰射手不能穿透二类防具进行减速 + if not self.helmetType2: + self.ice_slow_ratio = 1 + else: + self.ice_slow_ratio = 1 if damageType == c.ZOMBIE_DEAFULT_DAMAGE: # 不穿透二类防具的攻击 # 从第二类防具开始逐级传递 @@ -274,7 +281,7 @@ class Zombie(pg.sprite.Sprite): self.health -= damage else: print('警告:植物攻击类型错误,现在默认进行类豌豆射手型攻击') - setDamage(damage, ice=ice, damageType=c.ZOMBIE_DEAFULT_DAMAGE) + setDamage(damage, effect=effect, damageType=c.ZOMBIE_DEAFULT_DAMAGE) # 记录攻击时间 self.hit_timer = self.current_time diff --git a/source/constants.py b/source/constants.py index 78f68ba..a8f8441 100755 --- a/source/constants.py +++ b/source/constants.py @@ -149,6 +149,7 @@ HYPNOSHROOM = 'HypnoShroom' WALLNUTBOWLING = 'WallNutBowling' REDWALLNUTBOWLING = 'RedWallNutBowling' LILYPAD = 'LilyPad' +TORCHWOOD = 'TorchWood' PLANT_HEALTH = 300 WALLNUT_HEALTH = 4000 @@ -186,12 +187,21 @@ CARD_ICESHROOM = 'card_iceshroom' CARD_HYPNOSHROOM = 'card_hypnoshroom' CARD_REDWALLNUT = 'card_redwallnut' CARD_LILYPAD = 'card_lilypad' +CARD_TORCHWOOD = 'card_torchwood' #BULLET INFO +# 子弹类型 BULLET_PEA = 'PeaNormal' BULLET_PEA_ICE = 'PeaIce' +BULLET_FIREBALL = 'Fireball' BULLET_MUSHROOM = 'BulletMushRoom' +# 子弹伤害 BULLET_DAMAGE_NORMAL = 20 +BULLET_DAMAGE_FIREBALL_BODY = 27 # 这是火球本体的伤害,注意不是40,本体(27) + 溅射(13)才是40 +BULLET_DAMAGE_FIREBALL_RANGE = 13 +# 子弹效果 +BULLET_EFFECT_ICE = 'ice' +BULLET_EFFECT_UNICE = 'unice' #ZOMBIE INFO ZOMBIE_IMAGE_RECT = 'zombie_image_rect' diff --git a/source/state/level.py b/source/state/level.py index ac9c3e4..0dd0d46 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -517,6 +517,8 @@ class Level(tool.State): new_plant = plant.RedWallNutBowling(x, y) elif self.plant_name == c.LILYPAD: new_plant = plant.LilyPad(x, y) + elif self.plant_name == c.TORCHWOOD: + new_plant = plant.TorchWood(x, y, self.bullet_groups[map_y]) if new_plant.can_sleep and self.background_type in {c.BACKGROUND_DAY, c.BACKGROUND_POOL, c.BACKGROUND_ROOF, c.BACKGROUND_WALLNUTBOWLING, c.BACKGROUND_SINGLE, c.BACKGROUND_TRIPLE}: new_plant.setSleep() @@ -597,9 +599,15 @@ class Level(tool.State): if bullet.state == c.FLY: zombie = pg.sprite.spritecollideany(bullet, self.zombie_groups[i], collided_func) if zombie and zombie.state != c.DIE: - zombie.setDamage(bullet.damage, ice=bullet.ice, damageType=c.ZOMBIE_DEAFULT_DAMAGE) + # 这里生效代表已经发生了碰撞 + zombie.setDamage(bullet.damage, effect=bullet.effect, damageType=c.ZOMBIE_DEAFULT_DAMAGE) bullet.setExplode() - + # 火球有溅射伤害 + if bullet.name == c.BULLET_FIREBALL: + for rangeZombie in self.zombie_groups[i]: + if abs(rangeZombie.rect.x - bullet.rect.x) <= (c.GRID_X_SIZE // 2): + rangeZombie.setDamage(c.BULLET_DAMAGE_FIREBALL_RANGE, effect=False, damageType=c.ZOMBIE_DEAFULT_DAMAGE) + def checkZombieCollisions(self): if self.bar_type == c.CHOSSEBAR_BOWLING: ratio = 0.6 @@ -649,13 +657,15 @@ class Level(tool.State): if car.dead: self.cars.remove(car) - def boomZombies(self, x, map_y, y_range, x_range): + def boomZombies(self, x, map_y, y_range, x_range, effect=False): for i in range(self.map_y_len): if abs(i - map_y) > y_range: continue for zombie in self.zombie_groups[i]: if ((abs(zombie.rect.centerx - x) <= x_range) or ((zombie.rect.right - (x-x_range) > 20) or (zombie.rect.right - (x-x_range))/zombie.rect.width > 0.2, ((x+x_range) - zombie.rect.left > 20) or ((x+x_range) - zombie.rect.left)/zombie.rect.width > 0.2)[zombie.rect.x > x]): # 这代码不太好懂,后面是一个判断僵尸在左还是在右,前面是一个元组,[0]是在左边的情况,[1]是在右边的情况 + if effect == c.BULLET_EFFECT_UNICE: + zombie.ice_slow_ratio = 1 zombie.setDamage(1800, damageType=c.ZOMBIE_ASH_DAMAGE) if zombie.health <= 0: zombie.setBoomDie() @@ -680,10 +690,12 @@ class Level(tool.State): self.map.map[map_y][map_x][c.MAP_SLEEP] = False # 用铲子铲不用触发植物功能 if not shovel: - if (plant.name == c.CHERRYBOMB or plant.name == c.JALAPENO or - plant.name == c.REDWALLNUTBOWLING): + if (plant.name == c.CHERRYBOMB or plant.name == c.REDWALLNUTBOWLING): self.boomZombies(plant.rect.centerx, map_y, plant.explode_y_range, plant.explode_x_range) + elif plant.name == c.JALAPENO: + self.boomZombies(plant.rect.centerx, map_y, plant.explode_y_range, + plant.explode_x_range, effect=c.BULLET_EFFECT_UNICE) elif plant.name == c.ICESHROOM and plant.state != c.SLEEP: self.freezeZombies(plant) elif plant.name == c.HYPNOSHROOM and plant.state != c.SLEEP: