-
Notifications
You must be signed in to change notification settings - Fork 15
/
musicmgr.lua
51 lines (43 loc) · 1.34 KB
/
musicmgr.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
local MusicMgr = {}
MusicMgr.__index = MusicMgr
MusicMgr.STATE_NONE = 0
MusicMgr.STATE_MENU = 1
MusicMgr.STATE_INGAME = 2
MusicMgr.STATE_MINIGAME = 3
MusicMgr.STATE_GAMEOVER = 4
local musicState = MusicMgr.STATE_NONE
local menuSong = "groovecallus.ogg"
local minigameSong = "radiationwoman.ogg"
local gameOverSong = "interlude.ogg"
local ingameSongs = {}
function MusicMgr.loadSongs()
for i, song in ipairs(love.filesystem.getDirectoryItems("res/music/")) do
local ending = song:sub(-4):lower()
if (ending == ".ogg" or ending == ".mp3")
and song ~= menuSong and song ~= minigameSong and song ~= gameOverSong then
table.insert(ingameSongs, song)
end
end
end
function MusicMgr.playIngame()
if #ingameSongs == 0 then stopMusic() return end
if musicState == MusicMgr.STATE_INGAME then return end
playMusic(table.random(ingameSongs))
musicState = MusicMgr.STATE_INGAME
end
function MusicMgr.playMenu()
if musicState == MusicMgr.STATE_MENU then return end
playMusic(menuSong)
musicState = MusicMgr.STATE_MENU
end
function MusicMgr.playMinigame()
if musicState == MusicMgr.STATE_MINIGAME then return end
playMusic(minigameSong)
musicState = MusicMgr.STATE_MINIGAME
end
function MusicMgr.playGameOver()
if musicState == MusicMgr.STATE_GAMEOVER then return end
playMusic(gameOverSong)
musicState = MusicMgr.STATE_GAMEOVER
end
return MusicMgr