more work on the ui theme and changing the hud
This commit is contained in:
28
UI/EnemyHealthBar/health_bar.gd
Normal file
28
UI/EnemyHealthBar/health_bar.gd
Normal file
@@ -0,0 +1,28 @@
|
||||
class_name HealthBar
|
||||
extends TextureProgressBar
|
||||
|
||||
@export var health_bar_gradient: Gradient
|
||||
|
||||
@onready var prev_bar: TextureProgressBar = $PreviousHealthBar
|
||||
|
||||
|
||||
func setup(health: float) -> void:
|
||||
max_value = health
|
||||
value = health
|
||||
prev_bar.max_value = health
|
||||
prev_bar.value = health
|
||||
|
||||
|
||||
func on_health_changed(health: float) -> void:
|
||||
set_visible(true)
|
||||
var health_went_down: bool = true if health < value else false
|
||||
value = health
|
||||
tint_progress = health_bar_gradient.sample(value / max_value)
|
||||
if health_went_down:
|
||||
var tween: Tween = create_tween()
|
||||
tween.set_ease(Tween.EASE_OUT)
|
||||
tween.set_trans(Tween.TRANS_QUINT)
|
||||
tween.tween_interval(0.3)
|
||||
tween.tween_property(prev_bar, "value", value, 0.7)
|
||||
else:
|
||||
prev_bar.value = value
|
||||
1
UI/EnemyHealthBar/health_bar.gd.uid
Normal file
1
UI/EnemyHealthBar/health_bar.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bf06es50d0flv
|
||||
30
UI/EnemyHealthBar/health_bar.tscn
Normal file
30
UI/EnemyHealthBar/health_bar.tscn
Normal file
@@ -0,0 +1,30 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://hjq3nrnumklp"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://r202vo47jw1q" path="res://Assets/Textures/enemyhealth.png" id="1_x8m88"]
|
||||
[ext_resource type="Script" uid="uid://bf06es50d0flv" path="res://UI/EnemyHealthBar/health_bar.gd" id="2_m8c1f"]
|
||||
[ext_resource type="Gradient" uid="uid://dx7auy3oqw82t" path="res://UI/EnemyHealthBar/health_bar_gradient.tres" id="3_dpmma"]
|
||||
|
||||
[node name="HealthBar" type="TextureProgressBar"]
|
||||
offset_right = 200.0
|
||||
offset_bottom = 200.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
step = 0.0
|
||||
value = 100.0
|
||||
fill_mode = 6
|
||||
texture_progress = ExtResource("1_x8m88")
|
||||
tint_progress = Color(0, 1, 0, 1)
|
||||
script = ExtResource("2_m8c1f")
|
||||
health_bar_gradient = ExtResource("3_dpmma")
|
||||
|
||||
[node name="PreviousHealthBar" type="TextureProgressBar" parent="."]
|
||||
z_index = -1
|
||||
layout_mode = 0
|
||||
offset_right = 200.0
|
||||
offset_bottom = 200.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
step = 0.0
|
||||
value = 100.0
|
||||
fill_mode = 6
|
||||
texture_progress = ExtResource("1_x8m88")
|
||||
6
UI/EnemyHealthBar/health_bar_gradient.tres
Normal file
6
UI/EnemyHealthBar/health_bar_gradient.tres
Normal file
@@ -0,0 +1,6 @@
|
||||
[gd_resource type="Gradient" format=3 uid="uid://dx7auy3oqw82t"]
|
||||
|
||||
[resource]
|
||||
interpolation_color_space = 2
|
||||
offsets = PackedFloat32Array(0, 0.131148, 0.357143, 0.758242, 1)
|
||||
colors = PackedColorArray(0.788235, 0, 0, 1, 0.818896, 0.282651, 0.000353087, 1, 0.945098, 1, 0, 1, 0.259747, 0.912524, 6.85382e-05, 1, 0, 0.917647, 0, 1)
|
||||
Reference in New Issue
Block a user