sound and other misc fixes
This commit is contained in:
parent
38eaba2fa6
commit
176216df8e
6 changed files with 97 additions and 15 deletions
47
sound.lua
Normal file
47
sound.lua
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
-- Central sound-effect registry. One preloaded Source per named effect; the game
|
||||
-- calls Sound.play("name") to (re)trigger it. Ambient static + music live in
|
||||
-- main.lua's _initSounds; this covers the one-shot gameplay/UI feedback.
|
||||
--
|
||||
-- Top level does NO audio calls on purpose: requiring this under the test love
|
||||
-- stub (which never runs Sound.init) must be side-effect free. Until Sound.init
|
||||
-- runs, Sound.sfx is empty and Sound.play is a harmless no-op.
|
||||
Sound = {}
|
||||
|
||||
Sound.sfx = {} -- name -> Source
|
||||
Sound.jabbers = {} -- pool of npc chatter Sources, picked at random
|
||||
|
||||
local function load(path)
|
||||
return love.audio.newSource(path, "static")
|
||||
end
|
||||
|
||||
function Sound.init()
|
||||
Sound.sfx = {
|
||||
playerMove = load("sounds/player_move.ogg"),
|
||||
switchFail = load("sounds/switch_fail.wav"),
|
||||
switchSuccess = load("sounds/switch_success.wav"),
|
||||
doorUnlock = load("sounds/door_unlock.ogg"),
|
||||
levelChange = load("sounds/level_change.ogg"),
|
||||
uiButton = load("sounds/ui/button.wav"),
|
||||
}
|
||||
Sound.jabbers = {
|
||||
load("sounds/jabber_1.ogg"),
|
||||
load("sounds/jabber_2.ogg"),
|
||||
}
|
||||
end
|
||||
|
||||
-- Restart-and-play a named effect. A static Source only plays one instance at a
|
||||
-- time, so stopping first makes rapid retriggers (e.g. mashing move) audible.
|
||||
function Sound.play(name)
|
||||
local src = Sound.sfx[name]
|
||||
if not src then return end
|
||||
src:stop()
|
||||
src:play()
|
||||
end
|
||||
|
||||
-- Pick a random npc jabber clip and play it. Used when a Dialogable starts talking.
|
||||
function Sound.jabber()
|
||||
if #Sound.jabbers == 0 then return end
|
||||
local src = Sound.jabbers[love.math.random(#Sound.jabbers)]
|
||||
src:stop()
|
||||
src:play()
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue