déplacement: se coller au mur

lorsque le joueur presse la touche de déplacement et que le personnage
est contre le mur, alors, le personnage tombe moins vite et l'animation
de 'se coller au mur' est jouée.
This commit is contained in:
Thomas Lavocat
2023-04-28 20:59:19 +02:00
parent accb23ec4c
commit 1b8e1c30f1

View File

@@ -49,6 +49,8 @@ var jump_key_counter : int = 0
var falling_step : int = -1 var falling_step : int = -1
var pressing_wall = false
func walk(direction:int) -> int: func walk(direction:int) -> int:
# Fait marcher le personnage. # Fait marcher le personnage.
@@ -58,6 +60,9 @@ func walk(direction:int) -> int:
if is_on_floor(): if is_on_floor():
threshold = WALK_INCR_GROUND threshold = WALK_INCR_GROUND
if is_on_wall():
walking_step = min(walking_step, 1)
# Si le joueur décide de marcher alors, le compteur de pas doit s'incrémenter # Si le joueur décide de marcher alors, le compteur de pas doit s'incrémenter
# Si le joueur ne veut plus marcher, alors, le compteur de pas décrémente # Si le joueur ne veut plus marcher, alors, le compteur de pas décrémente
@@ -99,6 +104,8 @@ func fall() -> int:
return velocity.y return velocity.y
else: else:
falling_step = min(falling_step+1, FALL_SPEED_TABLE.size()-1) falling_step = min(falling_step+1, FALL_SPEED_TABLE.size()-1)
if pressing_wall:
falling_step = min(falling_step, FALL_SPEED_TABLE.size()-5)
return FALL_SPEED_TABLE[falling_step] * FALLING_SPEED return FALL_SPEED_TABLE[falling_step] * FALLING_SPEED
@@ -151,8 +158,10 @@ func _physics_process(delta: float) -> void:
"move_right" + action_suffix "move_right" + action_suffix
) )
pressing_wall = is_on_wall_only() and not is_zero_approx(axis)
if axis != 0: if axis != 0:
direction = axis direction = axis
velocity.x = walk(direction) velocity.x = walk(direction)
if not is_zero_approx(velocity.x): if not is_zero_approx(velocity.x):
@@ -161,6 +170,9 @@ func _physics_process(delta: float) -> void:
else: else:
animation.scale.x = -1.0 animation.scale.x = -1.0
if pressing_wall and not jumping:
animation.scale.x *= -1
floor_stop_on_slope = not platform_detector.is_colliding() floor_stop_on_slope = not platform_detector.is_colliding()
move_and_slide() # Character is colliding move_and_slide() # Character is colliding
@@ -180,10 +192,13 @@ func get_new_animation(is_shooting := false) -> String:
animation_new = "idle" animation_new = "idle"
else: else:
if velocity.y > 0.0: if velocity.y > 0.0:
if walking_step > 0: if pressing_wall:
animation_new = "falling_diagonals" animation_new = "wall_stick"
else: else:
animation_new = "falling_straight" if walking_step > 0:
animation_new = "falling_diagonals"
else:
animation_new = "falling_straight"
else: else:
animation_new = "jumping" animation_new = "jumping"
return animation_new return animation_new