feat: add damage timer to stop enemy when it takes damage

This commit is contained in:
Renge 2022-04-24 23:25:57 -04:00
parent 17f4b00488
commit 1d73a39bad
2 changed files with 6 additions and 0 deletions

View File

@ -64,6 +64,7 @@ export default class EnemyAI extends StateMachineAI implements BattlerAI {
attackTimer : Timer;
isAttaking: boolean = false;
damageTimer: Timer;
initializeAI(owner: AnimatedSprite, options: Record<string, any>): void {
@ -96,6 +97,7 @@ export default class EnemyAI extends StateMachineAI implements BattlerAI {
this.poisonTimer = new Timer(1000);
this.attackTimer = new Timer(2500);
this.damageTimer = new Timer(400);
}
damage(damage: number): void {
@ -136,6 +138,7 @@ export default class EnemyAI extends StateMachineAI implements BattlerAI {
this.emitter.fireEvent(Player_Events.ENEMY_KILLED, {owner: this.owner.id, ai:this});
}
this.damageTimer.start();
}
collideWithPlayer(player: PlayerController): void {

View File

@ -27,6 +27,9 @@ export default abstract class EnemyState extends State {
}
update(deltaT: number): void {
if (!this.parent.damageTimer.isStopped()) {
this.parent.velocity.x = 0;
}
// Do gravity
this.parent.velocity.y += this.gravity * deltaT;
this.owner.move(this.parent.velocity.scaled(deltaT));