From b1028611f20ba76c12bfb2e3e0ed3f7142efebe0 Mon Sep 17 00:00:00 2001 From: Renge Date: Sun, 24 Apr 2022 18:41:17 -0400 Subject: [PATCH] feat: add dash animation --- .../spritesheets/Hiro.json | 20 +++++++++++++------ .../Player/PlayerStates/Fall.ts | 12 ++++++++--- .../Player/PlayerStates/Idle.ts | 9 ++++++++- .../Player/PlayerStates/Jump.ts | 12 ++++++++--- .../Player/PlayerStates/PlayerState.ts | 2 +- .../Player/PlayerStates/Walk.ts | 13 ++++++++---- 6 files changed, 50 insertions(+), 18 deletions(-) diff --git a/dist/shattered_sword_assets/spritesheets/Hiro.json b/dist/shattered_sword_assets/spritesheets/Hiro.json index 5f66021..647f076 100644 --- a/dist/shattered_sword_assets/spritesheets/Hiro.json +++ b/dist/shattered_sword_assets/spritesheets/Hiro.json @@ -310,23 +310,31 @@ "frames": [ { "index": 46, - "duration": 5 + "duration": 1 }, { "index": 47, - "duration": 5 + "duration": 1 }, { "index": 48, - "duration": 5 + "duration": 1 }, { "index": 49, - "duration": 5 + "duration": 2 }, { - "index": 50, - "duration": 10 + "index": 48, + "duration": 1 + }, + { + "index": 47, + "duration": 1 + }, + { + "index": 46, + "duration": 1 } ] } diff --git a/src/shattered_sword/Player/PlayerStates/Fall.ts b/src/shattered_sword/Player/PlayerStates/Fall.ts index c4a16fc..ff4a6a7 100644 --- a/src/shattered_sword/Player/PlayerStates/Fall.ts +++ b/src/shattered_sword/Player/PlayerStates/Fall.ts @@ -2,6 +2,7 @@ import GameEvent from "../../../Wolfie2D/Events/GameEvent"; import AnimatedSprite from "../../../Wolfie2D/Nodes/Sprites/AnimatedSprite"; import InAir from "./InAir"; import InputWrapper from "../../Tools/InputWrapper"; +import PlayerState from "./PlayerState"; export default class Fall extends InAir { owner: AnimatedSprite; @@ -11,11 +12,16 @@ export default class Fall extends InAir { } update(deltaT: number): void { - if (this.parent.invincible) { - this.owner.animation.playIfNotAlready("HURT"); + if (!PlayerState.dashTimer.isStopped()) { + this.owner.animation.playIfNotAlready("DASH"); } else { - this.owner.animation.playIfNotAlready("FALL", true); + if (this.parent.invincible) { + this.owner.animation.playIfNotAlready("HURT"); + } + else { + this.owner.animation.playIfNotAlready("FALL", true); + } } //TODO - testing doublejump, may have to move to InAir instead // If we jump, move to the Jump state, give a burst of upwards velocity diff --git a/src/shattered_sword/Player/PlayerStates/Idle.ts b/src/shattered_sword/Player/PlayerStates/Idle.ts index e343d61..1c73efe 100644 --- a/src/shattered_sword/Player/PlayerStates/Idle.ts +++ b/src/shattered_sword/Player/PlayerStates/Idle.ts @@ -1,6 +1,7 @@ import AnimatedSprite from "../../../Wolfie2D/Nodes/Sprites/AnimatedSprite"; import { PlayerStates } from "../PlayerController"; import OnGround from "./OnGround"; +import PlayerState from "./PlayerState"; export default class Idle extends OnGround { owner: AnimatedSprite; @@ -13,7 +14,13 @@ export default class Idle extends OnGround { update(deltaT: number): void { //("idle anim"); - this.owner.animation.playIfNotAlready("IDLE", true); + if (!PlayerState.dashTimer.isStopped()) { + console.log("Playing dash"); + this.owner.animation.playIfNotAlready("DASH"); + } + else { + this.owner.animation.playIfNotAlready("IDLE", true); + } let dir = this.getInputDirection(); diff --git a/src/shattered_sword/Player/PlayerStates/Jump.ts b/src/shattered_sword/Player/PlayerStates/Jump.ts index dcabfbe..4e7ee11 100644 --- a/src/shattered_sword/Player/PlayerStates/Jump.ts +++ b/src/shattered_sword/Player/PlayerStates/Jump.ts @@ -6,6 +6,7 @@ import { Player_Events } from "../../sword_enums"; import InputWrapper from "../../Tools/InputWrapper"; import { PlayerStates } from "../PlayerController"; import InAir from "./InAir"; +import PlayerState from "./PlayerState"; export default class Jump extends InAir { owner: AnimatedSprite; @@ -17,11 +18,16 @@ export default class Jump extends InAir { update(deltaT: number): void { - if (this.parent.invincible) { - this.owner.animation.playIfNotAlready("HURT"); + if (!PlayerState.dashTimer.isStopped()) { + this.owner.animation.playIfNotAlready("DASH"); } else { - this.owner.animation.playIfNotAlready("JUMP", true); + if (this.parent.invincible) { + this.owner.animation.playIfNotAlready("HURT"); + } + else { + this.owner.animation.playIfNotAlready("JUMP", true); + } } diff --git a/src/shattered_sword/Player/PlayerStates/PlayerState.ts b/src/shattered_sword/Player/PlayerStates/PlayerState.ts index 69b9449..3aa216b 100644 --- a/src/shattered_sword/Player/PlayerStates/PlayerState.ts +++ b/src/shattered_sword/Player/PlayerStates/PlayerState.ts @@ -24,7 +24,7 @@ export default abstract class PlayerState extends State { this.owner = owner; this.positionTimer = new Timer(250); this.positionTimer.start(); - PlayerState.dashTimer = new Timer(50); + PlayerState.dashTimer = new Timer(100); PlayerState.dashCoolDownTimer = new Timer(600); } diff --git a/src/shattered_sword/Player/PlayerStates/Walk.ts b/src/shattered_sword/Player/PlayerStates/Walk.ts index 09c1e50..dc539ee 100644 --- a/src/shattered_sword/Player/PlayerStates/Walk.ts +++ b/src/shattered_sword/Player/PlayerStates/Walk.ts @@ -3,6 +3,7 @@ import { Player_Events } from "../../sword_enums"; import InputWrapper from "../../Tools/InputWrapper"; import { PlayerStates } from "../PlayerController"; import OnGround from "./OnGround"; +import PlayerState from "./PlayerState"; export default class Walk extends OnGround { owner: AnimatedSprite; @@ -14,13 +15,17 @@ export default class Walk extends OnGround { update(deltaT: number): void { - if (this.parent.invincible) { - this.owner.animation.playIfNotAlready("HURT"); + if (!PlayerState.dashTimer.isStopped()) { + this.owner.animation.playIfNotAlready("DASH"); } else { - this.owner.animation.playIfNotAlready("WALK", true); + if (this.parent.invincible) { + this.owner.animation.playIfNotAlready("HURT"); + } + else { + this.owner.animation.playIfNotAlready("WALK", true); + } } - let dir = this.getInputDirection(); if(dir.isZero()){