Skip to content

Commit

Permalink
Fix jump after fall
Browse files Browse the repository at this point in the history
  • Loading branch information
WimYedema committed Jan 24, 2024
1 parent aabc5bc commit a48a865
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
11 changes: 4 additions & 7 deletions src/actors/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,7 @@ export class Player extends GameActor<PlayerState> {
onPostCollision(evt: ex.PostCollisionEvent) {
// Bot has collided with it's Top of another collider
this._state.groundVel = ex.Vector.Zero;
if (evt.side === ex.Side.Bottom && evt.other instanceof Ground) {
this._state.onGround = true;
} else if (evt.side === ex.Side.Bottom && evt.other instanceof Lift) {
this._state.onGround = true;
if (evt.side === ex.Side.Bottom && evt.other instanceof Lift) {
this._state.groundVel = evt.other.vel;
}

Expand All @@ -163,7 +160,6 @@ export class Player extends GameActor<PlayerState> {
this._state.hurt = true;
this._state.hurtTime = 1000;
this.vel.y = -200;
this._state.onGround = false;
Resources.hit.play(0.1);
if (stats.health == 0) {
// Remove ability to collide. This will result in gameover when the player leaves the camera
Expand Down Expand Up @@ -214,7 +210,6 @@ export class Player extends GameActor<PlayerState> {
this._state.onGround
) {
this.vel.y = -tileSize * 20 * Math.sqrt(this._state.scaleTarget / 3);
this._state.onGround = false;
this.graphics.use("jumpleft");
Resources.jump.play(0.1);
}
Expand All @@ -223,7 +218,8 @@ export class Player extends GameActor<PlayerState> {
// Change animation based on velocity
if (!this._state.hurt) {
let relvel = this.vel.sub(this._state.groundVel);
if (this._state.onGround) {
if (relvel.y == 0) {
this._state.onGround = true;
if (relvel.x === 0) {
this.graphics.use("idle");
} else if (relvel.x < 0) {
Expand All @@ -232,6 +228,7 @@ export class Player extends GameActor<PlayerState> {
this.graphics.use("right");
}
} else {
this._state.onGround = false;
if (relvel.x < 0) {
this.graphics.use("jumpleft");
} else {
Expand Down
8 changes: 6 additions & 2 deletions src/core/levelLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ export abstract class LevelLayout extends ex.Scene implements iSceneNode {
scoreLabel.color = ex.Color.Black;
scoreLabel.on("preupdate", (evt) => {
scoreLabel.text =
"♥".repeat(stats.health) + "♡".repeat(5 - stats.health)+
" S" + stats.score + " Opdracht: " + assignment;
"♥".repeat(stats.health) +
"♡".repeat(5 - stats.health) +
" S" +
stats.score +
" Opdracht: " +
assignment;
});
engine.add(scoreLabel);

Expand Down

0 comments on commit a48a865

Please sign in to comment.