feat: implemented healthbar for enemies
This commit is contained in:
parent
10238c96df
commit
bee0a4264a
|
@ -25,6 +25,8 @@ import { Player_Events } from "../sword_enums";
|
||||||
import InputWrapper from "../Tools/InputWrapper";
|
import InputWrapper from "../Tools/InputWrapper";
|
||||||
import Timer from "../../Wolfie2D/Timing/Timer";
|
import Timer from "../../Wolfie2D/Timing/Timer";
|
||||||
import PlayerController from "../Player/PlayerController";
|
import PlayerController from "../Player/PlayerController";
|
||||||
|
import Rect from "../../Wolfie2D/Nodes/Graphics/Rect";
|
||||||
|
import Color from "../../Wolfie2D/Utils/Color";
|
||||||
export default class EnemyAI extends StateMachineGoapAI implements BattlerAI {
|
export default class EnemyAI extends StateMachineGoapAI implements BattlerAI {
|
||||||
/** The owner of this AI */
|
/** The owner of this AI */
|
||||||
owner: AnimatedSprite;
|
owner: AnimatedSprite;
|
||||||
|
@ -76,6 +78,8 @@ export default class EnemyAI extends StateMachineGoapAI implements BattlerAI {
|
||||||
bleedTimer : Timer;
|
bleedTimer : Timer;
|
||||||
bleedCounter :number = 0;
|
bleedCounter :number = 0;
|
||||||
|
|
||||||
|
healthBar: Rect;
|
||||||
|
|
||||||
|
|
||||||
initializeAI(owner: AnimatedSprite, options: Record<string, any>): void {
|
initializeAI(owner: AnimatedSprite, options: Record<string, any>): void {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
|
@ -146,6 +150,7 @@ export default class EnemyAI extends StateMachineGoapAI implements BattlerAI {
|
||||||
this.owner.setAIActive(false, {});
|
this.owner.setAIActive(false, {});
|
||||||
this.owner.isCollidable = false;
|
this.owner.isCollidable = false;
|
||||||
this.owner.visible = false;
|
this.owner.visible = false;
|
||||||
|
this.healthBar.destroy();
|
||||||
|
|
||||||
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});
|
||||||
|
|
||||||
|
@ -237,6 +242,18 @@ export default class EnemyAI extends StateMachineGoapAI implements BattlerAI {
|
||||||
this.bleedTimer.start();
|
this.bleedTimer.start();
|
||||||
this.damage(5 + (<PlayerController>this.player._ai).extraDotDmg + (<PlayerController>this.player._ai).CURRENT_ATK * .08);
|
this.damage(5 + (<PlayerController>this.player._ai).extraDotDmg + (<PlayerController>this.player._ai).CURRENT_ATK * .08);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.healthBar.position = this.owner.collisionShape.center.clone().add(new Vec2(0, -((<AABB>this.owner.collisionShape).hh+5)));
|
||||||
|
this.healthBar.fillWidth = this.CURRENT_HP/this.maxHealth * this.owner.collisionShape.hw * 3;
|
||||||
|
if (this.CURRENT_HP/this.maxHealth >= 2/3) {
|
||||||
|
this.healthBar.color = Color.GREEN;
|
||||||
|
}
|
||||||
|
else if (this.CURRENT_HP/this.maxHealth >= 1/3) {
|
||||||
|
this.healthBar.color = Color.YELLOW;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.healthBar.color = Color.RED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -739,6 +739,10 @@ export default class GameLevel extends Scene {
|
||||||
}
|
}
|
||||||
|
|
||||||
enemy.addAI(EnemyAI, aiOptions); //TODO - add individual enemy AI
|
enemy.addAI(EnemyAI, aiOptions); //TODO - add individual enemy AI
|
||||||
|
(<EnemyAI>enemy._ai).healthBar = <Rect>this.add.graphic(GraphicType.RECT, "primary", {position: enemy.collisionShape.center.clone().add(new Vec2(0, -((<AABB>enemy.collisionShape).hh+5))), size: new Vec2((<AABB>enemy.collisionShape).hw*3, 5)});
|
||||||
|
(<EnemyAI>enemy._ai).healthBar.borderColor = Color.BLACK;
|
||||||
|
(<EnemyAI>enemy._ai).healthBar.borderWidth = 1;
|
||||||
|
(<EnemyAI>enemy._ai).healthBar.color = Color.GREEN;
|
||||||
enemy.setGroup("Enemy");
|
enemy.setGroup("Enemy");
|
||||||
enemy.setTrigger("player", Player_Events.PLAYER_COLLIDE, null);
|
enemy.setTrigger("player", Player_Events.PLAYER_COLLIDE, null);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user