-
Notifications
You must be signed in to change notification settings - Fork 0
/
background-music.js
68 lines (58 loc) · 1.79 KB
/
background-music.js
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
const MAH_NA_MA_NA = "mahNaMahNa";
const MAH_NA_MA_NA_NO_INTRO = "mahNaMahNaNoIntro";
const JEOPARDY_THEME = "jeopardyTheme";
class Music {
constructor(props) {
this.volume = props.volume;
this.name = props.name;
props.kaboom.loadSound(this.name, props.path);
}
}
class BackgroundMusic {
constructor(kaboom) {
this.kaboom = kaboom;
this.mahNaMahNa = new Music({kaboom: kaboom, volume: 0.5, name: MAH_NA_MA_NA, path: "/sardines/audio/mah-ma-mah-na.mp3"});
this.mahNaMahNaNoIntro = new Music({kaboom: kaboom, volume: 0.5, name: MAH_NA_MA_NA_NO_INTRO, path: "/sardines/audio/mah-ma-mah-na-no-intro.mp3"});
this.jeopardyTheme = new Music({kaboom: kaboom, volume: 1.5, name: JEOPARDY_THEME, path: "/sardines/audio/jeopardy-theme.mp3"});
this.active = this.mahNaMahNa;
this.loop = true;
this.musicObject = null;
this.enabled = true;
}
selectMahNaMahNa() {
this.active = this.mahNaMahNa;
}
selectMahNaMahNaNoIntro() {
this.active = this.mahNaMahNaNoIntro;
}
selectJeopardyTheme() {
this.active = this.jeopardyTheme;
}
stop() {
// .resume() does not work so force .play() to be called again when game
// restarts
if (this.musicObject) {
this.musicObject.stop();
this.musicObject = null;
}
}
enableDisable(b) {
this.enabled = b;
if (this.enabled) {
this.play();
}
else {
this.stop();
}
console.log("Background Music is now " + this.enabled);
}
isEnabled() {
return this.enabled;
}
play() {
if (!this.enabled) return;
this.stop();
// .pause() and .resume() of music does not work very well
this.musicObject = this.kaboom.play(this.active.name, {loop: this.loop, volume: this.active.volume});
}
}