-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.js
54 lines (45 loc) · 980 Bytes
/
helper.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
var ambianceSound;
// HELPER FUNCTIONS - not all functions are needed for every game.
/*
* Toggles mute variable. Called from HTML button.
*/
function toggleMute() {
if (mute == true) {
mute = false;
} else {
mute = true;
}
if (mute == true) {
stage.addChild(muteButton);
stage.removeChild(unmuteButton);
ambianceSound.stop();
} else {
stage.addChild(unmuteButton);
stage.removeChild(muteButton);
ambianceSound = createjs.Sound.play("song", {loop:-1});
}
}
/**
* Shuffles array in place.
* @param {Array} a items The array containing the items.
*/
function shuffle(a) {
var j, x, i;
for (i = a.length; i; i--) {
j = Math.floor(Math.random() * i);
x = a[i - 1];
a[i - 1] = a[j];
a[j] = x;
}
}
/*
* Plays a sound if the game is not muted.
*/
function playSound(id) {
if (mute == false) {
createjs.Sound.play(id);
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}