From fb4599d197ef58bf553248fdc0d4632f7690d52c Mon Sep 17 00:00:00 2001 From: Thomas Lavocat Date: Sun, 30 Apr 2023 12:09:50 +0200 Subject: [PATCH] =?UTF-8?q?princess/marche+kick:=20r=C3=A9initialisation?= =?UTF-8?q?=20correct=20des=20l'=C3=A9tat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Certaines variables d'état nécessaire au bon déroulement des décélérations et de la marche n'étaient pas remises au bon état correctement en fin de marche. Ce commit essaye d'addresser ce soucis. --- princesse.gd | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/princesse.gd b/princesse.gd index 300eb7d..b2fc9cc 100644 --- a/princesse.gd +++ b/princesse.gd @@ -84,10 +84,19 @@ const PICS_BLOCK_LAYER = 1 << (6 - 1) # collision layer 6 -> pics const CHEESE_LAYER = 1 << (6 - 1) # collision layer 7 -> fromages var layer_of_collision = null +func init_walk_state(): + walk_incr_reserve = 0 + walking_step = -1 + init_decel = false + func walk(direction:int) -> float: - if kicking: - return velocity.x # Fait marcher le personnage. + if kicking: + init_walk_state() + return velocity.x + + if velocity.x == 0 and not walking: + init_walk_state() # Si le personnage est dans l'air, il aura une friction plus faible lors de # la décélération. @@ -95,9 +104,6 @@ func walk(direction:int) -> float: if is_on_floor(): threshold = WALK_INCR_GROUND - if is_on_wall(): - walking_step = min(walking_step, 1) - # Un changement de direction implique de perdre la vélocité dans la direction # précédente avant de repartir dans la direction que l'on veut. # ça ne change rien pour le nombre de frames nécéssaires pour accélérer dans @@ -123,18 +129,23 @@ func walk(direction:int) -> float: # qu'il n'y a pas d'input du joueur. Lorsque le joueur va vouloir reprendre # la main, il faut démarrer à la bonne vélocité var abs_v_x = abs(velocity.x) - if abs_v_x != 0 and walking_step == -1: - # trouver l'indice le plus proche de la vitesse courante - for index in range(0, table.size()-1): - var speed_i = table[walking_step] * WALKING_SPEED - var speed_i1 = table[walking_step+1] * WALKING_SPEED - # lorsque l'on a trouvé l'indice le bon endroit dans le tableau, alors - # on renvoie l'indice trouvé - if abs_v_x > speed_i and abs_v_x <= speed_i1: - walking_step = index+1 - # si rien n'est trouvé, alors on initialise l'indice au maximum possible + if abs_v_x != 0: if walking_step == -1: - walking_step = table.size() - 1 + # trouver l'indice le plus proche de la vitesse courante + for index in range(0, table.size()-1): + var speed_i = table[walking_step] * WALKING_SPEED + var speed_i1 = table[walking_step+1] * WALKING_SPEED + # lorsque l'on a trouvé l'indice le bon endroit dans le tableau, alors + # on renvoie l'indice trouvé + if abs_v_x == speed_i: + walking_step = index + if abs_v_x == speed_i1: + walking_step = index+1 + if abs_v_x > speed_i and abs_v_x < speed_i1: + walking_step = index+1 + # si rien n'est trouvé, alors on initialise l'indice au maximum possible + if walking_step == -1: + walking_step = table.size() - 1 if walking: walking_step = min(walking_step+1, X_SPEED_TABLE.size() -1) @@ -166,6 +177,8 @@ func walk(direction:int) -> float: return speed * direction + velocity.x else: return speed * direction + else: + init_walk_state return velocity.x func fall() -> float: