From cf3c3cf860f84dea3f46a17b787b69823075cda3 Mon Sep 17 00:00:00 2001 From: Renge Date: Sat, 7 May 2022 22:32:39 -0400 Subject: [PATCH] feat: dash doesnot affect by gravity and will cancel jump --- .../Player/PlayerStates/Jump.ts | 19 ++++++++++--------- .../Player/PlayerStates/PlayerState.ts | 19 +++++++++++-------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/shattered_sword/Player/PlayerStates/Jump.ts b/src/shattered_sword/Player/PlayerStates/Jump.ts index 1f4ac50..1f21cc3 100644 --- a/src/shattered_sword/Player/PlayerStates/Jump.ts +++ b/src/shattered_sword/Player/PlayerStates/Jump.ts @@ -38,21 +38,22 @@ export default class Jump extends InAir { } } - + if(this.owner.onCeiling){ + this.parent.velocity.y = 0; + this.finished(PlayerStates.FALL); + } + // If we're falling, go to the fall state + if(this.parent.velocity.y >= 0){ + this.finished(PlayerStates.FALL); + } + if (!this.jumpTimer.isStopped() && !this.jumpTimer.isPaused() && InputWrapper.isJumpPressed()) { this.parent.velocity.y = -400; } else { this.jumpTimer.pause(); } - - if(this.owner.onCeiling){ - this.parent.velocity.y = 0; - } - // If we're falling, go to the fall state - if(this.parent.velocity.y >= 0){ - this.finished(PlayerStates.FALL); - } + super.update(deltaT); } diff --git a/src/shattered_sword/Player/PlayerStates/PlayerState.ts b/src/shattered_sword/Player/PlayerStates/PlayerState.ts index 1db2272..c050b5f 100644 --- a/src/shattered_sword/Player/PlayerStates/PlayerState.ts +++ b/src/shattered_sword/Player/PlayerStates/PlayerState.ts @@ -58,23 +58,26 @@ export default abstract class PlayerState extends State { update(deltaT: number): void { - // Do gravity + if (this.positionTimer.isStopped()){ this.emitter.fireEvent(Player_Events.PLAYER_MOVE, {position: this.owner.position.clone()}); this.positionTimer.start(); } - - if(InputWrapper.isDashJustPressed()){ - this.doDash(); - } - if (!PlayerState.dashTimer.isStopped()) { - this.parent.velocity.x = (this.owner).invertX ? -800 : 800; - } if (InputWrapper.getState() === GameState.GAMING) { + // Do gravity (this.parent.owner).animation.resume(); this.parent.velocity.y += this.gravity*deltaT; + + // Do dash + if(InputWrapper.isDashJustPressed()){ + this.doDash(); + } + if (!PlayerState.dashTimer.isStopped()) { + this.parent.velocity.x = (this.owner).invertX ? -800 : 800; + this.parent.velocity.y = 0; + } this.owner.move(this.parent.velocity.scaled(deltaT)); } else {