HTML and CSS Reference
In-Depth Information
// Flag all the cells as "modified"
Grid[i][j] = 1;
}
}
// Call the update loop for the first time
requestAnimationFrame(update);
// Listen for keydown
window.addEventListener('keydown', function(e) {
var diff = 0.2;
switch(e.keyCode) {
case 37: // Left
case 65: // A
playerVelocityX -= diff;
break;
case 39: // Right
case 68: // D
playerVelocityX += diff;
break;
case 38: // Up
case 87: // W
playerVelocityY -= diff;
break;
case 40: // Down
case 83: // S
playerVelocityY += diff;
break;
}
// Make sure the acceleration in the X axis is limited
if (Math.abs(playerVelocityX) > playerVelocityLimit) {
playerVelocityX = (playerVelocityX < 0) ? (playerVelocityLimit * -1) :
playerVelocityLimit;
}
// Make sure the acceleration in the Y axis is limited
if (Math.abs(playerVelocityY) > playerVelocityLimit) {
playerVelocityY = (playerVelocityY < 0) ? (playerVelocityLimit * -1) :
playerVelocityLimit;
}
}, false);
function update(ts) {
Search WWH ::




Custom Search