Skip to content

Commit

Permalink
fix: Avoid adding extra listeners, avoid moving when has won, avoid r…
Browse files Browse the repository at this point in the history
…espawning when has won
  • Loading branch information
johnedvard committed Sep 13, 2022
1 parent 6831421 commit 3302526
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class Player {
sprite = { render: () => {}, x: 0, y: 0 };
headSprite = { render: () => {}, x: 0, y: 0 }; // From Arcadian API
hasWon = false;
hasSetListeners = false;
headImg;
headOffset = { x: 10, y: 38 };
isLeft = false;
Expand Down Expand Up @@ -184,6 +185,7 @@ export class Player {
}
}
handleDeadInAir() {
if (this.hasWon) return;
if (!this.isRopeCut || this.playerState == PLAYER_DEAD) return;
this.deadInAirTimer += 1;
if (this.deadInAirTimer >= this.deadInAirLimit) {
Expand Down Expand Up @@ -243,9 +245,11 @@ export class Player {
}
resetHearts() {}
listenForGameEvents() {
if (this.hasSetListeners) return;
on(GOAL_COLLISION, this.onGoalCollision);
on(ARCADIAN_HEAD_SELECTED, this.onArcadianAdded);
on(CUT_ROPE, this.onCutRope);
this.hasSetListeners = true;
}
onGoalCollision = () => {
this.hasWon = true;
Expand Down
7 changes: 6 additions & 1 deletion src/PlayerControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ export class PlayerControls {
}

updateControls() {
if (this.player.isRopeCut || this.player.rope.length <= 0) return;
if (
this.player.hasWon ||
this.player.isRopeCut ||
this.player.rope.length <= 0
)
return;
// TODO (johnedvard) add support for touch gesture and gamepad (if enough space)
if (keyPressed('arrowleft')) {
this.player.applyForce(-1.5, -1);
Expand Down

0 comments on commit 3302526

Please sign in to comment.