feat: 添加玩家和敌人血条
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://b3hyy3co71rtf
|
||||
@@ -0,0 +1,53 @@
|
||||
[gd_scene format=3 uid="uid://ifmw1e7gycc8"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b3hyy3co71rtf" path="res://scenes/ui/health_bar/health_bar.gd" id="1_ruhgv"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ilash"]
|
||||
bg_color = Color(0.13725491, 0.019607844, 0.02745098, 1)
|
||||
corner_radius_top_left = 8
|
||||
corner_radius_top_right = 8
|
||||
corner_radius_bottom_right = 8
|
||||
corner_radius_bottom_left = 8
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ruhgv"]
|
||||
bg_color = Color(1, 0.2901961, 0.45490196, 1)
|
||||
border_width_left = 3
|
||||
border_width_top = 3
|
||||
border_width_right = 3
|
||||
border_width_bottom = 3
|
||||
border_color = Color(0.13725491, 0.019607844, 0.02745098, 1)
|
||||
corner_radius_top_left = 8
|
||||
corner_radius_top_right = 8
|
||||
corner_radius_bottom_right = 8
|
||||
corner_radius_bottom_left = 8
|
||||
|
||||
[node name="HealthBar" type="Control" unique_id=1540037291]
|
||||
custom_minimum_size = Vector2(96, 20)
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_right = 96.0
|
||||
offset_bottom = 20.0
|
||||
script = ExtResource("1_ruhgv")
|
||||
|
||||
[node name="ProgressBar" type="ProgressBar" parent="." unique_id=1237029629]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_styles/background = SubResource("StyleBoxFlat_ilash")
|
||||
theme_override_styles/fill = SubResource("StyleBoxFlat_ruhgv")
|
||||
max_value = 1.0
|
||||
value = 0.5
|
||||
show_percentage = false
|
||||
|
||||
[node name="HealthAmount" type="Label" parent="." unique_id=1539272143]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
text = "10"
|
||||
horizontal_alignment = 1
|
||||
Reference in New Issue
Block a user