forked from felixrieseberg/Node-Mayhem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio.js
68 lines (63 loc) · 2.58 KB
/
audio.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
/* global me, game */
// Audio manager, managing sound for the game
/* ----------------------------------------------------------------- */
(function () {
audioManager = {
init: function () {
// initialize the 'sound engine', giving 'mp3' and 'ogg' as desired audio format
// i.e. on Safari, the loader will load all audio.mp3 files,
// on Opera the loader will however load audio.ogg files
audioManager.playBackgroundMusic(true);
},
playBackgroundMusic: function (enabled) {
if (enabled) {
me.audio.playTrack('backgroundmusic1', 0.5 * game.data.volume);
} else if (enabled === false) {
me.audio.stopTrack();
} else {
me.audio.playTrack('backgroundmusic1', 0.5 * game.data.volume);
}
},
switchMusic: function () {
if (me.audio.getCurrentTrack() !== null) {
audioManager.playBackgroundMusic(false);
document.getElementById('musicSwitch').textContent = 'ENABLE MUSIC';
} else {
audioManager.playBackgroundMusic(true);
document.getElementById('musicSwitch').textContent = 'DISABLE MUSIC';
}
},
switchMute: function () {
if (document.getElementById('soundSwitch').textContent === 'DISABLE SOUND') {
me.audio.disable();
document.getElementById('soundSwitch').textContent = 'ENABLE SOUND';
} else {
me.audio.enable();
audioManager.playBackgroundMusic(true);
document.getElementById('soundSwitch').textContent = 'DISABLE SOUND';
}
},
playSound: function (effect) {
// shoot, death, powerup, hit, explosion
switch (effect) {
case 'shoot':
me.audio.play('shoot', false, null, game.data.volume);
break;
case 'death':
me.audio.play('death', false, null, game.data.volume);
break;
case 'powerup':
me.audio.play('powerup', false, null, game.data.volume);
break;
case 'hit':
me.audio.play('hit', false, null, game.data.volume);
break;
case 'explosion':
me.audio.play('explosion', false, null, game.data.volume);
break;
default:
break;
}
}
};
})();