princess/saut du mur: prise en compte du feedback

avant jouer au clavier, c'était impossible. Voic les améliorations:

- une fois que le joueur a décidé de se coller au mur, on le laisse
  collé tant qut'il ne décide pas d'en partir volontairement.
- j'ai rajouté des ray_cast à la tête et aux pieds de chaque côté pour
  que l'on puisse continuer de wall jumper jusqu'au bout
- si au cours d'un dash ou d'un kick on s'écrase contre le mur, la
  princesse s'y colle toute seule.
- faire flèche du bas permet d'accélérer la chute.
This commit is contained in:
Thomas Lavocat
2023-05-11 19:35:30 +02:00
parent 2307fdd112
commit 6336909379
2 changed files with 56 additions and 12 deletions

View File

@@ -7,6 +7,11 @@ class_name Princess extends CharacterBody2D
var gravity: int = ProjectSettings.get("physics/2d/default_gravity")
@onready var wall_detect_left := $wall_detect_left as RayCast2D
@onready var wall_detect_right := $wall_detect_right as RayCast2D
@onready var wall_detect_left2 := $wall_detect_left2 as RayCast2D
@onready var wall_detect_right2 := $wall_detect_right2 as RayCast2D
@onready var wall_detect_left3 := $wall_detect_left3 as RayCast2D
@onready var wall_detect_right3 := $wall_detect_right3 as RayCast2D
@onready var ground_far_detect := $ground_far_detect as RayCast2D
@onready var animation := $AnimatedSprite2D as AnimatedSprite2D
@onready var camera := $Camera2D as Camera2D
@@ -98,6 +103,9 @@ var dash_direction_x : int = 1
var dash_direction_y : int = 1
var available_dashs = 0
# Variables d'état relative au crouch
var crouch : bool = false
func copy_from(other : Princess):
direction = other.direction
walking = other.walking
@@ -254,7 +262,7 @@ func fall() -> float:
falling_step = -1
return velocity.y
else:
if grab_wall:
if grab_wall and not crouch:
falling_step = max(falling_step-1, 1)
else:
if intertia < 0 and intertia + FALL_SPEED_TABLE[falling_step] * FALLING_SPEED >0:
@@ -329,9 +337,9 @@ func choose_animation_orientation() -> void:
animation.scale.x = -1.0
if get_coyote(coyote_grab):
if wall_detect_left.is_colliding():
if pressing_wall_left:
animation.scale.x = 1
elif wall_detect_right.is_colliding():
elif pressing_wall_right:
animation.scale.x = -1
func play_animation() -> void:
@@ -363,6 +371,9 @@ func read_input() -> void:
if locked:
return
# le joueur veut-il accélérer sa chute si il s'accroche au mur?
crouch = Input.is_action_pressed("move_down" + action_suffix)
# Le joueur veut-il sauter ou kicker ?
if Input.is_action_just_pressed("jump" + action_suffix):
# Peut-il sauter ?
@@ -374,7 +385,7 @@ func read_input() -> void:
if not kicking:
kicking=true
kick_step = KICK_SPEED_TABLE.size()-1
if wall_detect_left.is_colliding():
if pressing_wall_left:
kick_direction = 1
else:
kick_direction = -1
@@ -414,11 +425,16 @@ func read_input() -> void:
# Le joueur veut-il et peut-il s'accrocher au mur ?
if pressing_wall:
grab_wall = (
(pressing_wall_left and walking and direction == -1)
or
(pressing_wall_right and walking and direction == 1)
)
if not grab_wall:
grab_wall = (
(pressing_wall_left and (
walking or kicking or dashing
) and direction == -1)
or
(pressing_wall_right and (
walking or kicking or dashing
) and direction == 1)
)
else:
grab_wall = false
@@ -482,8 +498,16 @@ func compute_state() -> void:
coyote_grab.remove_at(0)
# gestion de l'état de la pression au mur
pressing_wall_left = not is_on_floor() and wall_detect_left.is_colliding()
pressing_wall_right = not is_on_floor() and wall_detect_right.is_colliding()
pressing_wall_left = not is_on_floor() and (
wall_detect_left.is_colliding() or
wall_detect_left2.is_colliding() or
wall_detect_left3.is_colliding()
)
pressing_wall_right = not is_on_floor() and (
wall_detect_right.is_colliding() or
wall_detect_right2.is_colliding() or
wall_detect_right3.is_colliding()
)
pressing_wall = pressing_wall_left or pressing_wall_right

View File

@@ -265,7 +265,7 @@ script = ExtResource("1_dkp7s")
FALLING_SPEED = 200
JUMPING_SPEED = 230
COYOTE_LENGTH = 7
COYOTE_GRAB_LENGTH = 10
COYOTE_GRAB_LENGTH = 14
WALK_INCR_AIR = 4
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
@@ -276,10 +276,30 @@ animation = &"jump_impulsion"
target_position = Vector2(-10, 0)
collision_mask = 16
[node name="wall_detect_left2" type="RayCast2D" parent="."]
position = Vector2(0, -19)
target_position = Vector2(-10, 0)
collision_mask = 16
[node name="wall_detect_left3" type="RayCast2D" parent="."]
position = Vector2(0, 24)
target_position = Vector2(-10, 0)
collision_mask = 16
[node name="wall_detect_right" type="RayCast2D" parent="."]
target_position = Vector2(14, 0)
collision_mask = 16
[node name="wall_detect_right2" type="RayCast2D" parent="."]
position = Vector2(0, -19)
target_position = Vector2(14, 0)
collision_mask = 16
[node name="wall_detect_right3" type="RayCast2D" parent="."]
position = Vector2(0, 24)
target_position = Vector2(14, 0)
collision_mask = 16
[node name="Camera2D" type="Camera2D" parent="."]
zoom = Vector2(2, 2)
position_smoothing_enabled = true