Skip to content

Commit

Permalink
Introduces current frame date to save date objects
Browse files Browse the repository at this point in the history
  • Loading branch information
maechler committed Apr 6, 2019
1 parent c621a34 commit d4a3f26
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/KurveCurve.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ Kurve.Curve.prototype.isCollided = function(positionX, positionY) {
};

Kurve.Curve.prototype.isWithinSelfCollisionTimeout = function(time) {
var now = new Date();
return now.getTime() - time.getTime() < this.getOptions().selfCollisionTimeout;
return Kurve.Game.CURRENT_FRAME_DATE.getTime() - time.getTime() < this.getOptions().selfCollisionTimeout;
};

Kurve.Curve.prototype.die = function() {
Expand Down
2 changes: 1 addition & 1 deletion src/KurveField.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Kurve.Field = {
this.drawnPixels[pointX0][pointY0] = {
color: color,
curve: curve,
time: new Date()
time: Kurve.Game.CURRENT_FRAME_DATE
};

if ( Kurve.Config.Debug.fieldDrawnPixels ) {
Expand Down
6 changes: 4 additions & 2 deletions src/KurveGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Kurve.Game = {
isRoundStarted: false,
playerScoresElement: null,
isGameOver: false,
CURRENT_FRAME_DATE: null,

init: function() {
this.fps = Kurve.Config.Game.fps;
Expand All @@ -51,6 +52,7 @@ Kurve.Game = {
},

run: function() {
this.CURRENT_FRAME_DATE = new Date();
requestAnimationFrame(this.drawFrame.bind(this));
},

Expand Down Expand Up @@ -178,7 +180,7 @@ Kurve.Game = {
this.Audio.startNewRound();
},

startRun: function() {
startRun: function() {
this.isRunning = true;
this.runIntervalId = setInterval(this.run.bind(this), this.intervalTimeOut);

Expand All @@ -187,7 +189,7 @@ Kurve.Game = {
});
},

stopRun: function() {
stopRun: function() {
this.isRunning = false;
clearInterval(this.runIntervalId);
},
Expand Down
2 changes: 1 addition & 1 deletion src/KurveSuperpowerconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ Kurve.Superpowerconfig[Kurve.Superpowerconfig.types.HYDRA] = {
},

act: function(hook, curve) {
var now = new Date();
var now = Kurve.Game.CURRENT_FRAME_DATE;

if ( now.getTime() - curve.hydraData.previousExecution.getTime() > this.helpers.timeOut ) {
curve.hydraData.previousExecution = now;
Expand Down

0 comments on commit d4a3f26

Please sign in to comment.