|
68 | 68 | // game constants
|
69 | 69 | //-------------------------------------------------------------------------
|
70 | 70 |
|
71 |
| - var KEY = { ESC: 27, SPACE: 32, LEFT: 37, UP: 38, RIGHT: 39, DOWN: 40 }, |
72 |
| - DIR = { UP: 0, RIGHT: 1, DOWN: 2, LEFT: 3, MIN: 0, MAX: 3 }, |
| 71 | + var KEY = { ESC: 27, SPACE: 32, LEFT: 37, UP: 38, RIGHT: 39, DOWN: 40, SHIFT: 16 }, |
| 72 | + // drop all the way to BOTTOM is an action, but MAX=3 to avoid reaching |
| 73 | + // it by rotation |
| 74 | + DIR = { UP: 0, RIGHT: 1, DOWN: 2, LEFT: 3, BOTTOM:4, MIN: 0, MAX: 3 }, |
73 | 75 | stats = new Stats(),
|
74 | 76 | canvas = get('canvas'),
|
75 | 77 | ctx = canvas.getContext('2d'),
|
|
216 | 218 | var handled = false;
|
217 | 219 | if (playing) {
|
218 | 220 | switch(ev.keyCode) {
|
219 |
| - case KEY.LEFT: actions.push(DIR.LEFT); handled = true; break; |
220 |
| - case KEY.RIGHT: actions.push(DIR.RIGHT); handled = true; break; |
221 |
| - case KEY.UP: actions.push(DIR.UP); handled = true; break; |
222 |
| - case KEY.DOWN: actions.push(DIR.DOWN); handled = true; break; |
223 |
| - case KEY.ESC: lose(); handled = true; break; |
| 221 | + case KEY.LEFT: actions.push(DIR.LEFT); handled = true; break; |
| 222 | + case KEY.RIGHT: actions.push(DIR.RIGHT); handled = true; break; |
| 223 | + case KEY.UP: actions.push(DIR.UP); handled = true; break; |
| 224 | + case KEY.DOWN: actions.push(DIR.DOWN); handled = true; break; |
| 225 | + case KEY.SHIFT: |
| 226 | + // special care to only push once, even if it stays pressed |
| 227 | + if( actions[0] != DIR.BOTTOM ) { |
| 228 | + actions.push(DIR.BOTTOM); handled = true; |
| 229 | + } |
| 230 | + break; |
| 231 | + case KEY.ESC: lose(); handled = true; break; |
224 | 232 | }
|
225 | 233 | }
|
226 | 234 | else if (ev.keyCode == KEY.SPACE) {
|
|
277 | 285 |
|
278 | 286 | function handle(action) {
|
279 | 287 | switch(action) {
|
280 |
| - case DIR.LEFT: move(DIR.LEFT); break; |
281 |
| - case DIR.RIGHT: move(DIR.RIGHT); break; |
282 |
| - case DIR.UP: rotate(); break; |
283 |
| - case DIR.DOWN: drop(); break; |
| 288 | + case DIR.LEFT: move(DIR.LEFT); break; |
| 289 | + case DIR.RIGHT: move(DIR.RIGHT); break; |
| 290 | + case DIR.UP: rotate(); break; |
| 291 | + case DIR.DOWN: drop(); break; |
| 292 | + case DIR.BOTTOM: dropMany(); break; |
284 | 293 | }
|
285 | 294 | }
|
286 | 295 |
|
|
324 | 333 | }
|
325 | 334 | }
|
326 | 335 |
|
| 336 | + function dropMany() { |
| 337 | + while( move(DIR.DOWN) ) { } |
| 338 | + addScore(10); |
| 339 | + dropPiece(); |
| 340 | + removeLines(); |
| 341 | + setCurrentPiece(next); |
| 342 | + setNextPiece(randomPiece()); |
| 343 | + clearActions(); |
| 344 | + if (occupied(current.type, current.x, current.y, current.dir)) { |
| 345 | + lose(); |
| 346 | + } |
| 347 | + } |
| 348 | + |
327 | 349 | function dropPiece() {
|
328 | 350 | eachblock(current.type, current.x, current.y, current.dir, function(x, y) {
|
329 | 351 | setBlock(x, y, current.type);
|
|
0 commit comments