Created
December 24, 2012 14:01
-
-
Save vgheri/4369350 to your computer and use it in GitHub Desktop.
client physics loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function updatePhysics() { | |
// 1: updates self position and direction | |
if (!pongR.updateTimestamp) { // The first time this loop runs, pongR.updateTimestamp will be undefined | |
pongR.updateTimestamp = new Date().getTime(); | |
} | |
else { | |
var now = new Date().getTime(); | |
pongR.deltaTime = (now - pongR.updateTimestamp) / 1000; | |
//console.log("Delta time: " + pongR.deltaTime + ". Now: " + now + ", previous update: " + pongR.updateTimestamp); | |
pongR.updateTimestamp = now; | |
} | |
pongR.me.topLeftVertex = computeNewClientPosition(); | |
// 2: update ball position | |
var newPosition = updateBallPosition(pongR.game.ball.angle, pongR.game.ball.position, pongR.deltaTime, pongR.settings.BALL_FIXED_STEP); | |
pongR.game.ball.position = newPosition; | |
// 2: check collision | |
checkForCollisionsAndUpdateBallState(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment