-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio.lua
153 lines (117 loc) · 2.53 KB
/
audio.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
-- BLAST FLOCK source files
-- by TRASEVOL_DOG (https://trasevol.dog/)
function init_audio()
local music_list={
-- name = "file.ext",
}
local sfx_list={
-- name = "file.ext",
button = "button.ogg",
deadbot = "deadbot.ogg",
deadwall = "deadwall.ogg",
harvest = "harvest.ogg",
hurtbot = "hurtbot.ogg",
newtask = "newtask.ogg",
newunit = "newunit.ogg",
newwall = "newwall.ogg",
nomoney = "nomoney.ogg",
over = "over.ogg",
select = "select.ogg",
start = "start.ogg",
menu_confirm = "menu_confirm.ogg",
menu_select = "menu_select.ogg",
menu_slider = "menu_sliderset.ogg"
}
musics={}
sfxs={}
for n,f in pairs(music_list) do
musics[n]=love.audio.newSource("assets/"..f,"stream")
musics[n]:setLooping(true)
end
for n,f in pairs(sfx_list) do
sfxs[n]=love.audio.newSource("assets/sfx/"..f,"static")
end
sfx_volume(100)
music_volume(60)
master_volume(100)
curmusic=nil
end
function sfx(name,x,y,pitch,volume)
if server_only then return end
local s=sfxs[name]
if not s then return end
if pitch then
s:setPitch(pitch)
end
if volume then
s:setVolume(volume * sfx_vol/100)
end
if x and y then
local k=50
local scrnw,scrnh = screen_size()
x,y=(x-cam.x-scrnw/2)/k,(y-cam.y-scrnh/2)/k
s:setPosition(x,y,1)
end
if s:isPlaying() then
s:seek(0)
else
s:play()
end
end
function music(name)
if server_only then return end
if curmusic then
musics[curmusic]:stop()
end
curmusic=name
if not name then
return
end
local m = musics[name]
if not m then return end
love.audio.play(m)
end
function music_lowpass(enable)
if server_only then return end
if enable then
for n,m in pairs(musics) do
m:setFilter{type="lowpass",highgain=.4,volume=music_vol/100}
end
else
for n,m in pairs(musics) do
m:setFilter()
end
end
end
function listener(x,y)
if server_only then return end
love.audio.setPosition(x,y)
end
function sfx_volume(v)
if server_only then return end
if not v then
return sfx_vol
end
for n,s in pairs(sfxs) do
s:setVolume(v/100)
end
sfx_vol=v
end
function music_volume(v)
if server_only then return end
if not v then
return music_vol
end
for n,m in pairs(musics) do
m:setVolume(v/100)
end
music_vol=v
end
function master_volume(v)
if server_only then return end
if not v then
return master_vol
end
love.audio.setVolume(v/100)
master_vol=v
end