cambridge/load/sounds.lua

101 lines
2.5 KiB
Lua
Raw Normal View History

2019-05-22 22:57:34 -05:00
sounds = {
blocks = {
I = "res/se/piece_i.wav",
J = "res/se/piece_j.wav",
L = "res/se/piece_l.wav",
O = "res/se/piece_o.wav",
S = "res/se/piece_s.wav",
T = "res/se/piece_t.wav",
Z = "res/se/piece_z.wav"
2019-05-22 22:57:34 -05:00
},
move = "res/se/move.wav",
rotate = "res/se/rotate.wav",
kick = "res/se/kick.wav",
bottom = "res/se/bottom.wav",
cursor = "res/se/cursor.wav",
cursor_lr = "res/se/cursor_lr.wav",
main_decide = "res/se/main_decide.wav",
mode_decide = "res/se/mode_decide.wav",
lock = "res/se/lock.wav",
hold = "res/se/hold.wav",
erase = {
single = "res/se/single.wav",
double = "res/se/double.wav",
triple = "res/se/triple.wav",
quad = "res/se/quad.wav"
},
fall = "res/se/fall.wav",
ready = "res/se/ready.wav",
go = "res/se/go.wav",
irs = "res/se/irs.wav",
ihs = "res/se/ihs.wav",
2020-12-19 19:31:14 -06:00
-- a secret sound!
welcome = "res/se/welcomeToCambridge.wav",
2019-05-22 22:57:34 -05:00
}
-- Replace each sound effect string with its love audiosource counterpart, but only if it exists. This lets the game handle missing SFX.
for k,v in pairs(sounds) do
if(type(v) == "table") then
-- list of subsounds
for k2,v2 in pairs(v) do
if(love.filesystem.getInfo(sounds[k][k2])) then
-- this file exists
sounds[k][k2] = love.audio.newSource(sounds[k][k2], "static")
else
sounds[k][k2] = nil
end
end
else
if(love.filesystem.getInfo(sounds[k])) then
-- this file exists
print("Successfully converted " .. v)
sounds[k] = love.audio.newSource(sounds[k], "static")
else
sounds[k] = nil
end
end
end
function playSE(sound, subsound)
if sound ~= nil then
if sounds[sound] then
if subsound ~= nil then
if sounds[sound][subsound] then
sounds[sound][subsound]:setVolume(config.sfx_volume)
if sounds[sound][subsound]:isPlaying() then
sounds[sound][subsound]:stop()
end
sounds[sound][subsound]:play()
end
else
sounds[sound]:setVolume(config.sfx_volume)
if sounds[sound]:isPlaying() then
sounds[sound]:stop()
end
sounds[sound]:play()
end
2019-05-22 22:57:34 -05:00
end
end
end
2020-10-26 08:21:49 -05:00
function playSEOnce(sound, subsound)
if sound ~= nil then
if sounds[sound] then
if subsound ~= nil then
if sounds[sound][subsound] then
sounds[sound][subsound]:setVolume(config.sfx_volume)
if sounds[sound][subsound]:isPlaying() then
return
end
sounds[sound][subsound]:play()
end
else
sounds[sound]:setVolume(config.sfx_volume)
if sounds[sound]:isPlaying() then
return
end
sounds[sound]:play()
end
2020-10-26 08:21:49 -05:00
end
end
end