-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoundEffects.adept
56 lines (46 loc) · 1.42 KB
/
SoundEffects.adept
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
import 'main.adept'
import 'soundutils.adept'
struct SoundEffects (
spawn, button, back Sound,
players <SoundPlayer> List,
disable_sfx bool,
amplifier float
) {
func load {
sfx_folder String = where() + "assets/sfx/"
this.spawn.load(sfx_folder + "spawn.wav", false, 0.5f)
this.button.load(sfx_folder + "button.wav", false, 0.5f)
this.back.load(sfx_folder + "back.wav", false, 0.5f)
this.disable_sfx = false
this.amplifier = 1.0f
}
func unload {
each SoundPlayer in this.players, it.stop(); it.destroy()
this.spawn.destroy()
this.button.destroy()
this.back.destroy()
this.players.length = 0
}
func update {
each SoundPlayer in this.players, unless it.isPlaying() {
it.destroy()
this.players.remove(idx--)
}
}
func toggle {
this.disable_sfx = !this.disable_sfx
if this.disable_sfx, each SoundPlayer in this.players, it.stop()
}
func play(sound Sound) {
if this.disable_sfx, return
player *SoundPlayer = this.players.add()
player.create()
player.play(sound)
player.setVolume(this.amplifier)
}
func setVolumeAmplifier(amplifier float) {
each SoundPlayer in this.players, it.setVolume(amplifier)
this.amplifier = amplifier
}
}
sfx SoundEffects