From abebaf2615f24dacd3cc10eed517dd900f2ca630 Mon Sep 17 00:00:00 2001 From: Renge Date: Wed, 20 Apr 2022 13:53:55 -0400 Subject: [PATCH 1/2] fix: hurt animation --- .../spritesheets/Hiro.json | 56 ++++++++++++++++++- .../spritesheets/Hiro.json | 54 +++++++++++++++++- src/shattered_sword/AI/EnemyAI.ts | 2 +- .../Player/PlayerController.ts | 4 +- .../Player/PlayerStates/Fall.ts | 13 +++-- .../Player/PlayerStates/Idle.ts | 8 ++- .../Player/PlayerStates/Jump.ts | 9 ++- .../Player/PlayerStates/OnGround.ts | 4 +- .../Player/PlayerStates/Walk.ts | 9 ++- 9 files changed, 140 insertions(+), 19 deletions(-) diff --git a/dist/shattered_sword_assets/spritesheets/Hiro.json b/dist/shattered_sword_assets/spritesheets/Hiro.json index bc3ec3f..28bfc5a 100644 --- a/dist/shattered_sword_assets/spritesheets/Hiro.json +++ b/dist/shattered_sword_assets/spritesheets/Hiro.json @@ -210,13 +210,65 @@ "name": "HURT", "repeat": false, "frames": [ + { + "index": 39, + "duration": 5 + }, { "index": 0, - "duration": 500 + "duration": 5 }, { "index": 39, - "duration": 500 + "duration": 5 + }, + { + "index": 0, + "duration": 5 + }, + { + "index": 39, + "duration": 5 + }, + { + "index": 0, + "duration": 5 + }, + { + "index": 39, + "duration": 5 + }, + { + "index": 0, + "duration": 5 + }, + { + "index": 39, + "duration": 5 + }, + { + "index": 0, + "duration": 5 + }, + { + "index": 39, + "duration": 5 + }, + { + "index": 0, + "duration": 5 + }, + { + "index": 39, + "duration": 5 + }, + { + "index": 0, + "duration": 5 + }, + { + "index": 39, + "duration": 5 } ] }, diff --git a/public/shattered_sword_assets/spritesheets/Hiro.json b/public/shattered_sword_assets/spritesheets/Hiro.json index 009acfd..b7c4b4c 100644 --- a/public/shattered_sword_assets/spritesheets/Hiro.json +++ b/public/shattered_sword_assets/spritesheets/Hiro.json @@ -200,15 +200,63 @@ }, { "name": "HURT", - "repeat": true, + "repeat": false, "frames": [ { "index": 0, - "duration": 50 + "duration": 5 }, { "index": 39, - "duration": 50 + "duration": 5 + }, + { + "index": 0, + "duration": 5 + }, + { + "index": 39, + "duration": 5 + }, + { + "index": 0, + "duration": 5 + }, + { + "index": 39, + "duration": 5 + }, + { + "index": 0, + "duration": 5 + }, + { + "index": 39, + "duration": 5 + }, + { + "index": 0, + "duration": 5 + }, + { + "index": 39, + "duration": 5 + }, + { + "index": 0, + "duration": 5 + }, + { + "index": 39, + "duration": 5 + }, + { + "index": 0, + "duration": 5 + }, + { + "index": 39, + "duration": 5 } ] }, diff --git a/src/shattered_sword/AI/EnemyAI.ts b/src/shattered_sword/AI/EnemyAI.ts index 6c28696..ad8bf27 100644 --- a/src/shattered_sword/AI/EnemyAI.ts +++ b/src/shattered_sword/AI/EnemyAI.ts @@ -112,10 +112,10 @@ export default class EnemyAI extends StateMachineGoapAI implements BattlerAI { activate(options: Record): void { } damage(damage: number): void { + console.log(damage +" damage taken, "+this.CURRENT_HP+" hp left"); this.CURRENT_HP -= damage; //TODO - this.owner.animation.play("HURT",false); - console.log(damage +" damage taken, "+this.CURRENT_HP+" hp left"); // If we're low enough, add Low Health status to enemy if (this.CURRENT_HP <= Math.floor(this.maxHealth/2)) { diff --git a/src/shattered_sword/Player/PlayerController.ts b/src/shattered_sword/Player/PlayerController.ts index 63de062..3fbe227 100644 --- a/src/shattered_sword/Player/PlayerController.ts +++ b/src/shattered_sword/Player/PlayerController.ts @@ -121,8 +121,8 @@ export default class PlayerController extends StateMachineAI implements BattlerA this.CURRENT_SHIELD = newshield; //update shield value } else{ - //console.log("hurt anim"); - (this.owner).animation.play("HURT" ); + console.log("hurt anim"); + (this.owner).animation.play("HURT", false); this.CURRENT_HP -= damage; if(this.CURRENT_HP <= 0){ (this.owner).animation.play("DYING"); diff --git a/src/shattered_sword/Player/PlayerStates/Fall.ts b/src/shattered_sword/Player/PlayerStates/Fall.ts index 5c9f0a4..c4a16fc 100644 --- a/src/shattered_sword/Player/PlayerStates/Fall.ts +++ b/src/shattered_sword/Player/PlayerStates/Fall.ts @@ -7,20 +7,25 @@ export default class Fall extends InAir { owner: AnimatedSprite; onEnter(options: Record): void { - this.owner.animation.play("FALL", true); + // this.owner.animation.play("FALL", true); } update(deltaT: number): void { - super.update(deltaT); - + 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 if( this.parent.airjumps>0 && InputWrapper.isJumpJustPressed()){ this.parent.airjumps --; this.finished("jump"); this.parent.velocity.y = -600; // basically jump height - } + + super.update(deltaT); } onExit(): Record { this.owner.animation.stop(); diff --git a/src/shattered_sword/Player/PlayerStates/Idle.ts b/src/shattered_sword/Player/PlayerStates/Idle.ts index e924742..fe23ed3 100644 --- a/src/shattered_sword/Player/PlayerStates/Idle.ts +++ b/src/shattered_sword/Player/PlayerStates/Idle.ts @@ -11,9 +11,13 @@ export default class Idle extends OnGround { update(deltaT: number): void { - + if (this.parent.invincible) { + this.owner.animation.playIfNotAlready("HURT"); + } + else { + this.owner.animation.playIfNotAlready("IDLE", true); + } - 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 a758272..dcabfbe 100644 --- a/src/shattered_sword/Player/PlayerStates/Jump.ts +++ b/src/shattered_sword/Player/PlayerStates/Jump.ts @@ -17,9 +17,13 @@ export default class Jump extends InAir { update(deltaT: number): void { - super.update(deltaT); + if (this.parent.invincible) { + this.owner.animation.playIfNotAlready("HURT"); + } + else { + this.owner.animation.playIfNotAlready("JUMP", true); + } - this.owner.animation.play("JUMP", true); if(this.owner.onCeiling){ this.parent.velocity.y = 0; @@ -38,6 +42,7 @@ export default class Jump extends InAir { if(this.parent.velocity.y >= 0){ this.finished(PlayerStates.FALL); } + super.update(deltaT); } onExit(): Record { diff --git a/src/shattered_sword/Player/PlayerStates/OnGround.ts b/src/shattered_sword/Player/PlayerStates/OnGround.ts index f7c892e..4e5a8e8 100644 --- a/src/shattered_sword/Player/PlayerStates/OnGround.ts +++ b/src/shattered_sword/Player/PlayerStates/OnGround.ts @@ -1,6 +1,8 @@ import GameEvent from "../../../Wolfie2D/Events/GameEvent"; +import Game from "../../../Wolfie2D/Loop/Game"; import Sprite from "../../../Wolfie2D/Nodes/Sprites/Sprite"; import MathUtils from "../../../Wolfie2D/Utils/MathUtils"; +import { GameState } from "../../sword_enums"; import InputWrapper from "../../Tools/InputWrapper"; import PlayerState from "./PlayerState"; @@ -31,7 +33,7 @@ export default class OnGround extends PlayerState { this.parent.velocity.y = -600; // basically jump height } - else if(!this.owner.onGround){ + else if(!this.owner.onGround && InputWrapper.getState() === GameState.GAMING){ this.finished("fall"); } super.update(deltaT); diff --git a/src/shattered_sword/Player/PlayerStates/Walk.ts b/src/shattered_sword/Player/PlayerStates/Walk.ts index af79454..09c1e50 100644 --- a/src/shattered_sword/Player/PlayerStates/Walk.ts +++ b/src/shattered_sword/Player/PlayerStates/Walk.ts @@ -9,12 +9,17 @@ export default class Walk extends OnGround { onEnter(options: Record): void { this.parent.speed = this.parent.MIN_SPEED; + } update(deltaT: number): void { - console.log("walking anim"); - 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(); From 3e40298d4cfb434028d89bdb76bdc66e2570bcf1 Mon Sep 17 00:00:00 2001 From: Renge Date: Wed, 20 Apr 2022 13:57:11 -0400 Subject: [PATCH 2/2] feat: add invincibility to dash --- src/shattered_sword/Player/PlayerController.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/shattered_sword/Player/PlayerController.ts b/src/shattered_sword/Player/PlayerController.ts index 3fbe227..788cb00 100644 --- a/src/shattered_sword/Player/PlayerController.ts +++ b/src/shattered_sword/Player/PlayerController.ts @@ -19,6 +19,7 @@ import AnimatedSprite from "../../Wolfie2D/Nodes/Sprites/AnimatedSprite"; import InputWrapper from "../Tools/InputWrapper"; import EnemyAI from "../AI/EnemyAI"; import Timer from "../../Wolfie2D/Timing/Timer"; +import PlayerState from "./PlayerStates/PlayerState"; export enum PlayerType { @@ -108,7 +109,7 @@ export default class PlayerController extends StateMachineAI implements BattlerA if (this.godMode) { return; } - if( !this.invincible){ + if( !this.invincible && !PlayerState.dashTimer.isStopped()){ //i frame here PlayerController.invincibilityTimer.start(); this.invincible = true;