forked from SimonHung/LodeRunner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlodeRunner.key.js
245 lines (227 loc) · 5.21 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
var keyAction = ACT_STOP; //// keyLastLeftRight = ACT_RIGHT;
var shiftLevelNum = 0;
var runnerDebug = 0;
function pressShiftKey(code)
{
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];
showTipsText("COPY MAP", 0);
break;
case KEYCODE_R: //CTRL-R : abort game
runnerLife = 1;
gameState = GAME_RUNNER_DEAD;
break;
case KEYCODE_S: //CTRL-S, toggle sound
if( (soundOff ^= 1) == 1) {
soundDig.stop();
soundFall.stop();
showTipsText("SOUND OFF", 0);
} else {
showTipsText("SOUND ON", 0);
}
break;
case KEYCODE_LEFT: //SHIFT + <- : speed down
setSpeed(-1);
break;
case KEYCODE_RIGHT: //SHIFT + -> : speed up
setSpeed(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 godMode = 0, godModeKeyPressed = 0;
function initHotKeyVariable()
{
godMode = 0;
godModeKeyPressed = 0;
}
function toggleGodMode()
{
godModeKeyPressed = 1; //means player press the god-mod hot-key
godMode ^= 1;
if(godMode) {
showTipsText("GOD MODE ON", 0);
} else {
showTipsText("GOD MODE OFF", 0);
}
}
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], 0);
}
function helpCallBack() //help complete call back
{
pressKey(KEYCODE_ESC);
}
function pressKey(code)
{
switch(code) {
case KEYCODE_LEFT:
case KEYCODE_J:
keyAction = ACT_LEFT;
break;
case KEYCODE_RIGHT:
case KEYCODE_L:
keyAction = ACT_RIGHT;
break;
case KEYCODE_UP:
case KEYCODE_I:
keyAction = ACT_UP;
break;
case KEYCODE_DOWN:
case KEYCODE_K:
keyAction = ACT_DOWN;
break;
case KEYCODE_Z:
case KEYCODE_U:
keyAction = ACT_DIG_LEFT;
break;
case KEYCODE_X:
case KEYCODE_O:
keyAction = ACT_DIG_RIGHT;
break;
case KEYCODE_ESC: //help & pause
if(gameState == GAME_PAUSE) {
gameResume();
showTipsText("", 0); //clear text
} else {
gamePause();
showTipsText("PAUSE", 1); //display "PAUSE"
//helpObj.showHelp(helpCallBack);
}
break;
case KEYCODE_ENTER: //display hi-score
if(playMode == PLAY_CLASSIC) {
menuIconDisable(1);
gamePause();
showScoreTable(playData-1, 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);
}
}
}
/*
//e.cancelBubble is supported by IE - this will kill the bubbling process.
event.cancelBubble = true;
event.returnValue = false;
//event.stopPropagation works only in Firefox.
if (event.stopPropagation) {
event.stopPropagation();
event.preventDefault();
}
*/
if(event.keyCode >= 112 && event.keyCode <= 123) return true; //F1 ~ F12
return false;
}