feat: add sfx for terrains

This commit is contained in:
Kazhnuz 2021-04-21 16:46:41 +02:00
parent 021a2b08b2
commit 38c197a9fb
7 changed files with 21 additions and 0 deletions

Binary file not shown.

Binary file not shown.

View file

@ -25,6 +25,7 @@ return {
fallDamage = 10, fallDamage = 10,
speedFactor = 0, speedFactor = 0,
canJump = false, canJump = false,
sound = "splash"
}, },
{ {
forceAction = nil, forceAction = nil,
@ -35,6 +36,7 @@ return {
speedFactor = 0.5, speedFactor = 0.5,
canJump = true, canJump = true,
damage = 0, damage = 0,
sound = "splash"
}, },
{ {
forceAction = nil, forceAction = nil,
@ -54,6 +56,7 @@ return {
fallDamage = 10, fallDamage = 10,
speedFactor = 0, speedFactor = 0,
canJump = false, canJump = false,
sound = "fall"
}, },
}, },
lava = { lava = {
@ -63,6 +66,7 @@ return {
fallDamage = 20, fallDamage = 20,
speedFactor = 0, speedFactor = 0,
canJump = false, canJump = false,
sound = "splash"
}, },
}, },
swamp = { swamp = {

View file

@ -9,6 +9,7 @@ function PlayerHealth:initHealth()
self.hpbar:setColorForeground(248/255, 160/255, 0, 1) self.hpbar:setColorForeground(248/255, 160/255, 0, 1)
self.hpbar:setColorBackground(112/255, 0, 0) self.hpbar:setColorBackground(112/255, 0, 0)
self.fallDamage = 0 self.fallDamage = 0
self.fallSound = ""
end end
function PlayerHealth:drawHealth(x, y) function PlayerHealth:drawHealth(x, y)

View file

@ -82,6 +82,9 @@ function Player:checkGround()
self.x = self.lastPos.x self.x = self.lastPos.x
self.y = self.lastPos.y self.y = self.lastPos.y
self:takeDamage(self.fallDamage) self:takeDamage(self.fallDamage)
if (not utils.string.isEmpty(self.fallSound)) then
self.assets:playSFX(self.fallSound)
end
end end
end end
end end

View file

@ -20,6 +20,7 @@ function PlayerInteractions:initInteractions()
self.terrain = {} self.terrain = {}
self.terrain.name = "" self.terrain.name = ""
self.terrain.data = {} self.terrain.data = {}
self.terrain.new = false
self.lastPos = {} self.lastPos = {}
self.lastPos.x = self.x self.lastPos.x = self.x
self.lastPos.y = self.y self.lastPos.y = self.y
@ -73,6 +74,9 @@ end
function PlayerInteractions:updateTerrain() function PlayerInteractions:updateTerrain()
local newTerrain = self:getCurrentTerrain() local newTerrain = self:getCurrentTerrain()
if (newTerrain ~= self.terrain.name) then
self.terrain.new = true
end
self.terrain.name = newTerrain self.terrain.name = newTerrain
self:updateTerrainData() self:updateTerrainData()
if (newTerrain == "non-solid") then if (newTerrain == "non-solid") then
@ -132,7 +136,14 @@ function PlayerInteractions:setTerrainData(data)
self.canAct = data.canAct ~= false self.canAct = data.canAct ~= false
self.forceAction = data.forceAction self.forceAction = data.forceAction
end end
if (self.terrain.new and (self.z < 0)) then
self.terrain.new = false
if (not utils.string.isEmpty(data.sound)) then
self.assets:playSFX(data.sound)
end
end
self.fallDamage = data.fallDamage or 0 self.fallDamage = data.fallDamage or 0
self.fallSound = data.fallSound or ""
self.terrain.data = data self.terrain.data = data
end end

View file

@ -54,6 +54,8 @@ return {
{"spinrelease", "assets/sfx/spinrelease.wav"}, {"spinrelease", "assets/sfx/spinrelease.wav"},
{"ring", "assets/sfx/ring.wav"}, {"ring", "assets/sfx/ring.wav"},
{"pop", "assets/sfx/pop.wav"}, {"pop", "assets/sfx/pop.wav"},
{"fall", "assets/sfx/fall.wav"},
{"splash", "assets/sfx/splash.wav"},
{"mBack", "assets/sfx/menus/back.wav"}, {"mBack", "assets/sfx/menus/back.wav"},
{"mBeep", "assets/sfx/menus/beep.wav"}, {"mBeep", "assets/sfx/menus/beep.wav"},