Skip to content

Commit

Permalink
Remove firstRun param from reset function
Browse files Browse the repository at this point in the history
  • Loading branch information
mhluska committed Jun 26, 2016
1 parent e7e4d32 commit 24d6fea
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions source/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Game {
constructor(container, { keys = true } = {}) {
this._container = container;
[this._scene, this._camera, this._renderer] = this._setupScene(this._container);
this.reset();
this.setup();
this._cameraOriginalPosition = this._camera.position.clone();
this._cameraOriginalUp = this._camera.up.clone();
this._container.appendChild(this._renderer.domElement);
Expand All @@ -26,14 +26,9 @@ class Game {
this._animate();
}

reset({ firstRun = true } = {}) {
if (!firstRun) {
this._world.reset();
this._clearSceneMeshes();
this._camera.position.copy(this._cameraOriginalPosition);
this._camera.up.copy(this._cameraOriginalUp);
}

// NOTE(maros): This should be idempotent because it is called whenever the
// player dies.
setup() {
this._steps = 0;
this._debugMeshes = new Set();

Expand Down Expand Up @@ -67,6 +62,14 @@ class Game {
this._scene.add(...this._enemies.map(enemy => enemy.mesh));
}

reset() {
this._world.reset();
this._clearSceneMeshes();
this._camera.position.copy(this._cameraOriginalPosition);
this._camera.up.copy(this._cameraOriginalUp);
this.setup();
}

setupEventListeners(keys) {
window.addEventListener('resize', this._updateScreenSizeResize.bind(this));

Expand Down Expand Up @@ -231,7 +234,7 @@ class Game {
try {
this._update();
} catch(error) {
this.reset({ firstRun: false });
this.reset();
this._update();
}

Expand Down

0 comments on commit 24d6fea

Please sign in to comment.