princesse/mort: gestion avancée de la mort
Lorsque la princesse meurt, une animation de mort est lancée qui la fait disparaitre dans un tourbillon de la mort. A la fin du tourbillon de la mort, un signal est renvoyé à la princesse pour que la scene redémarre. Basique mais fait le taff!
This commit is contained in:
28
princesse.gd
28
princesse.gd
@@ -10,6 +10,7 @@ var gravity: int = ProjectSettings.get("physics/2d/default_gravity")
|
||||
@onready var ground_far_detect := $ground_far_detect as RayCast2D
|
||||
@onready var animation := $AnimatedSprite2D as AnimatedSprite2D
|
||||
@onready var camera := $Camera2D as Camera2D
|
||||
@onready var death_animation := $"Death player" as AnimationPlayer
|
||||
|
||||
################################################################################
|
||||
#
|
||||
@@ -43,11 +44,14 @@ var DASH_SPEED = WALKING_SPEED * 2
|
||||
|
||||
signal cheese_collected()
|
||||
|
||||
var locked = true
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# Etat de la princesse
|
||||
#
|
||||
################################################################################
|
||||
var dead = false
|
||||
# Direction dans laquelle est positioné le personnage.
|
||||
var direction : int = 1
|
||||
|
||||
@@ -276,7 +280,6 @@ func cancel_dash() -> void:
|
||||
dash_step = -1
|
||||
dashing=false
|
||||
|
||||
|
||||
func choose_animation_orientation() -> void:
|
||||
# Oriente l'animation correctement en fonction de laquelle on joue et de
|
||||
# la direction du personnage
|
||||
@@ -308,7 +311,7 @@ func move_and_handle_collisions() -> void:
|
||||
var tile_rid = collider.get_collider_rid()
|
||||
layer_of_collision = PhysicsServer2D.body_get_collision_layer(tile_rid)
|
||||
if layer_of_collision == PICS_BLOCK_LAYER:
|
||||
get_tree(). reload_current_scene()
|
||||
death()
|
||||
if dashing and not is_on_floor():
|
||||
cancel_dash()
|
||||
|
||||
@@ -320,6 +323,8 @@ func get_coyote(table: Array):
|
||||
|
||||
func read_input() -> void:
|
||||
# Lis les commandes du joueur pour piloter Princesse
|
||||
if locked:
|
||||
return
|
||||
|
||||
# Le joueur veut-il et peut-il s'accrocher au mur ?
|
||||
grab_wall = pressing_wall and Input.is_action_pressed("grab" + action_suffix)
|
||||
@@ -452,6 +457,8 @@ func get_new_animation() -> String:
|
||||
return animation_new
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if dead:
|
||||
return
|
||||
compute_state()
|
||||
read_input()
|
||||
velocity.y = jump()
|
||||
@@ -465,3 +472,20 @@ func _physics_process(delta: float) -> void:
|
||||
func reload_fart() -> void:
|
||||
available_dashs = min(available_dashs+1, MAX_FARTS)
|
||||
Input.start_joy_vibration(0, 0, 1, 0.1)
|
||||
|
||||
func death() -> void:
|
||||
if not dead:
|
||||
print("death")
|
||||
locked = true
|
||||
Input.start_joy_vibration(0, 1, 1, 1)
|
||||
self.rotation = 90
|
||||
dead = true
|
||||
death_animation.play(&"death")
|
||||
|
||||
func _ready():
|
||||
await get_tree().create_timer(0.3).timeout
|
||||
locked = false
|
||||
dead = false
|
||||
|
||||
func _on_death_player_animation_finished(anim_name: StringName) -> void:
|
||||
get_tree(). reload_current_scene()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=31 format=3 uid="uid://dv0mokf4eogm7"]
|
||||
[gd_scene load_steps=33 format=3 uid="uid://dv0mokf4eogm7"]
|
||||
|
||||
[ext_resource type="Script" path="res://princesse.gd" id="1_dkp7s"]
|
||||
[ext_resource type="Texture2D" uid="uid://dr7fyh2rufsyj" path="res://sprite/princess_falling_direction.png" id="2_hholp"]
|
||||
@@ -199,6 +199,39 @@ animations = [{
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_6r7th"]
|
||||
height = 52.0
|
||||
|
||||
[sub_resource type="Animation" id="Animation_uo4aj"]
|
||||
resource_name = "death"
|
||||
length = 0.5
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("AnimatedSprite2D:rotation")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0.1, 0.5),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [0.0, 31.4159]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("AnimatedSprite2D:scale")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0.1, 0.5),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector2(1, 1), Vector2(0, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_hxxp0"]
|
||||
_data = {
|
||||
"death": SubResource("Animation_uo4aj")
|
||||
}
|
||||
|
||||
[node name="Princesse" type="CharacterBody2D"]
|
||||
collision_mask = 113
|
||||
slide_on_ceiling = false
|
||||
@@ -234,4 +267,11 @@ shape = SubResource("CapsuleShape2D_6r7th")
|
||||
target_position = Vector2(0, 38)
|
||||
collision_mask = 16
|
||||
|
||||
[node name="Death player" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
"": SubResource("AnimationLibrary_hxxp0")
|
||||
}
|
||||
|
||||
[connection signal="cheese_collected" from="." to="." method="reload_fart"]
|
||||
[connection signal="animation_finished" from="Death player" to="." method="_on_death_player_animation_finished"]
|
||||
[connection signal="animation_finished" from="Death player" to="." method="reload_scene"]
|
||||
|
||||
Reference in New Issue
Block a user