saut: la princesse peut sauter

Si le joueur maintient la barre espace la princesse saute plus haut.
Il faudra tuner les variables.

Prochaine étape: modifier la décélération dans l'air.
This commit is contained in:
Thomas Lavocat
2023-04-23 09:13:37 +02:00
parent 12b3414abb
commit e38d18b5cd

View File

@@ -13,16 +13,15 @@ var _double_jump_charged := false
@export var WALKING_SPEED = 400 @export var WALKING_SPEED = 400
@export var FALLING_SPEED = 400 @export var FALLING_SPEED = 400
@export var JUMPING_SPEED = 400
@export var X_SPEED_TABLE = [0, 0.1, 0.15, 0.2, 0.3, 0.6, 0.9, 1] @export var X_SPEED_TABLE = [0, 0.1, 0.15, 0.2, 0.3, 0.6, 0.9, 1]
@export var X_SPEED_DECEL = [0, 0.1, 0.6, 1] @export var X_SPEED_DECEL = [0, 0.1, 0.6, 1]
@export var X_SPEED_AIR_DECEL =[0, 0.1, 0.6, 1] @export var X_SPEED_AIR_DECEL =[0, 0.1, 0.6, 1]
@export var FALL_SPEED_TABLE = [0, 0.1, 0.15, 0.2, 0.3, 0.6, 0.9, 1] @export var FALL_SPEED_TABLE = [0, 0.1, 0.15, 0.2, 0.3, 0.6, 0.9, 1]
@export var JUMP_SPEED_TABLE = [0, 0.4, 0.8, 1.2, 1.6, 2, 2.4, 2.8, 3, 3, 4, 5] @export var JUMP_SPEED_TABLE = [0, 0.1, 0.15, 0.2, 0.25,
0.6, 0.65, 0.7, 0.75, 0.8, 0.9, 1]
@export var KICK_SPEED_TABLE = [0, 0.2, 0.4, 0.6, 1, 1.6, 2.4, 3] @export var KICK_SPEED_TABLE = [0, 0.2, 0.4, 0.6, 1, 1.6, 2.4, 3]
# Nombre d'inréments composant un saut
@export var JUMPING_COUNTER = 20
# Nombre d'incrément à rajouter lorsque la touche de saut est maintenue # Nombre d'incrément à rajouter lorsque la touche de saut est maintenue
@export var JUMPING_COUNTER_REFILL = 2 @export var JUMPING_COUNTER_REFILL = 2
# Tous les combien d'incréments rajouter un refill sur le compteur # Tous les combien d'incréments rajouter un refill sur le compteur
@@ -37,6 +36,9 @@ var walking_step: int = -1
var init_decel: bool = true var init_decel: bool = true
var jumping : bool = false var jumping : bool = false
var jumping_step : int = -1
var jump_key_counter : int = 0
var falling_step : int = -1 var falling_step : int = -1
func walk(direction:int) -> int: func walk(direction:int) -> int:
@@ -56,7 +58,8 @@ func walk(direction:int) -> int:
walking_step-=1 walking_step-=1
return speed * direction return speed * direction
return 0 return 0
func fall() -> int: func fall() -> int:
if jumping or is_on_floor(): if jumping or is_on_floor():
falling_step = -1 falling_step = -1
@@ -64,18 +67,55 @@ func fall() -> int:
else: else:
falling_step = min(falling_step+1, FALL_SPEED_TABLE.size()-1) falling_step = min(falling_step+1, FALL_SPEED_TABLE.size()-1)
return FALL_SPEED_TABLE[falling_step] * FALLING_SPEED return FALL_SPEED_TABLE[falling_step] * FALLING_SPEED
func jump() -> int:
if is_on_ceiling():
end_jump()
if not jumping:
return velocity.y
if jump_key_counter > 0 and jump_key_counter % JUMPING_KEY_COUNTER_THRESHOLD == 0:
jumping_step = min(
jumping_step + JUMPING_COUNTER_REFILL,
JUMP_SPEED_TABLE.size() -1
)
if jumping_step > 0:
jumping_step -= 1
return JUMP_SPEED_TABLE[jumping_step] * JUMPING_SPEED * -1
else:
end_jump()
return velocity.y
func end_jump():
jumping = false
jumping_step = -1
jump_key_counter = 0
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:
if Input.is_action_just_pressed("jump" + action_suffix): if Input.is_action_just_pressed("jump" + action_suffix):
pass if is_on_floor():
elif Input.is_action_just_released("jump" + action_suffix) and velocity.y < 0.0: if not jumping:
# The player let go of jump early, reduce vertical momentum. jumping = true
pass jumping_step = JUMP_SPEED_TABLE.size()-1
jump_key_counter = 0
velocity.y = fall() if Input.is_action_pressed("jump" + action_suffix):
if jumping:
jump_key_counter += 1
else:
jump_key_counter = 0
velocity.y = jump()
velocity.y = fall()
walking = (
Input.is_action_pressed("move_left" + action_suffix) or
Input.is_action_pressed("move_right" + action_suffix)
)
walking = Input.is_action_pressed("move_left" + action_suffix) or Input.is_action_pressed("move_right" + action_suffix)
velocity.x = walk( velocity.x = walk(
Input.get_axis( Input.get_axis(
"move_left" + action_suffix, "move_left" + action_suffix,