Tut18 Complete; hearts, shadows, etc.

This commit is contained in:
Alan Youngblood
2024-11-26 09:23:20 -05:00
parent 7713127e27
commit 54f9772836
9 changed files with 80 additions and 16 deletions

View File

@ -3,17 +3,22 @@ extends Control
var hearts = 4 setget set_hearts
var max_hearts = 4 setget set_max_hearts
onready var label = $Label
onready var heartUIFull = $HeartUIFull
onready var heartUIEmpty = $HeartUIEmpty
func set_hearts(value):
hearts = clamp(value, 0, max_hearts)
if label != null:
label.text = "HP = " + str(hearts)
if heartUIFull != null:
heartUIFull.rect_size.x = hearts * 15
func set_max_hearts(value):
max_hearts = max(value, 1)
self.hearts = min(hearts, max_hearts)
if heartUIEmpty != null:
heartUIEmpty.rect_size.x = max_hearts * 15
func _ready():
self.max_hearts = PlayerStats.max_health
self.hearts = PlayerStats.health
PlayerStats.connect("health_changed", self, "set_hearts")
PlayerStats.connect("max_health_changed", self, "set_max_hearts")

View File

@ -1,13 +1,25 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=4 format=2]
[ext_resource path="res://UI/HealthUI.gd" type="Script" id=1]
[ext_resource path="res://UI/HeartUIEmpty.png" type="Texture" id=2]
[ext_resource path="res://UI/HeartUIFull.png" type="Texture" id=3]
[node name="HealthUI" type="Control"]
margin_right = 122.0
margin_bottom = 25.0
margin_left = 2.0
margin_top = 2.0
margin_right = 124.0
margin_bottom = 27.0
script = ExtResource( 1 )
[node name="Label" type="Label" parent="."]
margin_right = 42.0
margin_bottom = 14.0
text = "HP = 4"
[node name="HeartUIEmpty" type="TextureRect" parent="."]
margin_right = 59.0
margin_bottom = 12.0
texture = ExtResource( 2 )
stretch_mode = 2
[node name="HeartUIFull" type="TextureRect" parent="."]
margin_right = 60.0
margin_bottom = 11.0
texture = ExtResource( 3 )
expand = true
stretch_mode = 2