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}}
<langsyntaxhighlight lang="javascript"><!DOCTYPE html>
<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 lastFrameTime = -1;
 
var grid = [];
Line 98 ⟶ 99:
case 'ArrowLeft':
if (canMove(fallingShape, left))
move(fallingShape, left);
break;
 
Line 104 ⟶ 105:
case 'ArrowRight':
if (canMove(fallingShape, right))
move(fallingShape, right);
break;
 
Line 112 ⟶ 113:
fastDown = true;
while (canMove(fallingShape, down)) {
move(fallingShape, down);
draw();
}
Line 164 ⟶ 165:
}
 
function move(s, dir) {
fallingShapeRow += dir.y;
fallingShapeCol += dir.x;
Line 458 ⟶ 459:
}
 
function animate(lastFrameTime) {
var requestId = requestAnimationFrame(animatefunction (); {
animate(lastFrameTime);
 
});
var time = new Date().getTime();
var delay = scoreboard.getSpeed();
Line 469 ⟶ 472:
 
if (canMove(fallingShape, down)) {
move(fallingShape, down);
} else {
shapeHasLanded();
Line 486 ⟶ 489:
selectShape();
scoreboard.reset();
animate(-1);
}
 
Line 515 ⟶ 518:
 
</body>
 
</html></lang>
</html></syntaxhighlight>
9,485

edits