diff --git a/Scenes/Player/player.gd b/Scenes/Player/player.gd index 1e33cbd..4245216 100644 --- a/Scenes/Player/player.gd +++ b/Scenes/Player/player.gd @@ -8,7 +8,7 @@ class_name Player # Called when the node enters the scene tree for the first time. func _ready() -> void: update_scrolls() - print("HP: ", SceneManager.player_hp) + %HealthBar.play("3_hp") var damage: float = 2 if SceneManager.player_next_scene_spawn_pos != Vector2(0, 0): position = SceneManager.player_next_scene_spawn_pos @@ -64,11 +64,10 @@ func _on_area_2d_body_exited(body: Node2D) -> void: func _on_hit_box_area_2d_body_entered(body: Node2D) -> void: SceneManager.player_hp -= 1 - print("HP: ", SceneManager.player_hp) + %HealthBar.play(str(SceneManager.player_hp) + "_hp") if SceneManager.player_hp <= 0: die() func die(): - print("DED") get_tree().call_deferred("reload_current_scene") SceneManager.player_hp = 3 diff --git a/Scenes/Player/player.tscn b/Scenes/Player/player.tscn index 0f8f527..08dee29 100644 --- a/Scenes/Player/player.tscn +++ b/Scenes/Player/player.tscn @@ -3,6 +3,7 @@ [ext_resource type="Script" uid="uid://duilaa5lwqeup" path="res://Scenes/Player/player.gd" id="1_a3d8c"] [ext_resource type="Texture2D" uid="uid://cjbvc07lh4x1b" path="res://Ninja Adventure - Asset Pack/Actor/Characters/KnightGold/SeparateAnim/Walk.png" id="2_a3d8c"] [ext_resource type="Texture2D" uid="uid://6dmy1j0t5mqy" path="res://Ninja Adventure - Asset Pack/Items/Scroll/ScrollEmpty.png" id="3_xpcdj"] +[ext_resource type="Texture2D" uid="uid://ff3wjwfsais6" path="res://Ninja Adventure - Asset Pack/Ui/LifeReceptacle/heart_2.png" id="4_mtuoh"] [sub_resource type="AtlasTexture" id="AtlasTexture_a3d8c"] atlas = ExtResource("2_a3d8c") @@ -152,6 +153,57 @@ size = Vector2(8, 8) [sub_resource type="LabelSettings" id="LabelSettings_chgu2"] font_size = 48 +[sub_resource type="AtlasTexture" id="AtlasTexture_hnuln"] +atlas = ExtResource("4_mtuoh") +region = Rect2(0, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_aqm4k"] +atlas = ExtResource("4_mtuoh") +region = Rect2(16, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_rcvs5"] +atlas = ExtResource("4_mtuoh") +region = Rect2(32, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_h8ma5"] +atlas = ExtResource("4_mtuoh") +region = Rect2(48, 0, 16, 16) + +[sub_resource type="SpriteFrames" id="SpriteFrames_chgu2"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_hnuln") +}], +"loop": 1, +"name": &"0_hp", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_aqm4k") +}], +"loop": 1, +"name": &"1_hp", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_rcvs5") +}], +"loop": 1, +"name": &"2_hp", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_h8ma5") +}], +"loop": 1, +"name": &"3_hp", +"speed": 5.0 +}] + [node name="CharacterBody2D" type="CharacterBody2D" unique_id=1991398375] collision_mask = 7 motion_mode = 1 @@ -184,9 +236,9 @@ debug_color = Color(0.9427947, 0.09120729, 0.5535774, 0.41960785) [node name="CanvasLayer" type="CanvasLayer" parent="." unique_id=1672000946] [node name="Panel" type="Panel" parent="CanvasLayer" unique_id=1717998937] -offset_left = 50.0 +offset_left = 198.0 offset_top = 52.0 -offset_right = 264.0 +offset_right = 412.0 offset_bottom = 125.0 [node name="Label" type="Label" parent="CanvasLayer/Panel" unique_id=1669846200] @@ -206,6 +258,13 @@ offset_right = 63.0 offset_bottom = 62.0 texture = ExtResource("3_xpcdj") +[node name="HealthBar" type="AnimatedSprite2D" parent="CanvasLayer" unique_id=102598890] +unique_name_in_owner = true +position = Vector2(114, 88) +scale = Vector2(4.7812505, 4.7812505) +sprite_frames = SubResource("SpriteFrames_chgu2") +animation = &"0_hp" + [connection signal="body_entered" from="HitBoxArea2D" to="." method="_on_hit_box_area_2d_body_entered"] [connection signal="body_entered" from="InteractArea2D" to="." method="_on_area_2d_body_entered"] [connection signal="body_exited" from="InteractArea2D" to="." method="_on_area_2d_body_exited"]