summaryrefslogtreecommitdiff
path: root/src/entities/hp_bar.js
diff options
context:
space:
mode:
authorniliara-edu <nil.jimeno@estudiant.fjaverianas.com>2024-12-24 17:58:20 +0100
committerniliara-edu <nil.jimeno@estudiant.fjaverianas.com>2024-12-24 17:58:20 +0100
commit25adfc618e77db9a5ee3b98ce0dab0be832efed0 (patch)
tree36ca56758ddd4674ab5a43df4b76bbfcc5a47af1 /src/entities/hp_bar.js
parenta840990bdcabf45fb0d377478ba0ab27222434ae (diff)
hello kitty base done
Diffstat (limited to 'src/entities/hp_bar.js')
-rw-r--r--src/entities/hp_bar.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/entities/hp_bar.js b/src/entities/hp_bar.js
new file mode 100644
index 0000000..d6e68bb
--- /dev/null
+++ b/src/entities/hp_bar.js
@@ -0,0 +1,32 @@
+import { WHITE } from "../assets.js"
+import { Vector } from "../engine/vector.js"
+import { Engine } from "../engine.js"
+import { Entity } from "./entity.js"
+import { enemy } from "../main.js"
+
+export class HPBar extends Entity {
+ constructor() {
+ let size = new Vector(Engine.screen.viewport.x, 20)
+ super({
+ size: new Vector(Engine.screen.viewport.x, 20),
+ position: new Vector(size.x / 2, size.y / 2),
+ sprite: WHITE,
+ pixelated: true,
+ })
+
+ this.lasthp = enemy.hp
+ }
+
+ update() {
+ if (enemy.hp != this.lasthp) {
+ this.lasthp = enemy.hp
+
+ let hpScale = enemy.hp / enemy.max_hp
+ let viewport = Engine.screen.viewport
+
+ this.size.x = hpScale * viewport.x
+ this.position.x = (viewport.x / 2) - (1 - hpScale) / 2 * viewport.x
+ }
+ }
+}
+