-
Notifications
You must be signed in to change notification settings - Fork 1
/
selection.js
244 lines (244 loc) · 7.49 KB
/
selection.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
var rows=3;
var cols=6;
var redLoc=0;
var blueLoc=cols-1;
var greenLoc=(rows-1)*cols;
var yellowLoc=rows*cols-1;
var numPlayers=2;
var isFriedman=false;
var muted=false;
function setKeys() {
window.onkeydown = function(e) {
switch(e.which) {
case 87:
//move red up
if(Math.floor(redLoc/cols)==0) redLoc+=(rows-1)*cols;
else redLoc-=cols;
isFriedman=false;
break;
case 68:
//move red right
if(redLoc%cols==cols-1) redLoc-=cols-1;
else redLoc+=1;
isFriedman=false;
break;
case 83:
//move red down
if(Math.floor(redLoc/cols)==rows-1) redLoc-=(rows-1)*cols;
else redLoc+=cols;
isFriedman=false;
break;
case 65:
//move red left
if(redLoc%cols==0) redLoc+=cols-1;
else redLoc-=1;
isFriedman=false;
break;
case 38:
//move blue up
if(Math.floor(blueLoc/cols)==0) blueLoc+=(rows-1)*cols;
else blueLoc-=cols;
break;
case 39:
//move blue right
if(blueLoc%cols==cols-1) blueLoc-=cols-1;
else blueLoc+=1;
break;
case 40:
//move blue down
if(Math.floor(blueLoc/cols)==rows-1) blueLoc-=(rows-1)*cols;
else blueLoc+=cols;
break;
case 37:
//move blue left
if(blueLoc%cols==0) blueLoc+=cols-1;
else blueLoc-=1;
break;
case 89:
//move green up
if(Math.floor(greenLoc/cols)==0) greenLoc+=(rows-1)*cols;
else greenLoc-=cols;
break;
case 74:
//move green right
if(greenLoc%cols==cols-1) greenLoc-=cols-1;
else greenLoc+=1;
break;
case 72:
//move green down
if(Math.floor(greenLoc/cols)==rows-1) greenLoc-=(rows-1)*cols;
else greenLoc+=cols;
break;
case 71:
//move green left
if(greenLoc%cols==0) greenLoc+=cols-1;
else greenLoc-=1;
break;
case 80:
//move yellow up
if(Math.floor(yellowLoc/cols)==0) yellowLoc+=(rows-1)*cols;
else yellowLoc-=cols;
break;
case 222:
//move yellow right
if(yellowLoc%cols==cols-1) yellowLoc-=cols-1;
else yellowLoc+=1;
break;
case 186:
//move yellow down
if(Math.floor(yellowLoc/cols)==rows-1) yellowLoc-=(rows-1)*cols;
else yellowLoc+=cols;
break;
case 76:
//move yellow left
if(yellowLoc%cols==0) yellowLoc+=cols-1;
else yellowLoc-=1;
break;
case 49:
//friedman
isFriedman=true;
audio.sounds.crowd3.play();
break;
case 50:
//2 player
$("#player3").hide();
$("#player4").hide();
$("td").removeClass("highlightGreen");
$("td").removeClass("highlightYellow");
$("#p3").hide();
$("#p4").hide();
numPlayers=2;
break;
case 51:
//3 player
$("#player3").show();
$("#player4").hide();
$("td").removeClass("highlightYellow");
$("#p3").show();
$("#p4").hide();
numPlayers=3;
break;
case 52:
//4 player
$("#player3").show();
$("#player4").show();
$("#p3").show();
$("#p4").show();
numPlayers=4;
break;
case 53:
//start stage 5
startGame(5);
break;
case 54:
//start stage 6
startGame(6);
break;
case 55:
//start stage 7
startGame(7);
break;
case 56:
//start stage 8
startGame(8);
break;
case 57:
//start stage 9
startGame(9);
break;
case 48:
//start stage 0
startGame(0);
break;
case 13:
//start game
startGame(5);
break;
case 77:
//mute
muted=!muted;
if(muted) {
audio.stop();
} else if(!$("#selection").is(":visible")) {
audio.sounds.pokemon.play(true);
}
break;
}
//update coloring
updateColoring();
};
}
function startGame(stageNum) {
$("#selection").hide();
$("#game").show();
var redName=$("#choice"+redLoc+" img")[0].src.substring(document.URL.length+15);
var blueName=$("#choice"+blueLoc+" img")[0].src.substring(document.URL.length+15);
var greenName=$("#choice"+greenLoc+" img")[0].src.substring(document.URL.length+15);
var yellowName=$("#choice"+yellowLoc+" img")[0].src.substring(document.URL.length+15);
redName=redName.substring(7,redName.length-8);
blueName=blueName.substring(7,blueName.length-8);
greenName=greenName.substring(7,greenName.length-8);
yellowName=yellowName.substring(7,yellowName.length-8);
if(isFriedman) {
redName="friedman";
}
game = new Game(stageNum,numPlayers,redName,blueName,greenName,yellowName);
audio.stop();
audio.sounds.ok.play();
game.init();
}
function updateColoring() {
$("td").removeClass("highlightRed");
$("td").removeClass("highlightBlue");
$("td").removeClass("highlightGreen");
$("td").removeClass("highlightYellow");
$("#choice"+redLoc).addClass("highlightRed");
$("#choice"+blueLoc).addClass("highlightBlue");
if(numPlayers>2)
$("#choice"+greenLoc).addClass("highlightGreen");
if(numPlayers>3)
$("#choice"+yellowLoc).addClass("highlightYellow");
var redName=$("#choice"+redLoc+" img")[0].src.substring(document.URL.length+15);
var blueName=$("#choice"+blueLoc+" img")[0].src.substring(document.URL.length+15);
var greenName=$("#choice"+greenLoc+" img")[0].src.substring(document.URL.length+15);
var yellowName=$("#choice"+yellowLoc+" img")[0].src.substring(document.URL.length+15);
redName=redName.substring(7,redName.length-8);
blueName=blueName.substring(7,blueName.length-8);
greenName=greenName.substring(7,greenName.length-8);
yellowName=yellowName.substring(7,yellowName.length-8);
$("#player1 img")[0].src=document.URL+"assets/img/characters/"+redName+"Body.png";
$("#player2 img")[0].src=document.URL+"assets/img/characters/"+blueName+"Body.png";
$("#player3 img")[0].src=document.URL+"assets/img/characters/"+greenName+"Body.png";
$("#player4 img")[0].src=document.URL+"assets/img/characters/"+yellowName+"Body.png";
$("#player1 h2").html(capEachWord(decodeURIComponent(redName)));
$("#player2 h2").html(capEachWord(decodeURIComponent(blueName)));
$("#player3 h2").html(capEachWord(decodeURIComponent(greenName)));
$("#player4 h2").html(capEachWord(decodeURIComponent(yellowName)));
$("#player1a").html(constants.heros[redName].buff);
$("#player2a").html(constants.heros[blueName].buff);
$("#player3a").html(constants.heros[greenName].buff);
$("#player4a").html(constants.heros[yellowName].buff);
$("#player1d").html(constants.heros[redName].nerf);
$("#player2d").html(constants.heros[blueName].nerf);
$("#player3d").html(constants.heros[greenName].nerf);
$("#player4d").html(constants.heros[yellowName].nerf);
if(isFriedman) {
$("#player1 img")[0].src=document.URL+"assets/img/characters/friedmanBody.png";
$("#player1 h2").html("Friedman");
$("#player1a").html(constants.heros["friedman"].buff);
$("#player1d").html(constants.heros["friedman"].nerf);
}
}
function capEachWord(str) {
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
$(function() {
var aspect = window.innerWidth / window.innerHeight;
var canvas = $('#canvas');
var width = Number(canvas.attr('width'));
$('#canvas').attr('height', width / aspect);
audio.init();
audio.sounds.menu.play(true);
setKeys();
updateColoring();
});