Skip to content

Commit

Permalink
feat: Change player direction
Browse files Browse the repository at this point in the history
  • Loading branch information
johnedvard committed Aug 17, 2022
1 parent 1ec3ee5 commit 883eee1
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class Player {
rope = []; // list of pointmasses
pointMass;
playerControls;
sprite;
sprite = { render: () => {} };

constructor(x, y, game) {
this.x = x;
Expand Down Expand Up @@ -87,13 +87,20 @@ export class Player {
}

renderPlayer(_ctx) {
if (this.sprite) {
this.sprite.render();
}
this.sprite.render();
}

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

changePlayerDirection(isLeft) {
if (isLeft) {
this.sprite.scaleX = -2;
} else {
this.sprite.scaleX = 2;
}
}

render(ctx) {
Expand All @@ -104,10 +111,9 @@ export class Player {
update() {
this.x = this.pointMass.x;
this.y = this.pointMass.y;
if (this.sprite) {
this.sprite.x = this.pointMass.x;
this.sprite.y = this.pointMass.y;
}

this.sprite.x = this.pointMass.x;
this.sprite.y = this.pointMass.y;

this.updateRope();
this.dragRope();
Expand Down

0 comments on commit 883eee1

Please sign in to comment.