From 3bf7704528598296ff43f9b6d3b7f90611a25c4d Mon Sep 17 00:00:00 2001 From: Renge Date: Wed, 27 Apr 2022 22:34:07 -0400 Subject: [PATCH] fix: seperate charging state and attacking state --- src/shattered_sword/AI/EnemyAI.ts | 3 ++- src/shattered_sword/AI/EnemyStates/Attack.ts | 5 +++-- src/shattered_sword/AI/EnemyStates/EnemyState.ts | 2 +- src/shattered_sword/AI/EnemyStates/SnakeAttack.ts | 3 +++ src/shattered_sword/AI/EnemyStates/TigerAttack.ts | 3 +++ 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/shattered_sword/AI/EnemyAI.ts b/src/shattered_sword/AI/EnemyAI.ts index 37c80c3..59ebf85 100644 --- a/src/shattered_sword/AI/EnemyAI.ts +++ b/src/shattered_sword/AI/EnemyAI.ts @@ -63,6 +63,7 @@ export default class EnemyAI extends StateMachineAI implements BattlerAI { bleedStat: Sprite; attackTimer : Timer; + isCharging: boolean = false; isAttaking: boolean = false; damageTimer: Timer; @@ -111,7 +112,7 @@ export default class EnemyAI extends StateMachineAI implements BattlerAI { console.log(damage +" damage taken, "+this.CURRENT_HP+" hp left"); this.CURRENT_HP -= damage; //TODO - - if (!this.isAttaking) { + if (!this.isAttaking && !this.isCharging) { this.owner.animation.play("HURT",false); } diff --git a/src/shattered_sword/AI/EnemyStates/Attack.ts b/src/shattered_sword/AI/EnemyStates/Attack.ts index fa6687d..a9d22f2 100644 --- a/src/shattered_sword/AI/EnemyStates/Attack.ts +++ b/src/shattered_sword/AI/EnemyStates/Attack.ts @@ -9,7 +9,7 @@ export default class Attack extends EnemyState { onEnter(options: Record): void { this.parent.attackTimer.start(); this.parent.velocity.x = 0; - this.parent.isAttaking = true; + this.parent.isCharging = true; this.charged = this.owner.id+"charged"; this.attacked = this.owner.id+"attacked"; @@ -20,11 +20,12 @@ export default class Attack extends EnemyState { } update(deltaT: number): void { + this.finished(EnemyStates.ALERT); super.update(deltaT); } onExit(): Record { - this.parent.isAttaking = false; + this.parent.isCharging = false; (this.owner).animation.stop(); return null; } diff --git a/src/shattered_sword/AI/EnemyStates/EnemyState.ts b/src/shattered_sword/AI/EnemyStates/EnemyState.ts index 064a274..5c77dcb 100644 --- a/src/shattered_sword/AI/EnemyStates/EnemyState.ts +++ b/src/shattered_sword/AI/EnemyStates/EnemyState.ts @@ -27,7 +27,7 @@ export default abstract class EnemyState extends State { } update(deltaT: number): void { - if (!this.parent.damageTimer.isStopped() && !this.parent.isAttaking) { + if (!this.parent.damageTimer.isStopped() && !this.parent.isAttaking && !this.parent.isCharging) { this.parent.velocity.x = 0; } // Do gravity diff --git a/src/shattered_sword/AI/EnemyStates/SnakeAttack.ts b/src/shattered_sword/AI/EnemyStates/SnakeAttack.ts index bd822e5..61bc090 100644 --- a/src/shattered_sword/AI/EnemyStates/SnakeAttack.ts +++ b/src/shattered_sword/AI/EnemyStates/SnakeAttack.ts @@ -10,10 +10,13 @@ export default class SnakeAttack extends Attack { let event = this.receiver.getNextEvent().type; switch (event) { case this.charged: + this.parent.isCharging = false; + this.parent.isAttaking = true; (this.owner).animation.play("ATTACK", false, this.attacked); (this.owner.collisionShape).halfSize.x += 3.5; break; case this.attacked: + this.parent.isAttaking = false; (this.owner.collisionShape).halfSize.x -= 3.5; this.finished(EnemyStates.ALERT); break; diff --git a/src/shattered_sword/AI/EnemyStates/TigerAttack.ts b/src/shattered_sword/AI/EnemyStates/TigerAttack.ts index d44d6f4..e580307 100644 --- a/src/shattered_sword/AI/EnemyStates/TigerAttack.ts +++ b/src/shattered_sword/AI/EnemyStates/TigerAttack.ts @@ -22,12 +22,15 @@ export default class TigerAttack extends Attack { let event = this.receiver.getNextEvent().type; switch (event) { case this.charged: + this.parent.isCharging = false; + this.parent.isAttaking = true; (this.owner).animation.play("ATTACK", true); this.velocity = (this.parent.getPlayerPosition().x - this.owner.position.x)/2; this.parent.direction = this.velocity >= 0 ? 1 : 0; this.attacking = true; break; case this.attacked: + this.parent.isAttaking = false; this.finished(EnemyStates.ALERT); break; }