Skip to content

Commit

Permalink
nice death animation
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsOuvrard committed Nov 15, 2024
1 parent 9221b9a commit 8d5cd68
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions Scenes/gameplay.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ color = Color(0.117227, 3.39021e-06, 0.0957673, 1)
[node name="Greed" parent="." instance=ExtResource("3_bncwm")]

[node name="GamePlayAudio" type="AudioStreamPlayer2D" parent="."]
process_mode = 3
stream = ExtResource("3_0lt7v")
autoplay = true

Expand Down
2 changes: 2 additions & 0 deletions Scenes/player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ _data = {
radius = 13.0

[node name="Player" type="CharacterBody2D"]
process_mode = 3
collision_mask = 52
script = ExtResource("1_flqv2")
metadata/is_player = true
Expand Down Expand Up @@ -280,6 +281,7 @@ one_shot = true
[node name="ShotCooldown" type="Timer" parent="."]
one_shot = true

[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animated_sprite_2d_animation_finished"]
[connection signal="life_change" from="Health" to="." method="_on_health_life_change"]
[connection signal="area_entered" from="SwordAttack" to="." method="_on_sword_attack_area_entered"]
[connection signal="body_entered" from="SwordAttack" to="." method="_on_sword_attack_body_entered"]
14 changes: 11 additions & 3 deletions Scripts/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ func avoid_collision_with_other_bodies(delta: float):
print("Player send knockback to enemy")

func _physics_process(delta):
if get_tree().paused:
animation_handler.actualize_animation()
return
# * Direction
var direction_input = Vector2.ZERO

Expand Down Expand Up @@ -268,9 +271,7 @@ func _on_sword_attack_area_entered(area: Area2D) -> void:
func _on_health_life_change(value: Variant) -> void:
if value <= 0:
animation_handler.add_animation(Data.Animations.DIE)
# TODO put a animation node, and put this in the end of the animation
# get_tree().change_scene_to_file("res://Scenes/main_menu.tscn")
return
get_tree().paused = true
SignalsHandler.player_life_change.emit(value)

#region debug
Expand All @@ -291,3 +292,10 @@ func debug_weapons():
for weapon in ammo_inventory:
ammo_inventory[weapon] = 99
#endregion


func _on_animated_sprite_2d_animation_finished() -> void:
if get_tree().paused:
await get_tree().create_timer(1).timeout
get_tree().paused = false
get_tree().change_scene_to_file("res://Scenes/main_menu.tscn")

0 comments on commit 8d5cd68

Please sign in to comment.