Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
client physics loop
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
You can’t perform that action at this time.