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;
|
attackTimer : Timer;
|
||||||
isAttaking: boolean = false;
|
isAttaking: boolean = false;
|
||||||
|
damageTimer: Timer;
|
||||||
|
|
||||||
|
|
||||||
initializeAI(owner: AnimatedSprite, options: Record<string, any>): void {
|
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.poisonTimer = new Timer(1000);
|
||||||
|
|
||||||
this.attackTimer = new Timer(2500);
|
this.attackTimer = new Timer(2500);
|
||||||
|
this.damageTimer = new Timer(400);
|
||||||
}
|
}
|
||||||
|
|
||||||
damage(damage: number): void {
|
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.emitter.fireEvent(Player_Events.ENEMY_KILLED, {owner: this.owner.id, ai:this});
|
||||||
}
|
}
|
||||||
|
this.damageTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
collideWithPlayer(player: PlayerController): void {
|
collideWithPlayer(player: PlayerController): void {
|
||||||
|
|
|
@ -27,6 +27,9 @@ export default abstract class EnemyState extends State {
|
||||||
}
|
}
|
||||||
|
|
||||||
update(deltaT: number): void {
|
update(deltaT: number): void {
|
||||||
|
if (!this.parent.damageTimer.isStopped()) {
|
||||||
|
this.parent.velocity.x = 0;
|
||||||
|
}
|
||||||
// Do gravity
|
// Do gravity
|
||||||
this.parent.velocity.y += this.gravity * deltaT;
|
this.parent.velocity.y += this.gravity * deltaT;
|
||||||
this.owner.move(this.parent.velocity.scaled(deltaT));
|
this.owner.move(this.parent.velocity.scaled(deltaT));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user