-
Notifications
You must be signed in to change notification settings - Fork 57
/
lodeRunner.key.js
333 lines (310 loc) · 7.46 KB
/
lodeRunner.key.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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
var keyAction = ACT_STOP; //// keyLastLeftRight = ACT_RIGHT;
var shiftLevelNum = 0;
var runnerDebug = 0;
function pressShiftKey(code)
{
/* cheat key code disable 5/16/2015
switch(code) {
case KEYCODE_PERIOD: //SHIFT-. = '>', change to next level
shiftLevelNum = 1;
gameState = GAME_NEXT_LEVEL;
break;
case KEYCODE_COMMA: //SHIFT-, = '<', change to previous level
shiftLevelNum = 1;
gameState = GAME_PREV_LEVEL;
break;
case KEYCODE_UP: //SHIFT-UP, inc runner
if(playMode == PLAY_CLASSIC && runnerLife < 10) { //bug fixed: add check playMode, 12/15/2014
runnerLife++;
drawLife();
}
break;
case KEYCODE_X: //SHIFT-X
toggleTrapTile();
break;
case KEYCODE_G: //SHIFT-G, toggle god mode
toggleGodMode();
break;
default:
if(runnerDebug) debugKeyPress(code);
break;
}
*/
}
function pressCtrlKey(code)
{
switch(code) {
case KEYCODE_A: //CTRL-A : abort level
gameState = GAME_RUNNER_DEAD;
break;
case KEYCODE_C: //CTRL-C : copy current level
copyLevelMap = levelData[curLevel-1];
copyLevelPassed = 1; //means copy from exists level
showTipsText("COPY MAP", 1500);
break;
case KEYCODE_J: //CTRL-J : gamepad toggle
toggleGamepadMode(1);
//if(gamepadIconObj) gamepadIconObj.updateGamepadImage();
break;
case KEYCODE_K: //CTRL-K : repeat actions On/Off
toggleRepeatAction();
repeatActionIconObj.updateRepeatActionImage();
break;
case KEYCODE_R: //CTRL-R : abort game
runnerLife = 1;
gameState = GAME_RUNNER_DEAD;
break;
case KEYCODE_X: //CTRL-X
toggleTrapTile();
break;
// case KEYCODE_Z: //CTRL-Z, toggle god mode
// toggleGodMode();
// break;
case KEYCODE_S: //CTRL-S, toggle sound
if( (soundOff ^= 1) == 1) {
soundStop(soundDig);
soundStop(soundFall);
showTipsText("SOUND OFF", 1500);
} else {
showTipsText("SOUND ON", 1500);
}
soundIconObj.updateSoundImage(); //toggle sound On/Off icon
break;
case KEYCODE_LEFT: //SHIFT + <- : speed down
setSpeed(-1);
break;
case KEYCODE_RIGHT: //SHIFT + -> : speed up
setSpeed(1);
break;
case KEYCODE_H: //CTRL-H : redHat mode on/off
toggleRedhatMode();
break;
case KEYCODE_1: //CTRL-1
case KEYCODE_2: //CTRL-2
case KEYCODE_3: //CTRL-3
case KEYCODE_4: //CTRL-4
case KEYCODE_5: //CTRL-5
themeColorChange(code - KEYCODE_1);
break;
}
}
function debugKeyPress(code)
{
switch(code) {
case KEYCODE_1: //SHIFT-1 , add 5 level
shiftLevelNum = 5;
gameState = GAME_NEXT_LEVEL;
break;
case KEYCODE_2: //SHIFT-2 , add 10 level
shiftLevelNum = 10;
gameState = GAME_NEXT_LEVEL;
break;
case KEYCODE_3: //SHIFT-3 , add 20 level
shiftLevelNum = 20;
gameState = GAME_NEXT_LEVEL;
break;
case KEYCODE_4: //SHIFT-4 , add 50 level
shiftLevelNum = 50;
gameState = GAME_NEXT_LEVEL;
break;
case KEYCODE_6: //SHIFT-6 , dec 5 level
shiftLevelNum = 5;
gameState = GAME_PREV_LEVEL;
break;
case KEYCODE_7: //SHIFT-7 , dec 10 level
shiftLevelNum = 10;
gameState = GAME_PREV_LEVEL;
break;
case KEYCODE_8: //SHIFT-8 , dec 20 level
shiftLevelNum = 20;
gameState = GAME_PREV_LEVEL;
break;
case KEYCODE_9: //SHIFT-9 , dec 50 level
shiftLevelNum = 50;
gameState = GAME_PREV_LEVEL;
break;
}
}
var repeatAction = 0; //1: keyboard repeat on, 0: keyboard repeat Off
var repeatActionPressed = 0;
var gamepadMode = 1; //0: disable, 1: enable
var redhatMode = 1;
var godMode = 0, godModeKeyPressed = 0;
function initHotKeyVariable()
{
godMode = 0;
godModeKeyPressed = 0;
repeatActionPressed = 0;
}
function toggleRepeatAction()
{
if( (repeatAction ^= 1) == 1) {
showTipsText("REPEAT ACTIONS ON", 2500);
} else {
showTipsText("REPEAT ACTIONS OFF", 2500);
}
if(gameState != GAME_START) repeatActionPressed=1; //player change the "repeatAction" Mode at running
setRepeatAction();
}
function toggleGamepadMode(textMsg)
{
if(!gamepadSupport()) {
if(textMsg) showTipsText("GAMEPAD NOT SUPPORTED", 2500);
gamepadMode = 0;
} else {
if( (gamepadMode ^= 1) == 1) {
gamepadEnable();
if(textMsg) showTipsText("GAMEPAD ON", 2500);
} else {
gamepadDisable();
if(textMsg) showTipsText("GAMEPAD OFF", 2500);
}
}
setGamepadMode();
}
function toggleRedhatMode()
{
if( (redhatMode ^= 1) == 1 ) { //enable
for(var i = 0; i < guardCount; i++) {
if(guard[i].hasGold > 0)
guard[i].sprite.spriteSheet = redhatData;
else
guard[i].sprite.spriteSheet = guardData;
}
showTipsText("REDHAT MODE ON", 1500);
} else { //disable
for(var i = 0; i < guardCount; i++) {
guard[i].sprite.spriteSheet = guardData;
}
showTipsText("REDHAT MODE OFF", 1500);
}
}
function toggleGodMode()
{
godModeKeyPressed = 1; //means player press the god-mod hot-key
sometimePlayInGodMode = 1; // 12/23/2014
godMode ^= 1;
if(godMode) {
showTipsText("GOD MODE ON", 1500);
} else {
showTipsText("GOD MODE OFF", 1500);
}
}
function setSpeed(v)
{
speed += v;
if(speed < 0) speed = 0;
if(speed >= speedMode.length) speed = speedMode.length-1;
createjs.Ticker.setFPS(speedMode[speed]);
showTipsText(speedText[speed], 1500);
}
function helpCallBack() //help complete call back
{
pressKey(KEYCODE_ESC);
}
function pressKey(code)
{
switch(code) {
case KEYCODE_LEFT:
case KEYCODE_J:
case KEYCODE_A:
keyAction = ACT_LEFT;
break;
case KEYCODE_RIGHT:
case KEYCODE_L:
case KEYCODE_D:
keyAction = ACT_RIGHT;
break;
case KEYCODE_UP:
case KEYCODE_I:
case KEYCODE_W:
keyAction = ACT_UP;
break;
case KEYCODE_DOWN:
case KEYCODE_K:
case KEYCODE_S:
keyAction = ACT_DOWN;
break;
case KEYCODE_Z:
case KEYCODE_Y: //Y key to dig left, for German keyboards
case KEYCODE_U:
case KEYCODE_Q:
case KEYCODE_COMMA: //,
keyAction = ACT_DIG_LEFT;
break;
case KEYCODE_X:
case KEYCODE_O:
case KEYCODE_E:
case KEYCODE_PERIOD: //.
keyAction = ACT_DIG_RIGHT;
break;
case KEYCODE_ESC: //help & pause
if(gameState == GAME_PAUSE) {
gameResume();
showTipsText("", 1000); //clear text
} else {
gamePause();
showTipsText("PAUSE", 0); //display "PAUSE"
//helpObj.showHelp(helpCallBack);
}
break;
case KEYCODE_ENTER: //display hi-score
if(playMode == PLAY_CLASSIC) {
menuIconDisable(1);
gamePause();
showScoreTable(playData, null, function() { menuIconEnable(); gameResume();});
} else {
keyAction = ACT_UNKNOWN;
}
break;
default:
keyAction = ACT_UNKNOWN;
//debug("keycode = " + code);
break;
}
if(recordMode && code != KEYCODE_ESC) saveKeyCode(code, keyAction);
}
function gameResume()
{
gameState = lastGameState;
soundResume(soundFall);
soundResume(soundDig);
}
function gamePause()
{
lastGameState = gameState;
gameState = GAME_PAUSE;
soundPause(soundFall);
soundPause(soundDig);
}
function handleKeyDown(event)
{
if(!event){ event = window.event; } //cross browser issues exist
if(event.shiftKey) {
if(gameState == GAME_START || gameState == GAME_RUNNING) {
pressShiftKey(event.keyCode);
}
} else
if (event.ctrlKey) {
if(gameState == GAME_START || gameState == GAME_RUNNING) {
pressCtrlKey(event.keyCode);
}
} else {
if((gameState == GAME_PAUSE && event.keyCode == KEYCODE_ESC) ||
gameState == GAME_START || gameState == GAME_RUNNING)
{
if(recordMode != RECORD_PLAY && playMode != PLAY_AUTO) {
pressKey(event.keyCode);
}
}
}
if(event.keyCode >= 112 && event.keyCode <= 123) return true; //F1 ~ F12
return false;
}
function handleKeyUp(event)
{
if(repeatAction) return true;
if(!event){ event = window.event; }
if(recordKeyCode == event.keyCode && keyPressed != -1) keyPressed = 0;
return true;
}