Tetris/JavaScript: Difference between revisions
m
→Code: Fixed syntax highlighting.
m (→Code: small changes) |
m (→Code: Fixed syntax highlighting.) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 2:
WASD or arrow keys.
===Code===
{{trans|Java}}
<
<html lang='en'>
<head>
<meta charset='UTF-8'>
Line 19 ⟶ 20:
</style>
</head>
<body>
<canvas></canvas>
Line 75 ⟶ 77:
var keyDown = false;
var fastDown = false;
var grid = [];
Line 98 ⟶ 99:
case 'ArrowLeft':
if (canMove(fallingShape, left))
move(
break;
Line 104 ⟶ 105:
case 'ArrowRight':
if (canMove(fallingShape, right))
move(
break;
Line 112 ⟶ 113:
fastDown = true;
while (canMove(fallingShape, down)) {
move(
draw();
}
Line 164 ⟶ 165:
}
function move(
fallingShapeRow += dir.y;
fallingShapeCol += dir.x;
Line 458 ⟶ 459:
}
var requestId = requestAnimationFrame(
animate(lastFrameTime);
});
var time = new Date().getTime();
var delay = scoreboard.getSpeed();
Line 469 ⟶ 472:
if (canMove(fallingShape, down)) {
move(
} else {
shapeHasLanded();
Line 486 ⟶ 489:
selectShape();
scoreboard.reset();
animate(-1);
}
Line 515 ⟶ 518:
</body>
</html></syntaxhighlight>
|