Permalink
Browse files

explicitly increment 'elapsed' time so we can handle computer suspens…

…ion/hibernation/sleep/etc.
  • Loading branch information...
1 parent eb10279 commit 6366c53a98d61e5b37218a38c62415c9ed95889d @rflynn committed Mar 20, 2012
Showing with 4 additions and 1 deletion.
  1. +4 −1 jquery.pong.js
View
@@ -126,7 +126,7 @@
{
var profTxt = '';
var now = new Date();
- var elapsed = Math.round((now.valueOf() - gameData.start.valueOf()) / 1000.0);
+ var elapsed = Math.round(gameData.elapsed / 1000.0);
var gamecnt = gameData.playerWins + gameData.compWins;
var pointcnt = gameData.compScoreTotal + gameData.playerScoreTotal;
var ppg = Math.round(pointcnt / Math.max(1, gamecnt) * 100) / 100;
@@ -366,6 +366,7 @@
gameOver: true,
delay: new Date(),
start: new Date(),
+ elapsed: 0, // number of seconds elapsed since start
playerScoreTotal: 0,
compScoreTotal: 0,
playerWins: 0,
@@ -465,6 +466,8 @@
gameData.speed = opts.targetSpeed;
Update(gameData, balls);
+ setInterval(function(){ gameData.elapsed += 1.0;}, 1000);
+
if (opts.autoStart)
Start(gameData, balls);
else // wait for click

0 comments on commit 6366c53

Please sign in to comment.