-
Notifications
You must be signed in to change notification settings - Fork 23
/
sound.js
70 lines (61 loc) · 1.53 KB
/
sound.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
69
70
var muted = false
var about = false
popSound = document.createElement('audio')
popSound.src='assets/drop1.ogg'
popSound.volume = 0.4
bgSound = document.createElement('audio')
bgSound.src='assets/bg.ogg'
bgSound.loop = true
bgSound.volume = 0.6
bgSound.addEventListener('canplaythrough', function() {
bgSound.play()
})
bgSound.play()
if(localStorage.muted === 'true') toggleMute()
function toggleMute(){
if(!muted) {
popSound.volume = 0
bgSound.volume = 0
muted = true
localStorage.muted = 'true'
drawSoundControl()
} else {
popSound.volume = 0.4
bgSound.volume = 0.6
muted = false
localStorage.muted = 'false'
bgSound.play()
drawSoundControl()
}
}
function playPop() {
popSound.play()
}
function drawSoundControl() {
if(typeof ctx === 'undefined') return
ctx.fillStyle = '#111'
ctx.fillRect($canv.width - 25, 10, 50, 25)
if(muted)
ctx.drawImage(ASSETS.soundOff, $canv.width - 25, 10)
else
ctx.drawImage(ASSETS.soundOn, $canv.width - 25, 10)
if(GAME.state === 'menu' && about) {
ctx.fillStyle = '#111'
ctx.fillRect(10, 10, 50, 20)
ctx.fillStyle = '#333'
ctx.font = 'normal 14px sans'
ctx.fillText('By: Zolmeister', 10, 20)
ctx.font = 'normal 12px sans'
ctx.fillText('Music: Chrissi J', 10, 42)
} else if (GAME.state === 'menu') {
ctx.fillStyle = '#111'
ctx.fillRect(10, 10, 50, 20)
ctx.fillStyle = '#333'
ctx.font = 'normal 12px sans'
ctx.fillText('About', 10, 20)
}
}
function showAbout() {
about = true
drawSoundControl()
}