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
+6
View File
@@ -45,3 +45,9 @@ collision_mask = 32
position = Vector2(0, -30)
shape = SubResource("CircleShape2D_421q1")
debug_color = Color(0.95670325, 0.056883797, 0.5071302, 0.41960785)
[node name="HealthBar" parent="." index="7" unique_id=1540037291]
offset_top = -95.0
offset_bottom = -75.0
back_color = Color(0.015686275, 0.05490196, 0.16862746, 1)
fill_color = Color(0.37254903, 0.5372549, 0.75686276, 1)
+1
View File
@@ -16,6 +16,7 @@ var dash_available := true
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
super._ready()
dash_timer.wait_time = dash_duration
dash_cooldown_timer.wait_time = dash_cooldown
@@ -63,5 +63,9 @@ z_index = 1
position = Vector2(0, -32)
shape = SubResource("CircleShape2D_ht2l1")
[node name="HealthBar" parent="." index="8" unique_id=1540037291]
back_color = Color(0.13725491, 0.019607844, 0.02745098, 1)
fill_color = Color(1, 0.2901961, 0.45490196, 1)
[connection signal="timeout" from="DashTimer" to="." method="_on_dash_timer_timeout"]
[connection signal="timeout" from="TrailTimer" to="Visuals/Trail" method="_on_trail_timer_timeout"]
+13
View File
@@ -6,3 +6,16 @@ class_name Unit
@onready var visuals: Node2D = %Visuals
@onready var sprite: Sprite2D = %Sprite
@onready var anim_player: AnimationPlayer = $AnimationPlayer
@onready var health_component: HealthComponent = $HealthComponent
func _ready() -> void:
print(stats)
health_component.setup(stats)
func _on_hurtbox_component_on_damaged(hitbox: HitboxComponent) -> void:
if health_component.current_health <=0:
return
health_component.take_damage(hitbox.damage)
print("%s: %d" % [name, health_component.current_health] )
+13
View File
@@ -3,6 +3,8 @@
[ext_resource type="Texture2D" uid="uid://devt2xbk78rej" path="res://assets/sprites/shadow.png" id="1_fvc8g"]
[ext_resource type="Script" uid="uid://cwf3afjy6t6rg" path="res://scenes/unit/unit.gd" id="1_vh40f"]
[ext_resource type="PackedScene" uid="uid://bkyyic3okyjxx" path="res://scenes/components/hurtbox_component.tscn" id="3_vh40f"]
[ext_resource type="PackedScene" uid="uid://2ew7i6g3p0v8" path="res://scenes/components/health_component.tscn" id="4_bhlit"]
[ext_resource type="PackedScene" uid="uid://ifmw1e7gycc8" path="res://scenes/ui/health_bar/health_bar.tscn" id="5_vgvef"]
[sub_resource type="Animation" id="Animation_bhlit"]
length = 0.001
@@ -247,3 +249,14 @@ position = Vector2(0, -61)
libraries/ = SubResource("AnimationLibrary_w7udy")
[node name="HurtboxComponent" parent="." unique_id=1155790880 instance=ExtResource("3_vh40f")]
[node name="HealthComponent" parent="." unique_id=455886217 instance=ExtResource("4_bhlit")]
[node name="HealthBar" parent="." unique_id=1540037291 instance=ExtResource("5_vgvef")]
offset_left = -46.0
offset_top = -90.0
offset_right = 50.0
offset_bottom = -70.0
[connection signal="on_damaged" from="HurtboxComponent" to="." method="_on_hurtbox_component_on_damaged"]
[connection signal="on_health_changed" from="HealthComponent" to="HealthBar" method="_on_health_component_on_health_changed"]