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;
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);
}

View File

@ -9,7 +9,7 @@ export default class Attack extends EnemyState {
onEnter(options: Record<string, any>): 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<string, any> {
this.parent.isAttaking = false;
this.parent.isCharging = false;
(<AnimatedSprite>this.owner).animation.stop();
return null;
}

View File

@ -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

View File

@ -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;
(<AnimatedSprite>this.owner).animation.play("ATTACK", false, this.attacked);
(<AABB>this.owner.collisionShape).halfSize.x += 3.5;
break;
case this.attacked:
this.parent.isAttaking = false;
(<AABB>this.owner.collisionShape).halfSize.x -= 3.5;
this.finished(EnemyStates.ALERT);
break;

View File

@ -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;
(<AnimatedSprite>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;
}