princess/marche+kick: réinitialisation correct des l'état

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.
This commit is contained in:
Thomas Lavocat
2023-04-30 12:09:50 +02:00
parent 3879023222
commit fb4599d197

View File

@@ -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: