Skip to content

Commit

Permalink
fix timer and lap indicator (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChikanchiDmitrii authored Oct 12, 2024
1 parent 78cd1f6 commit 4f182d2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
13 changes: 3 additions & 10 deletions js/CGameBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,9 @@ CGameBase.prototype.update = function () {
this._oPlayer.update(iDt);

this.updateRace(iDt);
this.raceTimer =
this.raceTimer ||
setInterval(() => {
this._iGameState;
this.raceTime += this._iGameState === STATE_GAME_END ? 0 : 10;
this._oInterface.refreshRaceTime(this.raceTime);
}, 10);

this.raceTime += this._iGameState === STATE_GAME_END ? 0 : iDt;
this._oInterface.refreshRaceTime(this.raceTime);

break;
}
Expand All @@ -469,9 +465,6 @@ CGameBase.prototype.update = function () {
this._oPlayer.autoPilot();

this.updateOpponents(iDt);
clearInterval(this.raceTimer);
this.raceTimer = 0;
// this.resetParams();

break;
}
Expand Down
2 changes: 1 addition & 1 deletion js/CGameRace.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ CGameRace.prototype.trackCompleted = function () {
}
$(s_oMain).trigger("save_score", {
score: iTotalScore,
raceTime: this.raceTime,
raceTime: Math.round(this.raceTime * 1000),
});
} else {
var oLosePanel = new CLosePanel(iPlayerRank);
Expand Down
10 changes: 5 additions & 5 deletions js/lib/CTimeFormatter.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
function formatTimeCustomly(iMilliseconds) {
const iTotalSeconds = Math.floor(iMilliseconds / 1000);
function formatTimeCustomly(iSeconds) {
const iTotalSeconds = Math.floor(iSeconds);
const iMinutes = Math.floor(iTotalSeconds / 60);
const iSeconds = iTotalSeconds % 60;
const iMillis = iMilliseconds % 1000;
const iSecs = iTotalSeconds % 60;
const iMillis = Math.floor((iSeconds - iTotalSeconds) * 1000);

const szMinutes = String(iMinutes).padStart(2, "0");
const szSeconds = String(iSeconds).padStart(2, "0");
const szSeconds = String(iSecs).padStart(2, "0");
const szMillis = String(iMillis).padStart(3, "0");

return `${szMinutes}:${szSeconds}:${szMillis}`;
Expand Down

0 comments on commit 4f182d2

Please sign in to comment.