From 1b8e1c30f16a78ab50c4553c4407dcc3f3b55536 Mon Sep 17 00:00:00 2001 From: Thomas Lavocat Date: Fri, 28 Apr 2023 20:59:19 +0200 Subject: [PATCH] =?UTF-8?q?d=C3=A9placement:=20se=20coller=20au=20mur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- princesse.gd | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/princesse.gd b/princesse.gd index c226b4c..4fd7a20 100644 --- a/princesse.gd +++ b/princesse.gd @@ -49,6 +49,8 @@ var jump_key_counter : int = 0 var falling_step : int = -1 +var pressing_wall = false + func walk(direction:int) -> int: # Fait marcher le personnage. @@ -58,6 +60,9 @@ func walk(direction:int) -> int: if is_on_floor(): 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 ne veut plus marcher, alors, le compteur de pas décrémente @@ -99,6 +104,8 @@ func fall() -> int: return velocity.y else: 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 @@ -151,8 +158,10 @@ func _physics_process(delta: float) -> void: "move_right" + action_suffix ) + pressing_wall = is_on_wall_only() and not is_zero_approx(axis) if axis != 0: direction = axis + velocity.x = walk(direction) if not is_zero_approx(velocity.x): @@ -161,6 +170,9 @@ func _physics_process(delta: float) -> void: else: animation.scale.x = -1.0 + if pressing_wall and not jumping: + animation.scale.x *= -1 + floor_stop_on_slope = not platform_detector.is_colliding() move_and_slide() # Character is colliding @@ -180,10 +192,13 @@ func get_new_animation(is_shooting := false) -> String: animation_new = "idle" else: if velocity.y > 0.0: - if walking_step > 0: - animation_new = "falling_diagonals" + if pressing_wall: + animation_new = "wall_stick" else: - animation_new = "falling_straight" + if walking_step > 0: + animation_new = "falling_diagonals" + else: + animation_new = "falling_straight" else: animation_new = "jumping" return animation_new