summaryrefslogtreecommitdiff
path: root/components/healthbar
diff options
context:
space:
mode:
authorJonas Bernard <public.jbernard@web.de>2021-04-24 22:00:16 +0200
committerJonas Bernard <public.jbernard@web.de>2021-04-24 22:00:16 +0200
commita6d55f5145d1aa05c4b05fc4e9f980643dfbeefd (patch)
tree4e5482f769268ca48f4f019a3d3888d0893cc1d1 /components/healthbar
parent5d74b160790f35f201f2dd1876b84201a8be9534 (diff)
downloadldjam48-a6d55f5145d1aa05c4b05fc4e9f980643dfbeefd.tar.gz
ldjam48-a6d55f5145d1aa05c4b05fc4e9f980643dfbeefd.tar.bz2
ldjam48-a6d55f5145d1aa05c4b05fc4e9f980643dfbeefd.zip
healthbar
Diffstat (limited to 'components/healthbar')
-rw-r--r--components/healthbar/healtbar.gd25
-rw-r--r--components/healthbar/healtbar.tscn7
-rw-r--r--components/healthbar/heart.gd22
-rw-r--r--components/healthbar/heart.tscn14
4 files changed, 68 insertions, 0 deletions
diff --git a/components/healthbar/healtbar.gd b/components/healthbar/healtbar.gd
new file mode 100644
index 0000000..ee9915f
--- /dev/null
+++ b/components/healthbar/healtbar.gd
@@ -0,0 +1,25 @@
+extends Node2D
+
+export var maxhealth = 3
+export var offset = 40
+
+var h: PackedScene = preload("res://components/healthbar/heart.tscn")
+var hearts: Array = []
+
+
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+ for i in maxhealth:
+ var heart = h.instance()
+ hearts.append(heart)
+ heart.position = Vector2(i * offset, 0)
+ add_child(heart)
+
+
+func _process(delta):
+ pass
+
+func set_health(health: int=maxhealth):
+ for i in maxhealth:
+ hearts[i].set_filled(i < health)
diff --git a/components/healthbar/healtbar.tscn b/components/healthbar/healtbar.tscn
new file mode 100644
index 0000000..e7cf26c
--- /dev/null
+++ b/components/healthbar/healtbar.tscn
@@ -0,0 +1,7 @@
+[gd_scene load_steps=2 format=2]
+
+[ext_resource path="res://components/healthbar/healtbar.gd" type="Script" id=2]
+
+[node name="Node2D" type="Node2D"]
+script = ExtResource( 2 )
+maxhealth = 8
diff --git a/components/healthbar/heart.gd b/components/healthbar/heart.gd
new file mode 100644
index 0000000..6177452
--- /dev/null
+++ b/components/healthbar/heart.gd
@@ -0,0 +1,22 @@
+extends Node2D
+
+
+onready var fill = $fill
+onready var notfill = $notfill
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+ pass # Replace with function body.
+
+
+func _process(delta):
+ pass
+
+func set_filled(filled: bool):
+ if filled:
+ fill.visible = true
+ notfill.visible = false
+ else:
+ notfill.visible = true
+ fill.visible = false
+
diff --git a/components/healthbar/heart.tscn b/components/healthbar/heart.tscn
new file mode 100644
index 0000000..b4b14e5
--- /dev/null
+++ b/components/healthbar/heart.tscn
@@ -0,0 +1,14 @@
+[gd_scene load_steps=4 format=2]
+
+[ext_resource path="res://textures/icons/heart_fill.png" type="Texture" id=1]
+[ext_resource path="res://components/healthbar/heart.gd" type="Script" id=2]
+[ext_resource path="res://textures/icons/heart.png" type="Texture" id=3]
+
+[node name="Node2D" type="Node2D"]
+script = ExtResource( 2 )
+
+[node name="fill" type="Sprite" parent="."]
+texture = ExtResource( 1 )
+
+[node name="notfill" type="Sprite" parent="."]
+texture = ExtResource( 3 )