marcher: décélération air/sol dissociée

La princesse peut maintenant décélérer correctement. Et elle possède un
moyen de décélérer à des vitesses différentes dans l'air que sur le sol.
Il restera à tuner correctement cette nouvelle variable.

Prochaine étape: coyote time et wall stick + wall kick

banzaï!
This commit is contained in:
Thomas Lavocat
2023-04-23 20:45:28 +02:00
parent f9bbccca0a
commit e309410753

View File

@@ -31,10 +31,18 @@ var _double_jump_charged := false
# sans encore être au sol
@export var COYOTE_LENGTH := 20
# Direction dans laquelle est positioné le personnage.
var direction : int = 1
# Variables détats relatives à la marche.
var walking : bool = false
var walking_step: int = -1
var init_decel: bool = true
@export var WALK_INCR_GROUND : int = 1
@export var WALK_INCR_AIR : int = 3
var walk_incr_reserve : int = 0
var init_decel: bool = false
# variables d'état relatives au saut
var jumping : bool = false
var jumping_step : int = -1
var jump_key_counter : int = 0
@@ -42,22 +50,47 @@ var jump_key_counter : int = 0
var falling_step : int = -1
func walk(direction:int) -> int:
# Fait marcher le personnage.
# Si le personnage est dans l'air, il aura une friction plus faible lors de
# la décélération.
var threshold = WALK_INCR_AIR
if is_on_floor():
threshold = WALK_INCR_GROUND
# 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
# La vitese choisie est le numéro d'étape dans le tableau correspondant
# X_SPEED_TABLE pour l'accélération
# X_SPEED_DECEL pour la décélération
var table = X_SPEED_TABLE
if walking:
walking_step = min(walking_step+1, table.size() -1)
walking_step = min(walking_step+1, X_SPEED_TABLE.size() -1)
init_decel = true
else:
# Lors de la première frame de la décélération, initialiser la valeur
# du compteur d'incrément en haut du tableau de décélération
table = X_SPEED_DECEL
if init_decel:
walking_step = min(walking_step, table.size() - 1)
walking_step = min(walking_step, X_SPEED_DECEL.size() - 1)
init_decel = false
if walking_step > 0:
# 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
# la décélération
if walking_step >= 0:
var speed = table[walking_step] * WALKING_SPEED
if not walking:
walking_step-=1
walk_incr_reserve += 1
# appliquer le nombre de frames nécéssaire pour décrémenter, dépend
# de où est le personnage (air vs sol)
if walk_incr_reserve >= threshold:
walk_incr_reserve = 0
walking_step-=1
return speed * direction
return 0
return velocity.x
func fall() -> int:
@@ -113,12 +146,14 @@ func _physics_process(delta: float) -> void:
Input.is_action_pressed("move_right" + action_suffix)
)
velocity.x = walk(
Input.get_axis(
var axis = Input.get_axis(
"move_left" + action_suffix,
"move_right" + action_suffix
)
)
if axis != 0:
direction = axis
velocity.x = walk(direction)
if not is_zero_approx(velocity.x):
if velocity.x > 0.0: