diff options
| author | Eltrac <hi@guhub.cn> | 2025-03-13 15:01:24 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-03-13 15:01:24 +0800 |
| commit | 3647797bc60c0c2ffd28b14d14fed8b246e09254 (patch) | |
| tree | a8c2489cf8081f3c9c22c27cfa3154f302670799 /utils | |
| parent | 4c327ced8e8ed90b04042bd4e0807aa93e9219d0 (diff) | |
feat(audio): add background music for some rooms
Diffstat (limited to 'utils')
| -rw-r--r-- | utils/audio.lua | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/utils/audio.lua b/utils/audio.lua index 450951a..a5747df 100644 --- a/utils/audio.lua +++ b/utils/audio.lua @@ -1,21 +1,47 @@ local audio = {} -local resources = { - shootNormal = "sound/shoot_normal.wav", - shootFlash = "sound/shoot_flash.wav", - hit = "sound/hit.wav", +local soundResources = { + shootNormal = "shoot_normal.wav", + shootFlash = "shoot_flash.wav", + hit = "hit.wav", + hitGlass = "hit_glass.wav", +} + +local musicResources = { + briskFight = "brisk_fight.wav" } function audio.load() - audioData = {} - for name, path in pairs(resources) do - audioData[name] = love.audio.newSource("resources/" .. path, "static") + AudioData = {} + for name, path in pairs(soundResources) do + AudioData[name] = love.audio.newSource("resources/sound/" .. path, "static") + end + for name, path in pairs(musicResources) do + AudioData[name] = love.audio.newSource("resources/music/" .. path, "stream") + AudioData[name]:setLooping(true) end end function audio.play(name) - if audioData[name] then - love.audio.play(audioData[name]) + if AudioData[name] then + love.audio.play(AudioData[name]) + end +end + +function audio.music(name) + if G.musicPlaying == name then + return + end + if AudioData[name] then + love.audio.play(AudioData[name]) + G.musicPlaying = name + end +end + +function audio.stopMusic() + if G.musicPlaying then + love.audio.stop(AudioData[G.musicPlaying]) + G.musicPlaying = nil end end |
