diff --git a/resources/sound/firepea.ogg b/resources/sound/firepea.ogg index f068615..c5952eb 100644 Binary files a/resources/sound/firepea.ogg and b/resources/sound/firepea.ogg differ diff --git a/resources/sound/hypnoed.ogg b/resources/sound/hypnoed.ogg new file mode 100644 index 0000000..d1cba98 Binary files /dev/null and b/resources/sound/hypnoed.ogg differ diff --git a/resources/sound/plantDie.ogg b/resources/sound/plantDie.ogg new file mode 100644 index 0000000..ca3c4d2 Binary files /dev/null and b/resources/sound/plantDie.ogg differ diff --git a/resources/sound/plantGrow.ogg b/resources/sound/plantGrow.ogg new file mode 100644 index 0000000..52a647a Binary files /dev/null and b/resources/sound/plantGrow.ogg differ diff --git a/resources/sound/puff.ogg b/resources/sound/puff.ogg new file mode 100644 index 0000000..39d1ff2 Binary files /dev/null and b/resources/sound/puff.ogg differ diff --git a/resources/sound/shoot.ogg b/resources/sound/shoot.ogg new file mode 100644 index 0000000..f8449a5 Binary files /dev/null and b/resources/sound/shoot.ogg differ diff --git a/resources/sound/snowPeaSparkles.ogg b/resources/sound/snowPeaSparkles.ogg new file mode 100644 index 0000000..4917bdb Binary files /dev/null and b/resources/sound/snowPeaSparkles.ogg differ diff --git a/resources/sound/zombieEnteringWater.ogg b/resources/sound/zombieEnteringWater.ogg new file mode 100644 index 0000000..a9bb43f Binary files /dev/null and b/resources/sound/zombieEnteringWater.ogg differ diff --git a/source/component/plant.py b/source/component/plant.py index 86c465e..da75834 100755 --- a/source/component/plant.py +++ b/source/component/plant.py @@ -83,6 +83,8 @@ class Bullet(pg.sprite.Sprite): explode_name = 'PeaIceExplode' elif self.name == c.BULLET_SEASHROOM: explode_name = 'BulletSeaShroomExplode' + elif self.name == c.BULLET_STAR: + explode_name = 'StarBulletExplode' else: explode_name = 'PeaNormalExplode' @@ -123,49 +125,11 @@ class Bullet(pg.sprite.Sprite): # 杨桃的子弹 class StarBullet(Bullet): def __init__(self, x, start_y, damage, direction, level): # direction指星星飞行方向 - pg.sprite.Sprite.__init__(self) + Bullet.__init__(self, x, start_y, start_y, c.BULLET_STAR, damage) - self.name = c.BULLET_STAR self.level = level - self.frames = [] - self.effect = False - self.frame_index = 0 - self.load_images() - self.image = self.frames[self.frame_index] - self.rect = self.image.get_rect() - self.rect.x = x - self.rect.y = start_y _, self.map_y = self.level.map.getMapIndex(self.rect.x, self.rect.centery) self.direction = direction - self.damage = damage - self.state = c.FLY - self.current_time = 0 - self.passedTorchWood = None - - def loadFrames(self, frames, name): - frame_list = tool.GFX[name] - if name in tool.PLANT_RECT: - data = tool.PLANT_RECT[name] - x, y, width, height = data['x'], data['y'], data['width'], data['height'] - else: - x, y = 0, 0 - rect = frame_list[0].get_rect() - width, height = rect.w, rect.h - - for frame in frame_list: - frames.append(tool.get_image(frame, x, y, width, height)) - - def load_images(self): - self.fly_frames = [] - self.explode_frames = [] - - fly_name = self.name - explode_name = 'StarBulletExplode' - - self.loadFrames(self.fly_frames, fly_name) - self.loadFrames(self.explode_frames, explode_name) - - self.frames = self.fly_frames def update(self, game_info): self.current_time = game_info[c.CURRENT_TIME] @@ -190,15 +154,6 @@ class StarBullet(Bullet): if (self.current_time - self.explode_timer) > 250: self.kill() - def setExplode(self): - self.state = c.EXPLODE - self.explode_timer = self.current_time - self.frames = self.explode_frames - self.image = self.frames[self.frame_index] - - def draw(self, surface): - surface.blit(self.image, self.rect) - # 这里用的是坚果保龄球的代码改一下,实现子弹换行 def handleMapYPosition(self): _, map_y1 = self.level.map.getMapIndex(self.rect.x, self.rect.centery +20) @@ -390,6 +345,8 @@ class PeaShooter(Plant): self.bullet_group.add(Bullet(self.rect.right - 15, self.rect.y, self.rect.y, c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, effect=False)) self.shoot_timer = self.current_time + # 播放发射音效 + pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "shoot.ogg")).play() class RepeaterPea(Plant): @@ -406,10 +363,14 @@ class RepeaterPea(Plant): self.bullet_group.add(Bullet(self.rect.right - 15, self.rect.y, self.rect.y, c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, effect=False)) self.shoot_timer = self.current_time + # 播放发射音效 + pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "shoot.ogg")).play() 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, effect=False)) + # 播放发射音效 + pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "shoot.ogg")).play() class ThreePeaShooter(Plant): @@ -434,6 +395,8 @@ class ThreePeaShooter(Plant): self.bullet_groups[tmp_y].add(Bullet(self.rect.right - 15, self.rect.y, dest_y, c.BULLET_PEA, c.BULLET_DAMAGE_NORMAL, effect=False)) self.shoot_timer = self.current_time + # 播放发射音效 + pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "shoot.ogg")).play() class SnowPeaShooter(Plant): @@ -446,6 +409,10 @@ class SnowPeaShooter(Plant): self.bullet_group.add(Bullet(self.rect.right - 15, self.rect.y, self.rect.y, c.BULLET_PEA_ICE, c.BULLET_DAMAGE_NORMAL, effect=c.BULLET_EFFECT_ICE)) self.shoot_timer = self.current_time + # 播放发射音效 + pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "shoot.ogg")).play() + # 播放冰子弹音效 + pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "snowPeaSparkles")).play() class WallNut(Plant): @@ -608,6 +575,8 @@ class PuffShroom(Plant): self.bullet_group.add(Bullet(self.rect.right, self.rect.y + 10, self.rect.y + 10, c.BULLET_MUSHROOM, c.BULLET_DAMAGE_NORMAL, effect=False)) self.shoot_timer = self.current_time + # 播放音效 + pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "puff.ogg")).play() def canAttack(self, zombie): if (self.rect.x <= zombie.rect.right and @@ -771,6 +740,8 @@ class Spikeweed(Plant): for zombie in self.zombie_group: if self.canAttack(zombie): zombie.setDamage(20, damageType=c.ZOMBIE_COMMON_DAMAGE) + # 播放攻击音效,同子弹打击 + pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "bulletExplode.ogg")).play() class Jalapeno(Plant): @@ -865,6 +836,8 @@ class ScaredyShroom(Plant): self.bullet_group.add(Bullet(self.rect.right - 15, self.rect.y + 40, self.rect.y + 40, c.BULLET_MUSHROOM, c.BULLET_DAMAGE_NORMAL, effect=False)) self.shoot_timer = self.current_time + # 播放音效 + pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "puff.ogg")).play() class SunShroom(Plant): @@ -901,7 +874,8 @@ class SunShroom(Plant): elif (self.current_time - self.change_timer) > 100000: self.changeFrames(self.big_frames) self.is_big = True - + # 播放长大音效 + pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "plantGrow.ogg")).play() if self.sun_timer == 0: self.sun_timer = self.current_time - (c.FLOWER_SUN_INTERVAL - 6000) elif (self.current_time - self.sun_timer) > c.FLOWER_SUN_INTERVAL: @@ -1194,6 +1168,8 @@ class StarFruit(Plant): self.bullet_group.add(StarBullet(self.rect.right - 5, self.rect.bottom - 20, c.BULLET_DAMAGE_NORMAL, c.STAR_FORWARD_DOWN, self.level)) self.bullet_group.add(StarBullet(self.rect.right - 5, self.rect.y - 10, c.BULLET_DAMAGE_NORMAL, c.STAR_FORWARD_UP, self.level)) self.shoot_timer = self.current_time + # 播放发射音效 + pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "shoot.ogg")).play() class CoffeeBean(Plant): @@ -1243,6 +1219,8 @@ class SeaShroom(Plant): self.bullet_group.add(Bullet(self.rect.right, self.rect.y + 50, self.rect.y + 50, c.BULLET_SEASHROOM, c.BULLET_DAMAGE_NORMAL, effect=False)) self.shoot_timer = self.current_time + # 播放发射音效 + pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "puff.ogg")).play() def canAttack(self, zombie): if (self.rect.x <= zombie.rect.right and diff --git a/source/component/zombie.py b/source/component/zombie.py index 849f1cf..9798d2c 100755 --- a/source/component/zombie.py +++ b/source/component/zombie.py @@ -110,6 +110,8 @@ class Zombie(pg.sprite.Sprite): if not self.swimming: self.swimming = True self.changeFrames(self.swim_frames) + # 播放入水音效 + pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "zombieEnteringWater.ogg")).play() # 同样没有兼容双防具 if self.helmet: if self.helmetHealth <= 0: @@ -451,6 +453,8 @@ class Zombie(pg.sprite.Sprite): def setHypno(self): self.is_hypno = True self.setWalk() + # 播放魅惑音效 + pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "hypnoed.ogg")).play() class ZombieHead(Zombie): diff --git a/source/state/level.py b/source/state/level.py index f1f485a..3240930 100644 --- a/source/state/level.py +++ b/source/state/level.py @@ -995,6 +995,8 @@ class Level(tool.State): self.map.map[map_y][map_x][c.MAP_SLEEP] = False # 用铲子铲不用触发植物功能 if not shovel: + # 触发植物死亡音效 + pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "plantDie.ogg")).play() 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)