Added health bars

This commit is contained in:
2024-02-13 00:22:27 +01:00
parent ba978049a5
commit 6727be5cd0
23 changed files with 154 additions and 41 deletions

View File

@ -0,0 +1,14 @@
class_name HUDComponent
extends Sprite3D
@export var health: HealthComponent
func _ready():
texture = $SubViewport.get_texture()
update_name(owner.name)
if owner.has_signal("name_changed"):
owner.name_changed.connect(update_name)
func update_name(new_name: String):
%Label.text = new_name

View File

@ -0,0 +1,44 @@
[gd_scene load_steps=7 format=3 uid="uid://6jpnl6c4fdvo"]
[ext_resource type="Script" path="res://player/hud/HUDComponent.gd" id="1_vynft"]
[ext_resource type="Texture2D" uid="uid://d2rig4p2dfy30" path="res://assets/ui/bar-green.png" id="2_ad7qf"]
[ext_resource type="Script" path="res://player/hud/HealthBar.gd" id="3_61bgt"]
[ext_resource type="Texture2D" uid="uid://deopmcycal0aq" path="res://assets/ui/bar-yellow.png" id="4_5dl20"]
[ext_resource type="Texture2D" uid="uid://cjg6cgv6hvnd" path="res://assets/ui/bar-red.png" id="5_3x8xp"]
[sub_resource type="LabelSettings" id="LabelSettings_y8qrs"]
font_size = 32
shadow_color = Color(0, 0, 0, 1)
[node name="HUD" type="Sprite3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.83994, 0)
pixel_size = 0.003
billboard = 1
region_rect = Rect2(0, 0, 84, 26)
script = ExtResource("1_vynft")
[node name="SubViewport" type="SubViewport" parent="."]
disable_3d = true
transparent_bg = true
size = Vector2i(200, 70)
[node name="VBoxContainer" type="VBoxContainer" parent="SubViewport"]
offset_right = 40.0
offset_bottom = 40.0
[node name="Label" type="Label" parent="SubViewport/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
label_settings = SubResource("LabelSettings_y8qrs")
uppercase = true
[node name="HealthBar" type="TextureProgressBar" parent="SubViewport/VBoxContainer"]
layout_mode = 2
max_value = 1.0
step = 0.0
value = 1.0
texture_progress = ExtResource("2_ad7qf")
script = ExtResource("3_61bgt")
high = ExtResource("2_ad7qf")
medium = ExtResource("4_5dl20")
low = ExtResource("5_3x8xp")

View File

@ -0,0 +1,21 @@
extends TextureProgressBar
@export var high: Texture2D
@export var medium: Texture2D
@export var low: Texture2D
var health: HealthComponent
func _ready():
health = owner.health
health.value_changed.connect(on_health_changed)
func on_health_changed():
value = health.value / health.max_value
if value < 0.45:
texture_progress = low
elif value < 0.75:
texture_progress = medium
else:
texture_progress = high