Display Health Bar on player HUD

This commit is contained in:
Squinternator 2024-04-09 21:36:43 +00:00
parent 289cceddaf
commit 1994c1ce40
3 changed files with 30 additions and 6 deletions

View file

@ -150,4 +150,5 @@ root_path = NodePath(".")
replication_config = SubResource("SceneReplicationConfig_5j4ew")
script = SubResource("GDScript_uy24w")
[connection signal="health_changed" from="HealthComponent" to="HUD" method="_on_health_changed"]
[connection signal="health_zeroed" from="HealthComponent" to="." method="die"]

View file

@ -2,9 +2,13 @@ extends Area3D
class_name HealthComponent
@export var max_health : int = 100
@export var health : int
@export var health : int:
set(value):
health = value
health_changed.emit(value)
signal health_zeroed
signal health_changed
func _ready():
health = max_health

View file

@ -1,23 +1,30 @@
[gd_scene load_steps=5 format=3 uid="uid://bcv81ku26xo"]
[gd_scene load_steps=6 format=3 uid="uid://bcv81ku26xo"]
[sub_resource type="GDScript" id="GDScript_2vxif"]
script/source = "extends CanvasLayer
class_name HUD
@onready var health_bar = $HealthBar
@onready var energy_bar = $EnergyBar
func _update_energy_label(energy):
energy_bar.value = energy
func _ready():
_update_energy_label(100.0)
func _on_energy_changed(new_energy) -> void:
_update_energy_label(new_energy)
func _update_health_label(health):
health_bar.value = health
func _on_health_changed(new_health) -> void:
_update_health_label(new_health)
"
[sub_resource type="Theme" id="Theme_irfqb"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_8ju42"]
bg_color = Color(1, 0.356863, 0.145098, 1)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_f23s3"]
bg_color = Color(0, 0.454902, 0.992157, 1)
@ -41,7 +48,7 @@ func _process(_delta):
[node name="HUD" type="CanvasLayer"]
script = SubResource("GDScript_2vxif")
[node name="EnergyBar" type="ProgressBar" parent="."]
[node name="HealthBar" type="ProgressBar" parent="."]
offset_left = 32.0
offset_top = 32.0
offset_right = 288.0
@ -49,6 +56,18 @@ offset_bottom = 40.0
size_flags_horizontal = 0
mouse_filter = 2
theme = SubResource("Theme_irfqb")
theme_override_styles/fill = SubResource("StyleBoxFlat_8ju42")
value = 60.0
show_percentage = false
[node name="EnergyBar" type="ProgressBar" parent="."]
offset_left = 32.0
offset_top = 48.0
offset_right = 288.0
offset_bottom = 56.0
size_flags_horizontal = 0
mouse_filter = 2
theme = SubResource("Theme_irfqb")
theme_override_styles/fill = SubResource("StyleBoxFlat_f23s3")
value = 60.0
show_percentage = false