-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSounds.pde
84 lines (71 loc) · 2.3 KB
/
Sounds.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
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
class Sounds {
public Sound[] boops = new Sound[] { new Sound ("low.wav"), new Sound("high.wav") };
public Sound shot = new Sound("shot.wav", 6);
public SoundLoop thrust = new SoundLoop("thrust.wav", 1);
public SoundLoop smallShip = new SoundLoop("smallship.wav");
public SoundLoop bigShip = new SoundLoop("bigship.wav");
public Sound explodeLow = new Sound("explode_low.wav");
public Sound explodeMedium = new Sound("explode_medium.wav");
public Sound explodeHigh = new Sound("explode_high.wav");
public void killAllSounds() {
boops[0].stop();
boops[1].stop();
shot.stop();
thrust.stop();
smallShip.stop();
bigShip.stop();
explodeLow.stop();
explodeMedium.stop();
explodeHigh.stop();
}
public Sounds() {
dR = (dS - dE) / N;
println("Sounds Start Level @" + wait + " wait");
}
public void fire() { shot.play(); }
public void explode(int size) {
switch (size) {
case EXPLODE_SMALL:
explodeSmall();
break;
case EXPLODE_MEDIUM:
explodeMedium();
break;
case EXPLODE_BIG:
default:
explodeBig();
}
}
public void explodeSmall() { explodeHigh.play(); }
public void explodeMedium() { explodeMedium.play(); }
public void explodeBig() { explodeLow.play(); }
int dS = 1000;
int dE = 250;
int N = 80;
int dR, wait, start;
int sound = 0;
boolean inPlay = false;
public void startLevel() {
inPlay = true;
wait = dS;
start = millis();
println("dS = " + dS);
println("Sounds Start Level @" + wait + " wait, dS = " + dS);
}
public void playBoop() {
if (!inPlay) return;
int now = millis();
//println("playBoop - interval=" + (now-start) + ", wait = " + wait);
if (now - start > wait) {
start = now;
wait = max(wait - dR, dE);
boops[sound].play();
sound = (sound + 1) % 2;
}
}
public void stopGame() {
inPlay = false;
}
public void playThrust() { thrust.play(); }
public void stopThrust() { thrust.stop(); }
}