-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.js
94 lines (90 loc) · 3.08 KB
/
options.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//manages options menu
var optionsButton = document.getElementById('options');
optionsButton.addEventListener('click', function(){toggleOptionsMenu();}, false);
var options = {
}
//maybe if i make more songs i'll make a song switching function
var nextSong = function(){
wav.song.play();
}
var toggleOptionsMenu = function(){
if(optionsButton.innerHTML == 'Options'){
//repetition because i can't make sense of add and remove eventlisteners working with this and keydown code
var bindFlip = function(e){
bind('flip',e.keyCode);
buttonF.innerHTML = 'Set Flip Key';
document.removeEventListener('keydown',bindFlip);
}
var bindShoot = function(e){
bind('shoot',e.keyCode);
buttonS.innerHTML = 'Set Shoot Key';
document.removeEventListener('keydown',bindShoot);
}
var bindDash = function(e){
bind('dash',e.keyCode);
buttonD.innerHTML = 'Set Dash Key';
document.removeEventListener('keydown',bindDash);
}
optionsButton.innerHTML = '-Close Options-';
//menu div
var div = document.createElement("div");
div.setAttribute('class', 'menu');
div.setAttribute('id', 'optionsMenu');
document.body.appendChild(div);
var optionsMenu = document.getElementById('optionsMenu');
//mute/unmute sounds (default mute)
var buttonMute = document.createElement("button");
buttonMute.addEventListener('click', function(){
if(mute){
buttonMute.innerHTML = 'Turn Off Sounds';
nextSong();
wav.song.addEventListener('ended',nextSong, false); //thanks stackoverflow
}
else{
buttonMute.innerHTML = 'Turn On Sounds';
wav.song.pause();
wav.song.removeEventListener('ended',nextSong);
}
mute = !mute;
});
buttonMute.innerHTML = 'Turn On Sounds';
optionsMenu.appendChild(buttonMute);
//kill the darn music
var buttonKillMusic = document.createElement("button");
buttonKillMusic.addEventListener('click', function(){
wav.song.pause();
wav.song.removeEventListener('ended',nextSong);
});
buttonKillMusic.innerHTML = 'Kill Music';
optionsMenu.appendChild(buttonKillMusic);
//set flip key
var buttonF = document.createElement("button");
buttonF.addEventListener('click', function(){
buttonF.innerHTML = 'Press the key to bind to Flip';
document.addEventListener('keydown',bindFlip);
}, false);
buttonF.innerHTML = 'Set Flip Key';
optionsMenu.appendChild(buttonF);
//set shoot key
var buttonS = document.createElement("button");
buttonS.addEventListener('click', function(){
buttonS.innerHTML = 'Press the key to bind to Shoot';
document.addEventListener('keydown',bindShoot);
}, false);
buttonS.innerHTML = 'Set Shoot Key';
optionsMenu.appendChild(buttonS);
//set dash key
var buttonD = document.createElement("button");
buttonD.addEventListener('click', function(){
buttonD.innerHTML = 'Press the key to bind to Dash';
document.addEventListener('keydown',bindDash);
}, false);
buttonD.innerHTML = 'Set Dash Key';
optionsMenu.appendChild(buttonD);
}
else{
document.body.removeChild(document.getElementById('optionsMenu'));
optionsButton.innerHTML = 'Options';
}
}
toggleOptionsMenu();