-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoundManager.pde
44 lines (44 loc) · 1.32 KB
/
SoundManager.pde
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
import processing.sound.*;
class SoundManager {
private SoundFile[] sounds;
AudioDevice device;
public SoundManager(TrafficRacer parent) {
sounds = new SoundFile[5];
sounds[0] = new SoundFile(parent, "bg.mp3");
sounds[1] = new SoundFile(parent, "horn.mp3");
sounds[2] = new SoundFile(parent, "crash.mp3");
sounds[3] = new SoundFile(parent, "start.mp3");
sounds[4] = new SoundFile(parent, "idle.mp3");
device = new AudioDevice(parent, 44000, 128);
}
public void playSound(String name) {
switch(name) {
case "horn": sounds[1].play(0.5, 1.0); break;
case "accident": sounds[2].play(0.5, 1.0); break;
case "start": sounds[3].play(0.5, 1.0); break;
}
}
public void stopSound(String name) {
switch(name) {
case "horn": sounds[1].stop(); break;
case "accident": sounds[2].stop(); break;
case "start": sounds[3].stop(); break;
case "idle": if (sounds[4].isPlaying() == 1) sounds[4].stop(); break;
}
}
public void loopSound(String name) {
switch(name) {
case "idle": {
if (sounds[4].isPlaying() == 0) {
sounds[4].amp(1);
sounds[4].play();
}
break;
}
}
}
public void playBackgroundMusic() {
sounds[0].amp(0.3);
sounds[0].loop();
}
}