princesse/contrôles: réparer kick et dash

Les deux fonctionalités étaient cassées, mais ensemble.
Donc le wall kick, quand la princesse est au mur, le joueur peut
maintenant donner une direction et à le temps de la maintenir sans que
la princesse sorte de se position "collée au mur". Et ce pendant 20
frames soit 333ms. Une fois passé ce délai, la princesse se décolera du
mur. Une fois décollée, rien ne sert de sauter, mais ça se voit.

Vu que le joueur a le temps de pointer dans une direction pour kicker,
alors, il en va de même pour le dash. J'ai supprimé les rêgles complexes
qui liaent le dash au wall hug. Maintenant, le joueur doit pointer dans
une direction pour que le dash ait lieu correctement. Si le joueur ne
pointe pas dans une direction, alors le dash ne se produit pas.

Plus quelques autres corrections:
Le dash counter passait à -1 et donc faisait boucler la dash speed sur
la fin de l'execution. C'est corrigé. J'ai aussi rajouté de la durée de
dash globalement c'est plus agréable.
This commit is contained in:
Thomas Lavocat
2023-06-04 21:29:10 +02:00
parent d92e35278f
commit 9e12d98c69
2 changed files with 48 additions and 42 deletions

View File

@@ -32,7 +32,7 @@ var DASH_SPEED = WALKING_SPEED * 2
@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.1, 0.2, 0.5, 0.6, 0.7, 0.8, 0.9, 1] @export var JUMP_SPEED_TABLE = [0, 0.1, 0.2, 0.5, 0.6, 0.7, 0.8, 0.9, 1]
@export var KICK_SPEED_TABLE = [0.5, 0.6, 0.7, 0.8, 0.9, 1, 1, 1, 1, 1, 1, 1, 1] @export var KICK_SPEED_TABLE = [0.5, 0.6, 0.7, 0.8, 0.9, 1, 1, 1, 1, 1, 1, 1, 1]
@export var DASH_SPEED_TABLE = [0.5, 0.6, 0.7, 0.8, 0.9, 1, 1, 1, 1, 1, 2, 2, 2] @export var DASH_SPEED_TABLE = [0.5, 0.6, 0.7, 0.8, 0.9, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3]
# 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
@@ -154,8 +154,10 @@ func init_walk_state():
init_decel = false init_decel = false
func walk(direction:int) -> float: func walk(direction:int) -> float:
# Fait marcher le personnage. # Fait marcher le personnage
if kicking or dashing:
# Le personnage ne se déplace pas dans les cas suivants:
if kicking or kicking or dashing or get_coyote(coyote_grab):
init_walk_state() init_walk_state()
return velocity.x return velocity.x
@@ -257,7 +259,7 @@ func walk(direction:int) -> float:
func fall() -> float: func fall() -> float:
# fait tomber princesse # fait tomber princesse
if jumping or kicking or dashing: if jumping or kicking or dashing:
falling_step = -1 stop_fall()
return velocity.y return velocity.y
var intertia = 0 var intertia = 0
if velocity.y < 0: if velocity.y < 0:
@@ -276,7 +278,7 @@ func fall() -> float:
falling_step = -1 falling_step = -1
return velocity.y return velocity.y
else: else:
if grab_wall and not crouch: if get_coyote(coyote_grab) and not crouch:
falling_step = max(falling_step-1, 1) falling_step = max(falling_step-1, 1)
else: else:
if intertia < 0 and intertia + FALL_SPEED_TABLE[falling_step] * FALLING_SPEED >0: if intertia < 0 and intertia + FALL_SPEED_TABLE[falling_step] * FALLING_SPEED >0:
@@ -284,6 +286,9 @@ func fall() -> float:
falling_step = min(falling_step+1, FALL_SPEED_TABLE.size()-1) falling_step = min(falling_step+1, FALL_SPEED_TABLE.size()-1)
return intertia + FALL_SPEED_TABLE[falling_step] * FALLING_SPEED return intertia + FALL_SPEED_TABLE[falling_step] * FALLING_SPEED
func stop_fall() -> void:
falling_step = -1
func jump() -> float: func jump() -> float:
# fait sauter princesse # fait sauter princesse
if not jumping or kicking or dashing: if not jumping or kicking or dashing:
@@ -311,26 +316,25 @@ func end_jump():
func kick() -> void: func kick() -> void:
# fait kicker la princesse # fait kicker la princesse
if not kicking or dashing: if not kicking or dashing:
kick_step -= 1
kicking = false
return return
if kick_step > 0: if kick_step > 0:
kick_step -= 1 kick_step -= 1
velocity.y = KICK_SPEED_TABLE[kick_step] * JUMPING_SPEED * -1 * KICK_JUMP_LIMITER velocity.y = KICK_SPEED_TABLE[kick_step] * JUMPING_SPEED * -1 * KICK_JUMP_LIMITER
velocity.x = KICK_SPEED_TABLE[kick_step] * WALKING_SPEED * kick_direction velocity.x = KICK_SPEED_TABLE[kick_step] * WALKING_SPEED * kick_direction
velocity.rotated(45)
else: else:
cancel_kick()
func cancel_kick() -> void:
kick_step = -1 kick_step = -1
kicking=false kicking=false
velocity.rotated(0)
func dash() -> void: func dash() -> void:
# fait dasher la princesse # fait dasher la princesse
if not dashing: if not dashing:
return return
if dash_step >= 0: if dash_step > 0:
dash_step -= 1 dash_step -= 1
velocity.y = DASH_SPEED_TABLE[dash_step] * DASH_SPEED * dash_direction_y velocity.y = DASH_SPEED_TABLE[dash_step] * DASH_SPEED * dash_direction_y
velocity.x = DASH_SPEED_TABLE[dash_step] * DASH_SPEED * dash_direction_x velocity.x = DASH_SPEED_TABLE[dash_step] * DASH_SPEED * dash_direction_x
@@ -365,6 +369,11 @@ func play_animation() -> void:
animation.play() animation.play()
func move_and_handle_collisions() -> void: func move_and_handle_collisions() -> void:
if kicking or dashing:
end_jump()
if dashing:
cancel_kick()
# Bouge Princesse et réagis aux éléments avec lesquels elle rentre en collision # Bouge Princesse et réagis aux éléments avec lesquels elle rentre en collision
move_and_slide() move_and_slide()
for i in get_slide_collision_count(): for i in get_slide_collision_count():
@@ -391,7 +400,7 @@ func read_input() -> void:
# Le joueur veut-il sauter ou kicker ? # Le joueur veut-il sauter ou kicker ?
if Input.is_action_just_pressed("jump" + action_suffix): if Input.is_action_just_pressed("jump" + action_suffix):
# Peut-il sauter ? # Peut-il sauter ?
if collide_ground_far_detect or (is_on_floor() or get_coyote(coyote_ground)): if not kicking and collide_ground_far_detect or (is_on_floor() or get_coyote(coyote_ground)):
need_jump=true need_jump=true
else: else:
need_jump=false need_jump=false
@@ -399,14 +408,12 @@ func read_input() -> void:
if get_coyote(coyote_grab): if get_coyote(coyote_grab):
if not kicking: if not kicking:
kicking=true kicking=true
coyote_grab = [false]
kick_step = KICK_SPEED_TABLE.size()-1 kick_step = KICK_SPEED_TABLE.size()-1
if grab_wall:
if pressing_wall_left: if pressing_wall_left:
kick_direction = 1 kick_direction = 1
else: else:
kick_direction = -1 kick_direction = -1
else:
kick_direction = direction
# Dès qu'il peut et veut sauter, déclencher le saut # Dès qu'il peut et veut sauter, déclencher le saut
if need_jump and (is_on_floor() or get_coyote(coyote_ground)): if need_jump and (is_on_floor() or get_coyote(coyote_ground)):
need_jump = false need_jump = false
@@ -461,16 +468,21 @@ func read_input() -> void:
(pressing_wall_right and direction == 1) (pressing_wall_right and direction == 1)
) )
) )
else:
# Désactivation du grab wall
if walking:
if pressing_wall_left and direction == 1:
grab_wall = false
if pressing_wall_right and direction == -1:
grab_wall = false
if kicking or dashing:
grab_wall = false
else: else:
grab_wall = false grab_wall = false
if Input.is_action_just_pressed("dash" + action_suffix): if Input.is_action_just_pressed("dash" + action_suffix):
if not dashing and available_dashs > 0: if not dashing and available_dashs > 0:
Input.start_joy_vibration(0, 1, 0.5, 0.2)
available_dashs -=1
dashing = true
dash_fart.emit()
var axis_x = Input.get_axis( var axis_x = Input.get_axis(
"move_left" + action_suffix, "move_left" + action_suffix,
"move_right" + action_suffix "move_right" + action_suffix
@@ -485,16 +497,6 @@ func read_input() -> void:
else: else:
dash_direction_x = 1 dash_direction_x = 1
else: else:
# Si le joueur tient le mur, alors, il ne faut pas dasher dans
# dans le mur en cas de dash
if grab_wall:
direction = -direction
# Si le joueur n'appuye sur rien, alors dasher en avant par
# défaut
dash_direction_x = direction
# Si le joueur spécifie une commande, alors, ne pas supposer
# Qu'il veuille aller en avant
if not is_zero_approx(axis_y):
dash_direction_x = 0 dash_direction_x = 0
if not is_zero_approx(axis_y): if not is_zero_approx(axis_y):
if axis_y < 0: if axis_y < 0:
@@ -503,10 +505,17 @@ func read_input() -> void:
dash_direction_y = 1 dash_direction_y = 1
else: else:
dash_direction_y = 0 dash_direction_y = 0
# Ne dasher que si une direction est donnée avec le joystick
if dash_direction_x or dash_direction_y:
Input.start_joy_vibration(0, 1, 0.5, 0.2)
available_dashs -=1
dashing = true
dash_fart.emit()
# Limiter le dash en diagonnale car sinon il est trop grand # Limiter le dash en diagonnale car sinon il est trop grand
# par rapport à un dash dans une seule direction # par rapport à un dash dans une seule direction
if dash_direction_x and dash_direction_y: if dash_direction_x and dash_direction_y:
dash_step = DASH_SPEED_TABLE.size()-3 dash_step = DASH_SPEED_TABLE.size()-2
else: else:
dash_step = DASH_SPEED_TABLE.size()-1 dash_step = DASH_SPEED_TABLE.size()-1
@@ -541,7 +550,6 @@ func compute_state() -> void:
) )
pressing_wall = pressing_wall_left or pressing_wall_right pressing_wall = pressing_wall_left or pressing_wall_right
func get_new_animation() -> String: func get_new_animation() -> String:
# Renvoie la bonne annimation en fonction de l'état de la princesse # Renvoie la bonne annimation en fonction de l'état de la princesse
var animation_new: String var animation_new: String
@@ -572,8 +580,6 @@ func _physics_process(_delta: float) -> void:
velocity.y = jump() velocity.y = jump()
velocity.y = fall() velocity.y = fall()
velocity.x = walk(direction) velocity.x = walk(direction)
if grab_wall:
velocity.x *= 0.3
kick() kick()
dash() dash()
move_and_handle_collisions() move_and_handle_collisions()

View File

@@ -434,7 +434,7 @@ script = ExtResource("1_dkp7s")
JUMPING_SPEED = 230 JUMPING_SPEED = 230
KICK_JUMP_LIMITER = 0.75 KICK_JUMP_LIMITER = 0.75
COYOTE_LENGTH = 7 COYOTE_LENGTH = 7
COYOTE_GRAB_LENGTH = 4 COYOTE_GRAB_LENGTH = 20
WALK_INCR_AIR = 4 WALK_INCR_AIR = 4
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]