fix: seperate charging state and attacking state

This commit is contained in:
Renge 2022-04-27 22:34:07 -04:00
parent 85ca8edf05
commit 3bf7704528
5 changed files with 12 additions and 4 deletions

View File

@ -63,6 +63,7 @@ export default class EnemyAI extends StateMachineAI implements BattlerAI {
bleedStat: Sprite; bleedStat: Sprite;
attackTimer : Timer; attackTimer : Timer;
isCharging: boolean = false;
isAttaking: boolean = false; isAttaking: boolean = false;
damageTimer: Timer; damageTimer: Timer;
@ -111,7 +112,7 @@ export default class EnemyAI extends StateMachineAI implements BattlerAI {
console.log(damage +" damage taken, "+this.CURRENT_HP+" hp left"); console.log(damage +" damage taken, "+this.CURRENT_HP+" hp left");
this.CURRENT_HP -= damage; this.CURRENT_HP -= damage;
//TODO - //TODO -
if (!this.isAttaking) { if (!this.isAttaking && !this.isCharging) {
this.owner.animation.play("HURT",false); this.owner.animation.play("HURT",false);
} }

View File

@ -9,7 +9,7 @@ export default class Attack extends EnemyState {
onEnter(options: Record<string, any>): void { onEnter(options: Record<string, any>): void {
this.parent.attackTimer.start(); this.parent.attackTimer.start();
this.parent.velocity.x = 0; this.parent.velocity.x = 0;
this.parent.isAttaking = true; this.parent.isCharging = true;
this.charged = this.owner.id+"charged"; this.charged = this.owner.id+"charged";
this.attacked = this.owner.id+"attacked"; this.attacked = this.owner.id+"attacked";
@ -20,11 +20,12 @@ export default class Attack extends EnemyState {
} }
update(deltaT: number): void { update(deltaT: number): void {
this.finished(EnemyStates.ALERT);
super.update(deltaT); super.update(deltaT);
} }
onExit(): Record<string, any> { onExit(): Record<string, any> {
this.parent.isAttaking = false; this.parent.isCharging = false;
(<AnimatedSprite>this.owner).animation.stop(); (<AnimatedSprite>this.owner).animation.stop();
return null; return null;
} }

View File

@ -27,7 +27,7 @@ export default abstract class EnemyState extends State {
} }
update(deltaT: number): void { 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; this.parent.velocity.x = 0;
} }
// Do gravity // Do gravity

View File

@ -10,10 +10,13 @@ export default class SnakeAttack extends Attack {
let event = this.receiver.getNextEvent().type; let event = this.receiver.getNextEvent().type;
switch (event) { switch (event) {
case this.charged: case this.charged:
this.parent.isCharging = false;
this.parent.isAttaking = true;
(<AnimatedSprite>this.owner).animation.play("ATTACK", false, this.attacked); (<AnimatedSprite>this.owner).animation.play("ATTACK", false, this.attacked);
(<AABB>this.owner.collisionShape).halfSize.x += 3.5; (<AABB>this.owner.collisionShape).halfSize.x += 3.5;
break; break;
case this.attacked: case this.attacked:
this.parent.isAttaking = false;
(<AABB>this.owner.collisionShape).halfSize.x -= 3.5; (<AABB>this.owner.collisionShape).halfSize.x -= 3.5;
this.finished(EnemyStates.ALERT); this.finished(EnemyStates.ALERT);
break; break;

View File

@ -22,12 +22,15 @@ export default class TigerAttack extends Attack {
let event = this.receiver.getNextEvent().type; let event = this.receiver.getNextEvent().type;
switch (event) { switch (event) {
case this.charged: case this.charged:
this.parent.isCharging = false;
this.parent.isAttaking = true;
(<AnimatedSprite>this.owner).animation.play("ATTACK", true); (<AnimatedSprite>this.owner).animation.play("ATTACK", true);
this.velocity = (this.parent.getPlayerPosition().x - this.owner.position.x)/2; this.velocity = (this.parent.getPlayerPosition().x - this.owner.position.x)/2;
this.parent.direction = this.velocity >= 0 ? 1 : 0; this.parent.direction = this.velocity >= 0 ? 1 : 0;
this.attacking = true; this.attacking = true;
break; break;
case this.attacked: case this.attacked:
this.parent.isAttaking = false;
this.finished(EnemyStates.ALERT); this.finished(EnemyStates.ALERT);
break; break;
} }