Skip to content

Commit

Permalink
fix: Prevent player from humping on the ground
Browse files Browse the repository at this point in the history
  • Loading branch information
johnedvard committed Aug 17, 2022
1 parent 883eee1 commit 117cbbb
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export class Player {

applyForce(fX, fY) {
this.pointMass.applyForce(fX, fY);
this.changePlayerDirection(fX < 0);
}

changePlayerDirection(isLeft) {
Expand Down
2 changes: 2 additions & 0 deletions src/PlayerControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ export class PlayerControls {
// TODO (johnedvard) add support for touch gesture and gamepad (if enough space)
if (keyPressed('arrowleft')) {
this.player.applyForce(-1.5, 0);
this.player.changePlayerDirection(true);
}
if (keyPressed('arrowright')) {
this.player.applyForce(1.5, 0);
this.player.changePlayerDirection(false);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/PointMass.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class PointMass {
this.updatePhysics();
}
updatePhysics() {
if (this.y >= this.game.canvas.height - 2) return; // prevent humping on floor
this.applyForce(0, this.mass * gravity);

let velX = this.x - this.lastX;
Expand Down

0 comments on commit 117cbbb

Please sign in to comment.