fix&feat: make dash smother and make it available for all states

This commit is contained in:
Renge 2022-04-17 19:22:09 -04:00
parent 88535c4529
commit d3bcb0df79
4 changed files with 29 additions and 13 deletions

View File

@ -11,7 +11,7 @@ export default class Idle extends OnGround {
update(deltaT: number): void {
super.update(deltaT);
this.owner.animation.playIfNotAlready("IDLE", true);
@ -22,7 +22,7 @@ export default class Idle extends OnGround {
}
this.parent.velocity.x = 0;
super.update(deltaT);
this.owner.move(this.parent.velocity.scaled(deltaT));
}

View File

@ -16,7 +16,7 @@ export default class OnGround extends PlayerState {
}
super.update(deltaT);
let direction = this.getInputDirection();
@ -34,7 +34,8 @@ export default class OnGround extends PlayerState {
else if(!this.owner.onGround){
this.finished("fall");
}
super.update(deltaT);
this.owner.move(this.parent.velocity.scaled(deltaT));
}

View File

@ -3,6 +3,7 @@ import StateMachine from "../../../Wolfie2D/DataTypes/State/StateMachine";
import Vec2 from "../../../Wolfie2D/DataTypes/Vec2";
import GameEvent from "../../../Wolfie2D/Events/GameEvent";
import GameNode from "../../../Wolfie2D/Nodes/GameNode";
import Sprite from "../../../Wolfie2D/Nodes/Sprites/Sprite";
import Timer from "../../../Wolfie2D/Timing/Timer";
import { Player_Events } from "../../sword_enums";
import InputWrapper from "../../Tools/InputWrapper";
@ -14,12 +15,16 @@ export default abstract class PlayerState extends State {
gravity: number = 1500; //TODO - can change later
parent: PlayerController;
positionTimer: Timer;
static dashTimer: Timer;
static dashCoolDownTimer: Timer;
constructor(parent: StateMachine, owner: GameNode){
super(parent);
this.owner = owner;
this.positionTimer = new Timer(250);
this.positionTimer.start();
PlayerState.dashTimer = new Timer(50);
PlayerState.dashCoolDownTimer = new Timer(600);
}
@ -27,6 +32,17 @@ export default abstract class PlayerState extends State {
}
doDash(): void {
if (PlayerState.dashCoolDownTimer.isStopped()) {
//TODO - decide how to implement dash - could be a flash - maybe allow in air as well
//play dash anim maybe
//TODO - might give buffed speed stat to dash speed
//TODO - give player i frame
PlayerState.dashCoolDownTimer.start();
PlayerState.dashTimer.start();
}
}
/**
* Get the inputs from the keyboard, or Vec2.Zero if nothing is being pressed
*/
@ -47,5 +63,12 @@ export default abstract class PlayerState extends State {
this.positionTimer.start();
}
this.parent.velocity.y += this.gravity*deltaT;
if(InputWrapper.isDashJustPressed()){
this.doDash();
}
if (!PlayerState.dashTimer.isStopped()) {
this.parent.velocity.x = (<Sprite>this.owner).invertX ? -800 : 800;
}
}
}

View File

@ -13,7 +13,6 @@ export default class Walk extends OnGround {
update(deltaT: number): void {
super.update(deltaT);
//console.log("walking anim");
this.owner.animation.playIfNotAlready("WALK", true);
@ -25,14 +24,7 @@ export default class Walk extends OnGround {
this.parent.velocity.x = dir.x * (this.parent.speed + this.parent.CURRENT_BUFFS.speed);
//TODO - decide how to implement dash - could be a flash - maybe allow in air as well
if(InputWrapper.isDashJustPressed()){
//play dash anim maybe
//TODO - might give buffed speed stat to dash speed
this.parent.velocity.x = dir.x * 1000; //give sidewards velocity
//TODO - give player i frame
}
this.owner.move(this.parent.velocity.scaled(deltaT));
super.update(deltaT);
}
onExit(): Record<string, any> {