diff --git a/resources/graphics/Bullets/StarBulletExplode/StarBulletExplode_0.png b/resources/graphics/Bullets/StarBulletExplode/StarBulletExplode_0.png new file mode 100644 index 0000000..95e802b Binary files /dev/null and b/resources/graphics/Bullets/StarBulletExplode/StarBulletExplode_0.png differ diff --git a/resources/graphics/Cards/card_starfruit.png b/resources/graphics/Cards/card_starfruit.png new file mode 100644 index 0000000..af7be92 Binary files /dev/null and b/resources/graphics/Cards/card_starfruit.png differ diff --git a/resources/graphics/Plants/StarFruit/StarFruit_0.png b/resources/graphics/Plants/StarFruit/StarFruit_0.png index e8067dd..1d5a49c 100644 Binary files a/resources/graphics/Plants/StarFruit/StarFruit_0.png and b/resources/graphics/Plants/StarFruit/StarFruit_0.png differ diff --git a/resources/graphics/Plants/StarFruit/StarFruit_1.png b/resources/graphics/Plants/StarFruit/StarFruit_1.png index 6ef2c33..b0b8e7a 100644 Binary files a/resources/graphics/Plants/StarFruit/StarFruit_1.png and b/resources/graphics/Plants/StarFruit/StarFruit_1.png differ diff --git a/resources/graphics/Plants/StarFruit/StarFruit_10.png b/resources/graphics/Plants/StarFruit/StarFruit_10.png new file mode 100644 index 0000000..47183c5 Binary files /dev/null and b/resources/graphics/Plants/StarFruit/StarFruit_10.png differ diff --git a/resources/graphics/Plants/StarFruit/StarFruit_11.png b/resources/graphics/Plants/StarFruit/StarFruit_11.png new file mode 100644 index 0000000..10e83c0 Binary files /dev/null and b/resources/graphics/Plants/StarFruit/StarFruit_11.png differ diff --git a/resources/graphics/Plants/StarFruit/StarFruit_12.png b/resources/graphics/Plants/StarFruit/StarFruit_12.png new file mode 100644 index 0000000..7b1bdbe Binary files /dev/null and b/resources/graphics/Plants/StarFruit/StarFruit_12.png differ diff --git a/resources/graphics/Plants/StarFruit/StarFruit_2.png b/resources/graphics/Plants/StarFruit/StarFruit_2.png index b0ba74e..62339ad 100644 Binary files a/resources/graphics/Plants/StarFruit/StarFruit_2.png and b/resources/graphics/Plants/StarFruit/StarFruit_2.png differ diff --git a/resources/graphics/Plants/StarFruit/StarFruit_3.png b/resources/graphics/Plants/StarFruit/StarFruit_3.png index 907d132..f9d8d98 100644 Binary files a/resources/graphics/Plants/StarFruit/StarFruit_3.png and b/resources/graphics/Plants/StarFruit/StarFruit_3.png differ diff --git a/resources/graphics/Plants/StarFruit/StarFruit_4.png b/resources/graphics/Plants/StarFruit/StarFruit_4.png index 94daa88..a72bf21 100644 Binary files a/resources/graphics/Plants/StarFruit/StarFruit_4.png and b/resources/graphics/Plants/StarFruit/StarFruit_4.png differ diff --git a/resources/graphics/Plants/StarFruit/StarFruit_5.png b/resources/graphics/Plants/StarFruit/StarFruit_5.png index f474dc6..ab13bd0 100644 Binary files a/resources/graphics/Plants/StarFruit/StarFruit_5.png and b/resources/graphics/Plants/StarFruit/StarFruit_5.png differ diff --git a/resources/graphics/Plants/StarFruit/StarFruit_6.png b/resources/graphics/Plants/StarFruit/StarFruit_6.png index 3cb2c3d..9c769ae 100644 Binary files a/resources/graphics/Plants/StarFruit/StarFruit_6.png and b/resources/graphics/Plants/StarFruit/StarFruit_6.png differ diff --git a/resources/graphics/Plants/StarFruit/StarFruit_7.png b/resources/graphics/Plants/StarFruit/StarFruit_7.png index bfef997..d2712d3 100644 Binary files a/resources/graphics/Plants/StarFruit/StarFruit_7.png and b/resources/graphics/Plants/StarFruit/StarFruit_7.png differ diff --git a/resources/graphics/Plants/StarFruit/StarFruit_8.png b/resources/graphics/Plants/StarFruit/StarFruit_8.png index 602cb5e..d2712d3 100644 Binary files a/resources/graphics/Plants/StarFruit/StarFruit_8.png and b/resources/graphics/Plants/StarFruit/StarFruit_8.png differ diff --git a/resources/graphics/Plants/StarFruit/StarFruit_9.png b/resources/graphics/Plants/StarFruit/StarFruit_9.png index 53c5163..8cd84ca 100644 Binary files a/resources/graphics/Plants/StarFruit/StarFruit_9.png and b/resources/graphics/Plants/StarFruit/StarFruit_9.png differ diff --git a/source/component/menubar.py b/source/component/menubar.py index eb37f14..d516662 100755 --- a/source/component/menubar.py +++ b/source/component/menubar.py @@ -81,6 +81,10 @@ plantInfo = (#元组 (植物名称, 卡片名称, 阳光, 冷却时间) c.CARD_TORCHWOOD, 175, 7500), + (c.STARFRUIT, + c.CARD_STARFRUIT, + 125, + 7500), # 应当保证这两个在一般模式下不可选的特殊植物恒在最后 (c.WALLNUTBOWLING, c.CARD_WALLNUT, @@ -349,7 +353,7 @@ class Panel(): self.selected_cards.remove(delete_card) self.selected_num -= 1 - if self.selected_num >= c.BAR_CARD_X_INTERNAL: + if self.selected_num >= c.CARD_MAX_NUM: return for card in self.card_list: diff --git a/source/component/plant.py b/source/component/plant.py index b5cb8e7..a74b8c2 100755 --- a/source/component/plant.py +++ b/source/component/plant.py @@ -109,10 +109,10 @@ class Bullet(pg.sprite.Sprite): # 杨桃的子弹 class StarBullet(Bullet): - def __init__(self, x, start_y, name, damage, direction): # direction指星星飞行方向 + def __init__(self, x, start_y, damage, direction): # direction指星星飞行方向 pg.sprite.Sprite.__init__(self) - self.name = name + self.name = c.BULLET_STAR self.frames = [] self.frame_index = 0 self.load_images() @@ -143,7 +143,7 @@ class StarBullet(Bullet): self.explode_frames = [] fly_name = self.name - explode_name = 'PeaNormalExplode' + explode_name = 'StarBulletExplode' self.loadFrames(self.fly_frames, fly_name) self.loadFrames(self.explode_frames, explode_name) @@ -153,12 +153,20 @@ class StarBullet(Bullet): def update(self, game_info): self.current_time = game_info[c.CURRENT_TIME] if self.state == c.FLY: - if self.rect.y != self.dest_y: - self.rect.y += self.y_vel - if self.y_vel * (self.dest_y - self.rect.y) < 0: - self.rect.y = self.dest_y - self.rect.x += self.x_vel - if self.rect.x > c.SCREEN_WIDTH: + if self.direction == c.STAR_FORWARD_UP: + self.rect.x += 7 + self.rect.y -= 7 + elif self.direction == c.STAR_FORWARD_DOWN: + self.rect.x += 7 + self.rect.y += 7 + elif self.direction == c.STAR_UPWARD: + self.rect.y -= 10 + elif self.direction == c.STAR_DOWNWARD: + self.rect.y += 10 + else: + self.rect.x -= 10 + if ((self.rect.x > c.SCREEN_WIDTH) or (self.rect.x < 0) + or (self.rect.y > c.SCREEN_HEIGHT) or (self.rect.y < 0)): self.kill() elif self.state == c.EXPLODE: if (self.current_time - self.explode_timer) > 250: @@ -1112,3 +1120,29 @@ class TorchWood(Plant): 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() + +class StarFruit(Plant): + def __init__(self, x, y, bullet_group, global_bullet_group): + Plant.__init__(self, x, y, c.STARFRUIT, c.PLANT_HEALTH, bullet_group) + self.global_bullet_group = global_bullet_group + self.shoot_timer = 0 + + def canAttack(self, zombie): + if zombie.state != c.DIE: + if (self.rect.x >= zombie.rect.x) and abs(zombie.rect.bottom - self.rect.bottom) <= 30: # 对于同行且在杨桃后的僵尸 + return True + elif 0.9*abs(zombie.rect.y - self.rect.y) <= abs(zombie.rect.x - self.rect.x) <= 1.1*abs(zombie.rect.y - self.rect.y): + return True + elif zombie.rect.left <= self.rect.x <= zombie.rect.right: + return True + return False + + def attacking(self): + if (self.current_time - self.shoot_timer) > 1400: + self.bullet_group.add(StarBullet(self.rect.left + 10, self.rect.y, c.BULLET_DAMAGE_NORMAL, c.STAR_BACKWARD)) + self.global_bullet_group.add(StarBullet(self.rect.centerx, self.rect.bottom - self.rect.h + 5, c.BULLET_DAMAGE_NORMAL, c.STAR_UPWARD)) + self.global_bullet_group.add(StarBullet(self.rect.centerx, self.rect.bottom - 5, c.BULLET_DAMAGE_NORMAL, c.STAR_DOWNWARD)) + self.global_bullet_group.add(StarBullet(self.rect.left + 5, self.rect.y + 10, c.BULLET_DAMAGE_NORMAL, c.STAR_FORWARD_DOWN)) + self.global_bullet_group.add(StarBullet(self.rect.left + 5, self.rect.y - 10, c.BULLET_DAMAGE_NORMAL, c.STAR_FORWARD_UP)) + self.shoot_timer = self.current_time + diff --git a/source/component/zombie.py b/source/component/zombie.py index f7b1f29..fba96c9 100755 --- a/source/component/zombie.py +++ b/source/component/zombie.py @@ -202,6 +202,7 @@ class Zombie(pg.sprite.Sprite): def setDamage(self, damage, effect=False, damageType=c.ZOMBIE_COMMON_DAMAGE): # 冰冻减速效果 + print(damage, effect, damageType) if effect == c.BULLET_EFFECT_ICE: if damageType == c.ZOMBIE_DEAFULT_DAMAGE: # 寒冰射手不能穿透二类防具进行减速 if not self.helmetType2: diff --git a/source/constants.py b/source/constants.py index dd3f6ea..98e973e 100755 --- a/source/constants.py +++ b/source/constants.py @@ -181,6 +181,7 @@ WALLNUTBOWLING = 'WallNutBowling' REDWALLNUTBOWLING = 'RedWallNutBowling' LILYPAD = 'LilyPad' TORCHWOOD = 'TorchWood' +STARFRUIT = 'StarFruit' # 植物生命值 PLANT_HEALTH = 300 @@ -222,6 +223,7 @@ CARD_HYPNOSHROOM = 'card_hypnoshroom' CARD_REDWALLNUT = 'card_redwallnut' CARD_LILYPAD = 'card_lilypad' CARD_TORCHWOOD = 'card_torchwood' +CARD_STARFRUIT = 'card_starfruit' # 子弹信息 # 子弹类型 @@ -237,7 +239,10 @@ BULLET_DAMAGE_FIREBALL_RANGE = 13 BULLET_EFFECT_ICE = 'ice' BULLET_EFFECT_UNICE = 'unice' +# 特殊子弹 # 杨桃子弹 +# 子弹名称 +BULLET_STAR = 'StarBullet' # 子弹方向 STAR_FORWARD_UP = 'forwardUp' # 向前上方 STAR_FORWARD_DOWN = 'forwardDown' #向前下方 diff --git a/source/state/level.py b/source/state/level.py index 1a0b87b..643f89d 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -97,6 +97,7 @@ class Level(tool.State): self.zombie_groups = [] self.hypno_zombie_groups = [] #zombies who are hypno after eating hypnoshroom self.bullet_groups = [] + self.global_bullet_group = pg.sprite.Group() # 全局可用的子弹 for i in range(self.map_y_len): self.plant_groups.append(pg.sprite.Group()) self.zombie_groups.append(pg.sprite.Group()) @@ -360,6 +361,7 @@ class Level(tool.State): self.createZombie(data[1]) self.zombie_list.remove(data) + self.global_bullet_group.update((self.game_info)) for i in range(self.map_y_len): self.bullet_groups[i].update(self.game_info) self.plant_groups[i].update(self.game_info) @@ -434,6 +436,7 @@ class Level(tool.State): # 检查碰撞啥的 self.checkBulletCollisions() + self.checkGlobalBulletCollision() self.checkZombieCollisions() self.checkPlants() self.checkCarCollisions() @@ -535,6 +538,8 @@ class Level(tool.State): new_plant = plant.LilyPad(x, y) elif self.plant_name == c.TORCHWOOD: new_plant = plant.TorchWood(x, y, self.bullet_groups[map_y]) + elif self.plant_name == c.STARFRUIT: + new_plant = plant.StarFruit(x, y, self.bullet_groups[map_y], self.global_bullet_group) 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() @@ -631,6 +636,19 @@ class Level(tool.State): 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 checkGlobalBulletCollision(self): + collided_func = pg.sprite.collide_circle_ratio(0.7) + for i in range(self.map_y_len): + for globalBullet in self.global_bullet_group: + if globalBullet.state == c.FLY: + zombie = pg.sprite.spritecollideany(globalBullet, self.zombie_groups[i], collided_func) + if zombie and zombie.state != c.DIE: + # 这里生效代表已经发生了碰撞 + zombie.setDamage(globalBullet.damage, damageType=c.ZOMBIE_COMMON_DAMAGE) # 这里设定刻意与原版不同:逻辑上,杨桃是斜着打的,伤害应当可用穿透二类防具 + globalBullet.setExplode() + + def checkZombieCollisions(self): if self.bar_type == c.CHOSSEBAR_BOWLING: ratio = 0.6 @@ -820,6 +838,24 @@ class Level(tool.State): plant.setAttack() elif plant.state != c.IDLE: plant.setIdle() + elif plant.name == c.STARFRUIT: + can_attack = False + if (plant.state == c.IDLE): + ''' + totalZombie = 0 + for zombieColumn in range(self.map_y_len): + totalZombie += len(self.zombie_groups[zombieColumn]) + if totalZombie > 0: # 只要场上有僵尸就需要判断 + ''' + for zombie_group in self.zombie_groups: # 遍历循环所有僵尸 + for zombie in zombie_group: + if plant.canAttack(zombie): + can_attack = True + break + if plant.state == c.IDLE and can_attack: + plant.setAttack() + elif (plant.state == c.ATTACK and not can_attack): + plant.setIdle() elif(plant.name == c.WALLNUTBOWLING or plant.name == c.REDWALLNUTBOWLING): pass @@ -920,6 +956,7 @@ class Level(tool.State): self.menubar.draw(surface) for car in self.cars: car.draw(surface) + self.global_bullet_group.draw(surface) for i in range(self.map_y_len): self.plant_groups[i].draw(surface) self.zombie_groups[i].draw(surface)