尝试加入音效
This commit is contained in:
parent
89445251ec
commit
8526d2ed1b
BIN
resources/sound/shovel.ogg
Normal file
BIN
resources/sound/shovel.ogg
Normal file
Binary file not shown.
@ -30,6 +30,8 @@ class Car(pg.sprite.Sprite):
|
|||||||
def setWalk(self):
|
def setWalk(self):
|
||||||
if self.state == c.IDLE:
|
if self.state == c.IDLE:
|
||||||
self.state = c.WALK
|
self.state = c.WALK
|
||||||
|
# 播放音效
|
||||||
|
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "carWalking.ogg"))
|
||||||
|
|
||||||
def draw(self, surface):
|
def draw(self, surface):
|
||||||
surface.blit(self.image, self.rect)
|
surface.blit(self.image, self.rect)
|
||||||
@ -108,6 +110,12 @@ class Bullet(pg.sprite.Sprite):
|
|||||||
self.frames = self.explode_frames
|
self.frames = self.explode_frames
|
||||||
self.image = self.frames[self.frame_index]
|
self.image = self.frames[self.frame_index]
|
||||||
|
|
||||||
|
# 播放子弹爆炸音效
|
||||||
|
if self.name == c.BULLET_FIREBALL:
|
||||||
|
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "firepea.ogg"))
|
||||||
|
else:
|
||||||
|
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "bulletExplode.ogg"))
|
||||||
|
|
||||||
def draw(self, surface):
|
def draw(self, surface):
|
||||||
surface.blit(self.image, self.rect)
|
surface.blit(self.image, self.rect)
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import pygame as pg
|
import pygame as pg
|
||||||
|
from random import randint
|
||||||
from .. import tool
|
from .. import tool
|
||||||
from .. import constants as c
|
from .. import constants as c
|
||||||
|
|
||||||
@ -221,8 +222,11 @@ class Zombie(pg.sprite.Sprite):
|
|||||||
if self.checkToDie(self.losthead_attack_frames):
|
if self.checkToDie(self.losthead_attack_frames):
|
||||||
return
|
return
|
||||||
|
|
||||||
if (self.current_time - self.freeze_timer) > c.FREEZE_TIME:
|
if (self.current_time - self.freeze_timer) >= c.MIN_FREEZE_TIME + randint(0, 2000):
|
||||||
self.setWalk()
|
self.setWalk()
|
||||||
|
# 注意寒冰菇解冻后还有减速
|
||||||
|
self.ice_slow_timer = self.freeze_timer + 10000 # 每次冰冻冻结 + 减速时间为20 s,而减速有10 s计时,故这里+10 s
|
||||||
|
self.ice_slow_ratio = 2
|
||||||
|
|
||||||
def setLostHead(self):
|
def setLostHead(self):
|
||||||
self.losthead_timer = self.current_time
|
self.losthead_timer = self.current_time
|
||||||
@ -274,6 +278,9 @@ class Zombie(pg.sprite.Sprite):
|
|||||||
return self.ice_slow_ratio # 攻击速度只取决于冰冻状态
|
return self.ice_slow_ratio # 攻击速度只取决于冰冻状态
|
||||||
|
|
||||||
def setIceSlow(self):
|
def setIceSlow(self):
|
||||||
|
# 在转入冰冻减速状态时播放冰冻音效
|
||||||
|
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "freeze.ogg"))
|
||||||
|
|
||||||
# when get a ice bullet damage, slow the attack or walk speed of the zombie
|
# when get a ice bullet damage, slow the attack or walk speed of the zombie
|
||||||
self.ice_slow_timer = self.current_time
|
self.ice_slow_timer = self.current_time
|
||||||
self.ice_slow_ratio = 2
|
self.ice_slow_ratio = 2
|
||||||
@ -412,6 +419,9 @@ class Zombie(pg.sprite.Sprite):
|
|||||||
else:
|
else:
|
||||||
self.changeFrames(self.attack_frames)
|
self.changeFrames(self.attack_frames)
|
||||||
|
|
||||||
|
# 播放啃咬音效
|
||||||
|
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "zombieAttack.ogg"))
|
||||||
|
|
||||||
def setDie(self):
|
def setDie(self):
|
||||||
self.state = c.DIE
|
self.state = c.DIE
|
||||||
self.animate_interval = self.die_animate_interval
|
self.animate_interval = self.die_animate_interval
|
||||||
|
|||||||
@ -222,7 +222,7 @@ SUN_VALUE = 25
|
|||||||
|
|
||||||
# 僵尸冷冻
|
# 僵尸冷冻
|
||||||
ICE_SLOW_TIME = 10000
|
ICE_SLOW_TIME = 10000
|
||||||
FREEZE_TIME = 7500
|
MIN_FREEZE_TIME = 4000
|
||||||
ICETRAP = 'IceTrap'
|
ICETRAP = 'IceTrap'
|
||||||
|
|
||||||
# 植物卡片信息
|
# 植物卡片信息
|
||||||
|
|||||||
@ -193,6 +193,9 @@ class Level(tool.State):
|
|||||||
self.waveTime = current_time
|
self.waveTime = current_time
|
||||||
self.waveZombies = self.waves[self.waveNum - 1]
|
self.waveZombies = self.waves[self.waveNum - 1]
|
||||||
self.numZombie = len(self.waveZombies)
|
self.numZombie = len(self.waveZombies)
|
||||||
|
# 第一波刚刚刷出来的时候播放音效
|
||||||
|
if self.waveNum == 1:
|
||||||
|
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "zombieComing.ogg"))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if ((current_time - self.waveTime >= 45000) or (self.bar_type != c.CHOOSEBAR_STATIC and current_time - self.waveTime >= 25000)):
|
if ((current_time - self.waveTime >= 45000) or (self.bar_type != c.CHOOSEBAR_STATIC and current_time - self.waveTime >= 25000)):
|
||||||
@ -200,6 +203,8 @@ class Level(tool.State):
|
|||||||
self.waveTime = current_time
|
self.waveTime = current_time
|
||||||
self.waveZombies = self.waves[self.waveNum - 1]
|
self.waveZombies = self.waves[self.waveNum - 1]
|
||||||
self.numZombie = len(self.waveZombies)
|
self.numZombie = len(self.waveZombies)
|
||||||
|
# 一大波时播放音效
|
||||||
|
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "hugeWaveApproching.ogg"))
|
||||||
return
|
return
|
||||||
elif ((current_time - self.waveTime >= 43000) or (self.bar_type != c.CHOOSEBAR_STATIC and current_time - self.waveTime >= 23000)):
|
elif ((current_time - self.waveTime >= 43000) or (self.bar_type != c.CHOOSEBAR_STATIC and current_time - self.waveTime >= 23000)):
|
||||||
self.showHugeWaveApprochingTime = current_time
|
self.showHugeWaveApprochingTime = current_time
|
||||||
@ -216,7 +221,6 @@ class Level(tool.State):
|
|||||||
self.waveTime = current_time - 23000 # 即倒计时2000 ms
|
self.waveTime = current_time - 23000 # 即倒计时2000 ms
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 旧机制,目前仅用于调试
|
# 旧机制,目前仅用于调试
|
||||||
def setupZombies(self):
|
def setupZombies(self):
|
||||||
def takeTime(element):
|
def takeTime(element):
|
||||||
@ -587,6 +591,8 @@ class Level(tool.State):
|
|||||||
if sun.checkCollision(mouse_pos[0], mouse_pos[1]):
|
if sun.checkCollision(mouse_pos[0], mouse_pos[1]):
|
||||||
self.menubar.increaseSunValue(sun.sun_value)
|
self.menubar.increaseSunValue(sun.sun_value)
|
||||||
clickedSun = True
|
clickedSun = True
|
||||||
|
# 播放收集阳光的音效
|
||||||
|
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "collectSun.ogg"))
|
||||||
|
|
||||||
# 拖动植物或者铲子
|
# 拖动植物或者铲子
|
||||||
if not self.drag_plant and mouse_pos and mouse_click[0] and not clickedSun:
|
if not self.drag_plant and mouse_pos and mouse_click[0] and not clickedSun:
|
||||||
@ -594,6 +600,8 @@ class Level(tool.State):
|
|||||||
if result:
|
if result:
|
||||||
self.setupMouseImage(result[0], result[1])
|
self.setupMouseImage(result[0], result[1])
|
||||||
clickedCardsOrMap = True
|
clickedCardsOrMap = True
|
||||||
|
# 播放音效
|
||||||
|
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "clickCard.ogg"))
|
||||||
elif self.drag_plant:
|
elif self.drag_plant:
|
||||||
if mouse_click[1]:
|
if mouse_click[1]:
|
||||||
self.removeMouseImage()
|
self.removeMouseImage()
|
||||||
@ -618,6 +626,8 @@ class Level(tool.State):
|
|||||||
self.drag_shovel = not self.drag_shovel
|
self.drag_shovel = not self.drag_shovel
|
||||||
if not self.drag_shovel:
|
if not self.drag_shovel:
|
||||||
self.removeMouseImagePlus()
|
self.removeMouseImagePlus()
|
||||||
|
# 播放点击铲子的音效
|
||||||
|
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "shovel.ogg"))
|
||||||
elif self.drag_shovel:
|
elif self.drag_shovel:
|
||||||
# 移出这地方的植物
|
# 移出这地方的植物
|
||||||
self.shovelRemovePlant(mouse_pos)
|
self.shovelRemovePlant(mouse_pos)
|
||||||
@ -775,6 +785,9 @@ class Level(tool.State):
|
|||||||
self.map.addMapPlant(map_x, map_y, self.plant_name, sleep=mushroomSleep)
|
self.map.addMapPlant(map_x, map_y, self.plant_name, sleep=mushroomSleep)
|
||||||
self.removeMouseImage()
|
self.removeMouseImage()
|
||||||
|
|
||||||
|
# 播放种植音效
|
||||||
|
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "plant.ogg"))
|
||||||
|
|
||||||
def setupHintImage(self):
|
def setupHintImage(self):
|
||||||
pos = self.canSeedPlant(self.plant_name)
|
pos = self.canSeedPlant(self.plant_name)
|
||||||
if pos and self.mouse_image:
|
if pos and self.mouse_image:
|
||||||
@ -938,6 +951,9 @@ class Level(tool.State):
|
|||||||
zombie.setBoomDie()
|
zombie.setBoomDie()
|
||||||
|
|
||||||
def freezeZombies(self, plant):
|
def freezeZombies(self, plant):
|
||||||
|
# 播放冻结音效
|
||||||
|
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "freeze.ogg"))
|
||||||
|
|
||||||
for i in range(self.map_y_len):
|
for i in range(self.map_y_len):
|
||||||
for zombie in self.zombie_groups[i]:
|
for zombie in self.zombie_groups[i]:
|
||||||
if zombie.rect.left <= c.SCREEN_WIDTH:
|
if zombie.rect.left <= c.SCREEN_WIDTH:
|
||||||
@ -979,6 +995,9 @@ class Level(tool.State):
|
|||||||
if ((abs(zombie.rect.centerx - x) <= plant.explode_y_range) or
|
if ((abs(zombie.rect.centerx - x) <= plant.explode_y_range) or
|
||||||
((zombie.rect.right - (x-plant.explode_x_range) > 20) or (zombie.rect.right - (x-plant.explode_x_range))/zombie.rect.width > 0.2, ((x+plant.explode_x_range) - zombie.rect.left > 20) or ((x+plant.explode_x_range) - zombie.rect.left)/zombie.rect.width > 0.2)[zombie.rect.x > x]): # 这代码不太好懂,后面是一个判断僵尸在左还是在右,前面是一个元组,[0]是在左边的情况,[1]是在右边的情况
|
((zombie.rect.right - (x-plant.explode_x_range) > 20) or (zombie.rect.right - (x-plant.explode_x_range))/zombie.rect.width > 0.2, ((x+plant.explode_x_range) - zombie.rect.left > 20) or ((x+plant.explode_x_range) - zombie.rect.left)/zombie.rect.width > 0.2)[zombie.rect.x > x]): # 这代码不太好懂,后面是一个判断僵尸在左还是在右,前面是一个元组,[0]是在左边的情况,[1]是在右边的情况
|
||||||
zombie.setDamage(1800, damageType=c.ZOMBIE_RANGE_DAMAGE)
|
zombie.setDamage(1800, damageType=c.ZOMBIE_RANGE_DAMAGE)
|
||||||
|
else:
|
||||||
|
# 用铲子移除植物时播放音效
|
||||||
|
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "plant.ogg"))
|
||||||
|
|
||||||
# 避免僵尸在用铲子移除植物后还在原位啃食
|
# 避免僵尸在用铲子移除植物后还在原位啃食
|
||||||
plant.health = 0
|
plant.health = 0
|
||||||
@ -1111,9 +1130,13 @@ class Level(tool.State):
|
|||||||
self.game_info[c.LEVEL_NUM] += 1
|
self.game_info[c.LEVEL_NUM] += 1
|
||||||
self.next = c.GAME_VICTORY
|
self.next = c.GAME_VICTORY
|
||||||
self.done = True
|
self.done = True
|
||||||
|
# 播放胜利音效
|
||||||
|
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "win.ogg"))
|
||||||
elif self.checkLose():
|
elif self.checkLose():
|
||||||
self.next = c.GAME_LOSE
|
self.next = c.GAME_LOSE
|
||||||
self.done = True
|
self.done = True
|
||||||
|
# 播放失败音效
|
||||||
|
pg.mixer.Sound(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))) ,"resources", "sound", "lose.ogg"))
|
||||||
|
|
||||||
def drawMouseShow(self, surface):
|
def drawMouseShow(self, surface):
|
||||||
if self.hint_plant:
|
if self.hint_plant:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user