mirror of
https://github.com/hexahigh/games.git
synced 2025-12-11 20:15:38 +01:00
fixed wasd in tetris
This commit is contained in:
parent
b33c3b60cd
commit
6746bc5c73
@ -7,10 +7,10 @@ document.body.onkeydown = function( e ) {
|
||||
32: 'drop'
|
||||
};
|
||||
var keys = {
|
||||
68: 'left',
|
||||
65: 'right',
|
||||
83: 'down',
|
||||
87: 'rotate',
|
||||
65: 'left2',
|
||||
68: 'right2',
|
||||
83: 'down2',
|
||||
87: 'rotate2',
|
||||
};
|
||||
if ( typeof keys[ e.keyCode ] != 'undefined' ) {
|
||||
keyPress( keys[ e.keyCode ] );
|
||||
|
||||
@ -158,6 +158,33 @@ function keyPress( key ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
function keyPress( key ) {
|
||||
switch ( key ) {
|
||||
case 'left2':
|
||||
if ( valid( -1 ) ) {
|
||||
--currentX;
|
||||
}
|
||||
break;
|
||||
case 'right2':
|
||||
if ( valid( 1 ) ) {
|
||||
++currentX;
|
||||
}
|
||||
break;
|
||||
case 'down2':
|
||||
if ( valid( 0, 1 ) ) {
|
||||
++currentY;
|
||||
}
|
||||
break;
|
||||
case 'rotate2':
|
||||
var rotated = rotate( current );
|
||||
if ( valid( 0, 0, rotated ) ) {
|
||||
current = rotated;
|
||||
|
||||
}
|
||||
tick();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// checks if the resulting position of current shape will be feasible
|
||||
function valid( offsetX, offsetY, newCurrent ) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user