fix&feat: make dash smother and make it available for all states
This commit is contained in:
parent
88535c4529
commit
d3bcb0df79
|
@ -11,7 +11,7 @@ export default class Idle extends OnGround {
|
||||||
|
|
||||||
|
|
||||||
update(deltaT: number): void {
|
update(deltaT: number): void {
|
||||||
super.update(deltaT);
|
|
||||||
|
|
||||||
this.owner.animation.playIfNotAlready("IDLE", true);
|
this.owner.animation.playIfNotAlready("IDLE", true);
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ export default class Idle extends OnGround {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.parent.velocity.x = 0;
|
this.parent.velocity.x = 0;
|
||||||
|
super.update(deltaT);
|
||||||
this.owner.move(this.parent.velocity.scaled(deltaT));
|
this.owner.move(this.parent.velocity.scaled(deltaT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ export default class OnGround extends PlayerState {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
super.update(deltaT);
|
|
||||||
|
|
||||||
let direction = this.getInputDirection();
|
let direction = this.getInputDirection();
|
||||||
|
|
||||||
|
@ -34,7 +34,8 @@ export default class OnGround extends PlayerState {
|
||||||
else if(!this.owner.onGround){
|
else if(!this.owner.onGround){
|
||||||
this.finished("fall");
|
this.finished("fall");
|
||||||
}
|
}
|
||||||
|
super.update(deltaT);
|
||||||
|
this.owner.move(this.parent.velocity.scaled(deltaT));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ import StateMachine from "../../../Wolfie2D/DataTypes/State/StateMachine";
|
||||||
import Vec2 from "../../../Wolfie2D/DataTypes/Vec2";
|
import Vec2 from "../../../Wolfie2D/DataTypes/Vec2";
|
||||||
import GameEvent from "../../../Wolfie2D/Events/GameEvent";
|
import GameEvent from "../../../Wolfie2D/Events/GameEvent";
|
||||||
import GameNode from "../../../Wolfie2D/Nodes/GameNode";
|
import GameNode from "../../../Wolfie2D/Nodes/GameNode";
|
||||||
|
import Sprite from "../../../Wolfie2D/Nodes/Sprites/Sprite";
|
||||||
import Timer from "../../../Wolfie2D/Timing/Timer";
|
import Timer from "../../../Wolfie2D/Timing/Timer";
|
||||||
import { Player_Events } from "../../sword_enums";
|
import { Player_Events } from "../../sword_enums";
|
||||||
import InputWrapper from "../../Tools/InputWrapper";
|
import InputWrapper from "../../Tools/InputWrapper";
|
||||||
|
@ -14,12 +15,16 @@ export default abstract class PlayerState extends State {
|
||||||
gravity: number = 1500; //TODO - can change later
|
gravity: number = 1500; //TODO - can change later
|
||||||
parent: PlayerController;
|
parent: PlayerController;
|
||||||
positionTimer: Timer;
|
positionTimer: Timer;
|
||||||
|
static dashTimer: Timer;
|
||||||
|
static dashCoolDownTimer: Timer;
|
||||||
|
|
||||||
constructor(parent: StateMachine, owner: GameNode){
|
constructor(parent: StateMachine, owner: GameNode){
|
||||||
super(parent);
|
super(parent);
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.positionTimer = new Timer(250);
|
this.positionTimer = new Timer(250);
|
||||||
this.positionTimer.start();
|
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
|
* 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.positionTimer.start();
|
||||||
}
|
}
|
||||||
this.parent.velocity.y += this.gravity*deltaT;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -13,7 +13,6 @@ export default class Walk extends OnGround {
|
||||||
|
|
||||||
|
|
||||||
update(deltaT: number): void {
|
update(deltaT: number): void {
|
||||||
super.update(deltaT);
|
|
||||||
//console.log("walking anim");
|
//console.log("walking anim");
|
||||||
this.owner.animation.playIfNotAlready("WALK", true);
|
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);
|
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
|
super.update(deltaT);
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onExit(): Record<string, any> {
|
onExit(): Record<string, any> {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user