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()
|
||||
|
||||
Reference in New Issue
Block a user