Created
December 31, 2019 04:23
-
-
Save radzionc/3c437cdb6cb9e6f03bb5619681001f4b to your computer and use it in GitHub Desktop.
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
export class GameManager { | |
// ... | |
restart() { | |
// ... | |
this.lastUpdate = undefined | |
this.stopTime = undefined | |
} | |
// ... | |
tick() { | |
if (!this.stopTime) { | |
const lastUpdate = Date.now() | |
if (this.lastUpdate) { | |
this.game.process(lastUpdate - this.lastUpdate, this.controller.movement) | |
if (this.game.is_over()) { | |
this.restart() | |
return | |
} | |
if (this.game.score > Storage.getBestScore()) { | |
localStorage.setItem('bestScore', this.game.score) | |
Storage.setBestScore(this.game.score) | |
} | |
} | |
this.lastUpdate = lastUpdate | |
this.render() | |
} | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment