Tutorial 18.3 Player Stats with HP Label

This commit is contained in:
Alan Youngblood
2024-11-24 12:41:42 -05:00
parent 24bc047855
commit 7713127e27
4 changed files with 38 additions and 1 deletions

View File

@ -0,0 +1,19 @@
extends Control
var hearts = 4 setget set_hearts
var max_hearts = 4 setget set_max_hearts
onready var label = $Label
func set_hearts(value):
hearts = clamp(value, 0, max_hearts)
if label != null:
label.text = "HP = " + str(hearts)
func set_max_hearts(value):
max_hearts = max(value, 1)
func _ready():
self.max_hearts = PlayerStats.max_health
self.hearts = PlayerStats.health
PlayerStats.connect("health_changed", self, "set_hearts")

View File

@ -0,0 +1,13 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://UI/HealthUI.gd" type="Script" id=1]
[node name="HealthUI" type="Control"]
margin_right = 122.0
margin_bottom = 25.0
script = ExtResource( 1 )
[node name="Label" type="Label" parent="."]
margin_right = 42.0
margin_bottom = 14.0
text = "HP = 4"