feat: add damage timer to stop enemy when it takes damage
This commit is contained in:
parent
17f4b00488
commit
1d73a39bad
|
@ -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 {
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue
Block a user