From aff5df529ebe40a09183836f182de86550f74395 Mon Sep 17 00:00:00 2001 From: godzilla5hrimp Date: Thu, 24 Sep 2026 22:33:48 +0200 Subject: [PATCH] fix: combat animation fix; add the death animation + delay; --- Scenes/Player/player.gd | 14 ++++++++++++-- Scenes/Player/player.tscn | 20 +++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Scenes/Player/player.gd b/Scenes/Player/player.gd index 2af0288..7a3cc0d 100644 --- a/Scenes/Player/player.gd +++ b/Scenes/Player/player.gd @@ -18,6 +18,9 @@ func _ready() -> void: # Called every frame. 'delta' is the elapsed time since the previous frame. func _physics_process(delta: float) -> void: + if SceneManager.player_hp <= 0: + return + if not is_attacking: move_player() push_blocks() @@ -78,8 +81,8 @@ func _on_hit_box_area_2d_body_entered(body: Node2D) -> void: velocity += normalize_knockback * 500 func die(): - get_tree().call_deferred("reload_current_scene") - SceneManager.player_hp = 3 + $AnimatedSprite2D.play("death") + $DeathTimer.start() func _on_sword_area_2d_body_entered(body: Node2D) -> void: var distance_to_enemy: Vector2 = body.global_position - global_position @@ -91,6 +94,8 @@ func _on_sword_area_2d_body_entered(body: Node2D) -> void: body.queue_free() func attack(): + if not $Sword/SwordTimer.is_stopped(): + return var player_animation: String = $AnimatedSprite2D.animation if player_animation == "move_right": $AnimatedSprite2D.play("attack_right") @@ -125,3 +130,8 @@ func _on_sword_timer_timeout() -> void: $AnimatedSprite2D.play("move_up") if player_animation == "attack_down": $AnimatedSprite2D.play("move_down") + + +func _on_death_timer_timeout() -> void: + get_tree().call_deferred("reload_current_scene") + SceneManager.player_hp = 3 diff --git a/Scenes/Player/player.tscn b/Scenes/Player/player.tscn index cc7ea8a..e81a336 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://cpuphg0fwkemr" path="res://Ninja Adventure - Asset Pack/Actor/Characters/KnightGold/SeparateAnim/Attack.png" id="2_dd0ac"] +[ext_resource type="Texture2D" uid="uid://cp2qfumar3lu" path="res://Ninja Adventure - Asset Pack/Actor/Characters/KnightGold/SeparateAnim/Dead.png" id="3_0u5uq"] [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"] [ext_resource type="Texture2D" uid="uid://38ldil8moinv" path="res://Ninja Adventure - Asset Pack/Items/Weapons/Sword2/SpriteInHand.png" id="5_htcer"] @@ -23,6 +24,10 @@ region = Rect2(48, 0, 16, 16) atlas = ExtResource("2_dd0ac") region = Rect2(16, 0, 16, 16) +[sub_resource type="AtlasTexture" id="AtlasTexture_ythyg"] +atlas = ExtResource("3_0u5uq") +region = Rect2(0, 0, 16, 16) + [sub_resource type="AtlasTexture" id="AtlasTexture_a3d8c"] atlas = ExtResource("2_a3d8c") region = Rect2(0, 0, 16, 16) @@ -123,6 +128,14 @@ animations = [{ }, { "frames": [{ "duration": 1.0, +"texture": SubResource("AtlasTexture_ythyg") +}], +"loop": 1, +"name": &"death", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, "texture": SubResource("AtlasTexture_a3d8c") }, { "duration": 1.0, @@ -410,7 +423,7 @@ script = ExtResource("1_a3d8c") [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=721334358] sprite_frames = SubResource("SpriteFrames_bqpwv") -animation = &"attack_left" +animation = &"death" autoplay = "move_down" [node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=129222135] @@ -490,8 +503,13 @@ one_shot = true [node name="AnimationPlayer" type="AnimationPlayer" parent="." unique_id=1687360666] libraries/ = SubResource("AnimationLibrary_jlvik") +[node name="DeathTimer" type="Timer" parent="." unique_id=1301433095] +wait_time = 1.5 +one_shot = true + [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"] [connection signal="body_entered" from="Sword/SwordArea2D" to="." method="_on_sword_area_2d_body_entered"] [connection signal="timeout" from="Sword/SwordTimer" to="." method="_on_sword_timer_timeout"] +[connection signal="timeout" from="DeathTimer" to="." method="_on_death_timer_timeout"]