Skip to content

Instantly share code, notes, and snippets.

@radzionc
Created December 31, 2019 04:23
Show Gist options
  • Save radzionc/3c437cdb6cb9e6f03bb5619681001f4b to your computer and use it in GitHub Desktop.
Save radzionc/3c437cdb6cb9e6f03bb5619681001f4b to your computer and use it in GitHub Desktop.
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