diff --git a/princesse.gd b/princesse.gd index 886f65b..a4a5c7f 100644 --- a/princesse.gd +++ b/princesse.gd @@ -100,6 +100,23 @@ func walk(direction:int) -> float: walking_step = min(walking_step, X_SPEED_DECEL.size() - 1) init_decel = false + # dans le cas où le personnage est propulsé par une force extérieure et + # qu'il n'y a pas d'input du joueur pour permettre au personnage de ralentir + # il va bien falloir s'y coller, sinon, il va glisser indéfiniment. + 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, X_SPEED_DECEL.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 walking_step == -1: + walking_step = X_SPEED_DECEL.size() - 1 + # Si le compteur d'incrément est supérieur ou égal à zéro, c'est qu'il # faut bouger, donc il est nécéssaire en premier temps de récupérer la vitesse # à l'indice courant. Puis si le joueur ne veut plus accélérer, alors, appliquer