princesse: réorganuisation du code

Externalisation des fonctions pour gérer les animations et leur
orientation.
This commit is contained in:
Thomas Lavocat
2023-04-29 18:32:13 +02:00
parent 4ef5aaca15
commit 80fd4f4758

View File

@@ -185,6 +185,25 @@ func end_jump():
jumping_step = -1
jump_key_counter = 0
func choose_animation_orientation() -> void:
if not is_zero_approx(velocity.x):
if velocity.x > 0.0:
animation.scale.x = 1.0
else:
animation.scale.x = -1.0
if grab_wall:
if wall_detect_left.is_colliding():
animation.scale.x = 1
elif wall_detect_right.is_colliding():
animation.scale.x = -1
func play_animation() -> void:
var anim := get_new_animation()
if anim != animation.animation:
animation.animation = anim
animation.play()
func _physics_process(delta: float) -> void:
coyote_ground.append(is_on_floor())
@@ -234,18 +253,6 @@ func _physics_process(delta: float) -> void:
velocity.x = walk(direction)
if not is_zero_approx(velocity.x):
if velocity.x > 0.0:
animation.scale.x = 1.0
else:
animation.scale.x = -1.0
if grab_wall:
if wall_detect_left.is_colliding():
animation.scale.x = 1
elif wall_detect_right.is_colliding():
animation.scale.x = -1
#floor_stop_on_slope = not platform_detector.is_colliding()
var collision = move_and_slide()
if collision:
@@ -257,10 +264,8 @@ func _physics_process(delta: float) -> void:
if layer_of_collision == PICS_BLOCK_LAYER:
get_tree(). reload_current_scene()
var anim := get_new_animation()
if anim != animation.animation:
animation.animation = anim
animation.play()
choose_animation_orientation()
play_animation()
func get_new_animation() -> String: