From 85ca8edf0576a10ea2795d114d2fe1b7cc0a7990 Mon Sep 17 00:00:00 2001 From: Renge Date: Wed, 27 Apr 2022 22:16:03 -0400 Subject: [PATCH] fix: healthbar out of bound --- src/shattered_sword/AI/EnemyAI.ts | 9 ++++++--- src/shattered_sword/Scenes/GameLevel.ts | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/shattered_sword/AI/EnemyAI.ts b/src/shattered_sword/AI/EnemyAI.ts index 4050bfb..37c80c3 100644 --- a/src/shattered_sword/AI/EnemyAI.ts +++ b/src/shattered_sword/AI/EnemyAI.ts @@ -66,6 +66,9 @@ export default class EnemyAI extends StateMachineAI implements BattlerAI { isAttaking: boolean = false; damageTimer: Timer; + physicWidth: number; + physicHeight: number; + initializeAI(owner: AnimatedSprite, options: Record): void { this.owner = owner; @@ -231,8 +234,8 @@ export default class EnemyAI extends StateMachineAI implements BattlerAI { } if (this.healthBar) { - this.healthBar.position = this.owner.collisionShape.center.clone().add(new Vec2(0, -((this.owner.collisionShape).hh+5))); - this.healthBar.fillWidth = this.CURRENT_HP/this.maxHealth * this.owner.collisionShape.hw * 3; + this.healthBar.position = this.owner.collisionShape.center.clone().add(new Vec2(0, -(this.physicHeight+5))); + this.healthBar.fillWidth = this.CURRENT_HP/this.maxHealth * this.physicWidth * 3; if (this.CURRENT_HP/this.maxHealth >= 2/3) { this.healthBar.color = Color.GREEN; } @@ -244,7 +247,7 @@ export default class EnemyAI extends StateMachineAI implements BattlerAI { } } if (this.poisonStat) { - this.poisonStat.position = this.owner.collisionShape.center.clone().add(new Vec2(-((this.owner.collisionShape).hw)*1.5+10, -((this.owner.collisionShape).hh+15))); + this.poisonStat.position = this.owner.collisionShape.center.clone().add(new Vec2(-(this.physicWidth)*1.5+10, -(this.physicHeight+15))); this.poisonStat.visible = this.poisonCounter > 0; } if (this.burnStat) { diff --git a/src/shattered_sword/Scenes/GameLevel.ts b/src/shattered_sword/Scenes/GameLevel.ts index de10d02..3ee05fc 100644 --- a/src/shattered_sword/Scenes/GameLevel.ts +++ b/src/shattered_sword/Scenes/GameLevel.ts @@ -838,6 +838,8 @@ export default class GameLevel extends Scene { (enemy._ai).bleedStat = this.add.sprite("bleeding", "primary"); (enemy._ai).bleedStat.position = (enemy._ai).poisonStat.position.clone().add(new Vec2(30, 0)); (enemy._ai).bleedStat.scale.set(1, 1); + (enemy._ai).physicWidth = enemy.collisionShape.hw; + (enemy._ai).physicHeight = enemy.collisionShape.hh; enemy.setGroup("Enemy"); enemy.setTrigger("player", Player_Events.PLAYER_COLLIDE, null);