feat: 添加玩家和敌人血条

This commit is contained in:
luke358
2026-05-18 15:46:44 +08:00
parent 2060719f4e
commit b6bf8ef5ba
12 changed files with 180 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
extends Control
class_name HealthBar
@export var back_color: Color
@export var fill_color: Color
@onready var progress_bar: ProgressBar = $ProgressBar
@onready var health_amount: Label = $HealthAmount
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
var back_style := progress_bar.get_theme_stylebox("background").duplicate()
back_style.bg_color = back_color
var fill_style := progress_bar.get_theme_stylebox("fill").duplicate()
fill_style.bg_color = fill_color
progress_bar.add_theme_stylebox_override("background", back_style)
progress_bar.add_theme_stylebox_override("fill", fill_style)
func update_bar(value: float, health: float) -> void:
progress_bar.value = value
health_amount.text = str(health)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _on_health_component_on_health_changed(current: float, max: float) -> void:
var value = current / max
update_bar(value, current)