This repository was archived by the owner on Nov 6, 2024. It is now read-only.
forked from TecProg-grupo4-2018-2/panel-attack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsound.lua
More file actions
63 lines (56 loc) · 1.53 KB
/
sound.lua
File metadata and controls
63 lines (56 loc) · 1.53 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
require("sound_util")
function apply_config_volume()
love.audio.setVolume(config.master_volume/100)
themes[config.theme]:apply_config_volume()
for _,character in pairs(characters) do
character:apply_config_volume()
end
for _,stage in pairs(stages) do
stage:apply_config_volume()
end
end
function play_optional_sfx(sfx)
if not SFX_mute and sfx ~= nil then
sfx:stop()
sfx:play()
end
end
-- New music engine stuff here
music_t = {}
currently_playing_tracks = {} -- needed because we clone the tracks below
function update_music()
for k, v in pairs(music_t) do
if v and k - love.timer.getTime() < 0.007 then
if not v.t:isPlaying() then
v.t:play()
currently_playing_tracks[#currently_playing_tracks+1]=v.t
end
music_t[k] = nil
end
end
end
function stop_the_music()
print("musics have been stopped")
for k, v in pairs(currently_playing_tracks) do
v:stop()
currently_playing_tracks[k] = nil
end
music_t = {}
end
local function make_music_t(source, loop)
return {t = source, l = loop or false}
end
function find_and_add_music(musics, music_type)
print("music "..music_type.." is now playing")
local start_music = musics[music_type .. "_start"] or zero_sound
local loop_music = musics[music_type]
if loop_music:isPlaying() or start_music:isPlaying() then
return
end
music_t[love.timer.getTime()] = make_music_t(
start_music
)
music_t[love.timer.getTime() + start_music:getDuration()] = make_music_t(
loop_music, true
)
end