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 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 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
@export var JUMPING_COUNTER_REFILL = 2
@@ -154,8 +154,10 @@ func init_walk_state():
init_decel = false
func walk(direction:int) -> float:
# Fait marcher le personnage.
if kicking or dashing:
# Fait marcher le personnage
# 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()
return velocity.x
@@ -257,7 +259,7 @@ func walk(direction:int) -> float:
func fall() -> float:
# fait tomber princesse
if jumping or kicking or dashing:
falling_step = -1
stop_fall()
return velocity.y
var intertia = 0
if velocity.y < 0:
@@ -276,7 +278,7 @@ func fall() -> float:
falling_step = -1
return velocity.y
else:
if grab_wall and not crouch:
if get_coyote(coyote_grab) and not crouch:
falling_step = max(falling_step-1, 1)
else:
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)
return intertia + FALL_SPEED_TABLE[falling_step] * FALLING_SPEED
func stop_fall() -> void:
falling_step = -1
func jump() -> float:
# fait sauter princesse
if not jumping or kicking or dashing:
@@ -311,26 +316,25 @@ func end_jump():
func kick() -> void:
# fait kicker la princesse
if not kicking or dashing:
kick_step -= 1
kicking = false
return
if kick_step > 0:
kick_step -= 1
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.rotated(45)
else:
cancel_kick()
func cancel_kick() -> void:
kick_step = -1
kicking=false
velocity.rotated(0)
func dash() -> void:
# fait dasher la princesse
if not dashing:
return
if dash_step >= 0:
if dash_step > 0:
dash_step -= 1
velocity.y = DASH_SPEED_TABLE[dash_step] * DASH_SPEED * dash_direction_y
velocity.x = DASH_SPEED_TABLE[dash_step] * DASH_SPEED * dash_direction_x
@@ -365,6 +369,11 @@ func play_animation() -> void:
animation.play()
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
move_and_slide()
for i in get_slide_collision_count():
@@ -391,7 +400,7 @@ func read_input() -> void:
# Le joueur veut-il sauter ou kicker ?
if Input.is_action_just_pressed("jump" + action_suffix):
# 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
else:
need_jump=false
@@ -399,14 +408,12 @@ func read_input() -> void:
if get_coyote(coyote_grab):
if not kicking:
kicking=true
coyote_grab = [false]
kick_step = KICK_SPEED_TABLE.size()-1
if grab_wall:
if pressing_wall_left:
kick_direction = 1
else:
kick_direction = -1
if pressing_wall_left:
kick_direction = 1
else:
kick_direction = direction
kick_direction = -1
# Dès qu'il peut et veut sauter, déclencher le saut
if need_jump and (is_on_floor() or get_coyote(coyote_ground)):
need_jump = false
@@ -461,16 +468,21 @@ func read_input() -> void:
(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:
grab_wall = false
if Input.is_action_just_pressed("dash" + action_suffix):
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(
"move_left" + action_suffix,
"move_right" + action_suffix
@@ -485,17 +497,7 @@ func read_input() -> void:
else:
dash_direction_x = 1
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 axis_y < 0:
dash_direction_y = -1
@@ -503,12 +505,19 @@ func read_input() -> void:
dash_direction_y = 1
else:
dash_direction_y = 0
# Limiter le dash en diagonnale car sinon il est trop grand
# par rapport à un dash dans une seule direction
if dash_direction_x and dash_direction_y:
dash_step = DASH_SPEED_TABLE.size()-3
else:
dash_step = DASH_SPEED_TABLE.size()-1
# 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
# par rapport à un dash dans une seule direction
if dash_direction_x and dash_direction_y:
dash_step = DASH_SPEED_TABLE.size()-2
else:
dash_step = DASH_SPEED_TABLE.size()-1
func compute_state() -> void:
collide_ground_far_detect = ground_far_detect.is_colliding() or ground_far_detect2.is_colliding()
@@ -541,7 +550,6 @@ func compute_state() -> void:
)
pressing_wall = pressing_wall_left or pressing_wall_right
func get_new_animation() -> String:
# Renvoie la bonne annimation en fonction de l'état de la princesse
var animation_new: String
@@ -572,8 +580,6 @@ func _physics_process(_delta: float) -> void:
velocity.y = jump()
velocity.y = fall()
velocity.x = walk(direction)
if grab_wall:
velocity.x *= 0.3
kick()
dash()
move_and_handle_collisions()