diff --git a/princesse.gd b/princesse.gd index de40686..c8bfc90 100644 --- a/princesse.gd +++ b/princesse.gd @@ -11,6 +11,12 @@ var gravity: int = ProjectSettings.get("physics/2d/default_gravity") @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 wall_far_detect_left := $wall_far_detect_left as RayCast2D +@onready var wall_far_detect_left2 := $wall_far_detect_left2 as RayCast2D +@onready var wall_far_detect_left3 := $wall_far_detect_left3 as RayCast2D +@onready var wall_far_detect_right := $wall_far_detect_right as RayCast2D +@onready var wall_far_detect_right2 := $wall_far_detect_right2 as RayCast2D +@onready var wall_far_detect_right3 := $wall_far_detect_right3 as RayCast2D @onready var ground_far_detect := $ground_far_detect as RayCast2D @onready var ground_far_detect2 := $ground_far_detect2 as RayCast2D @@ -30,7 +36,7 @@ var DASH_SPEED = WALKING_SPEED * 2 @export var X_SPEED_TABLE = [0, 0.1, 0.15, 0.3, 0.4, 0.7, 1] @export var X_SPEED_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 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.2, 0.3, 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] @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] @@ -85,6 +91,8 @@ var jump_key_counter : int = 0 # Où en est-on du refil ? var collide_ground_far_detect = false # est-ce que les collisioneurs du sol sont en contact avec ? # variables d'état relatives au kick mural +var collide_wall_far_detect = false # est-ce que les collisioneurs du sol sont en contact avec ? +var need_kicking : bool = false # Le joueur veut-il sauter et peut il ? var kicking : bool = false var kick_step : int = -1 var kick_direction : int = 1 @@ -122,6 +130,7 @@ func copy_from(other : Princess): init_direction_change = other.init_direction_change jumping = other.jumping need_jump = other.need_jump + need_kicking = other.need_kicking jumping_step = other.jumping_step jump_key_counter = other.jump_key_counter kicking = other.kicking @@ -321,18 +330,16 @@ func kick() -> void: if not kicking or dashing: return - var substract := 0 if not is_on_ceiling() and jump_key_counter > last_kick_key_counter and jump_key_counter < KICK_REFILL_MAX_AMOUNT : last_kick_key_counter = jump_key_counter kick_step = KICK_SPEED_TABLE.size() -1 - substract = (last_kick_key_counter +1) /20 else: last_kick_key_counter = 1000 if kick_step > 0: kick_step -= 1 - velocity.y = (KICK_SPEED_TABLE[kick_step] - substract) * JUMPING_SPEED * -1 * KICK_JUMP_LIMITER - velocity.x = (KICK_SPEED_TABLE[kick_step] - substract) * WALKING_SPEED * kick_direction + velocity.y = KICK_SPEED_TABLE[kick_step] * JUMPING_SPEED * -1 * KICK_JUMP_LIMITER + velocity.x = KICK_SPEED_TABLE[kick_step] * WALKING_SPEED * kick_direction else: cancel_kick() @@ -413,19 +420,29 @@ func read_input() -> void: # Peut-il sauter ? if not kicking and collide_ground_far_detect or (is_on_floor() or get_coyote(coyote_ground)): need_jump=true + need_kicking=false else: need_jump=false # Peut-il kicker ? - if get_coyote(coyote_grab): - if not kicking: - kicking=true - coyote_grab = [false] - last_kick_key_counter = 0 - kick_step = KICK_SPEED_TABLE.size()-1 - if pressing_wall_left: - kick_direction = 1 - else: - kick_direction = -1 + if not kicking and (collide_wall_far_detect or get_coyote(coyote_grab)): + need_kicking=true + need_jump=false + else: + need_kicking=false + + # Dès qu'il peut et veut kicker, déclencher le kick + if need_kicking and get_coyote(coyote_grab): + if not kicking: + need_kicking=false + kicking=true + coyote_grab = [false] + last_kick_key_counter = 0 + kick_step = KICK_SPEED_TABLE.size()-1 + if pressing_wall_left: + kick_direction = 1 + else: + 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 @@ -521,6 +538,14 @@ func read_input() -> void: func compute_state() -> void: collide_ground_far_detect = ground_far_detect.is_colliding() or ground_far_detect2.is_colliding() + collide_wall_far_detect = ( + wall_far_detect_left.is_colliding() or + wall_detect_left2.is_colliding() or + wall_detect_left3.is_colliding() or + wall_far_detect_right.is_colliding() or + wall_far_detect_right2.is_colliding() or + wall_far_detect_right3.is_colliding() + ) # Met à jour une partie de l'état de la princesse # gestion du coyote time sur le contact au sol coyote_ground.append(is_on_floor()) diff --git a/princesse.tscn b/princesse.tscn index cb5c1b6..8b6e1ac 100644 --- a/princesse.tscn +++ b/princesse.tscn @@ -455,12 +455,12 @@ shape = SubResource("CapsuleShape2D_6r7th") [node name="ground_far_detect" type="RayCast2D" parent="."] position = Vector2(4, 0) -target_position = Vector2(0, 42) +target_position = Vector2(0, 48) collision_mask = 16 [node name="ground_far_detect2" type="RayCast2D" parent="."] position = Vector2(-4, 0) -target_position = Vector2(0, 42) +target_position = Vector2(0, 48) collision_mask = 16 [node name="Death player" type="AnimationPlayer" parent="."] @@ -484,9 +484,9 @@ texture = ExtResource("8_8c83t") offset = Vector2(0, -13) texture_scale = 0.34 -[node name="wall_detect_left2" type="RayCast2D" parent="."] -position = Vector2(0, -6.66667) -target_position = Vector2(-8, 0) +[node name="wall_detect_right" type="RayCast2D" parent="."] +position = Vector2(0, 5) +target_position = Vector2(8, 0) collision_mask = 16 [node name="wall_detect_right2" type="RayCast2D" parent="."] @@ -499,9 +499,14 @@ position = Vector2(0, 16.6667) target_position = Vector2(8, 0) collision_mask = 16 -[node name="wall_detect_right" type="RayCast2D" parent="."] +[node name="wall_detect_left" type="RayCast2D" parent="."] position = Vector2(0, 5) -target_position = Vector2(8, 0) +target_position = Vector2(-8, 0) +collision_mask = 16 + +[node name="wall_detect_left2" type="RayCast2D" parent="."] +position = Vector2(0, -6.66667) +target_position = Vector2(-8, 0) collision_mask = 16 [node name="wall_detect_left3" type="RayCast2D" parent="."] @@ -509,9 +514,32 @@ position = Vector2(0, 16.6667) target_position = Vector2(-8, 0) collision_mask = 16 -[node name="wall_detect_left" type="RayCast2D" parent="."] -position = Vector2(0, 5) -target_position = Vector2(-8, 0) +[node name="wall_far_detect_left" type="RayCast2D" parent="."] +target_position = Vector2(-30, 0) +collision_mask = 16 + +[node name="wall_far_detect_left2" type="RayCast2D" parent="."] +position = Vector2(0, -15) +target_position = Vector2(-30, 0) +collision_mask = 16 + +[node name="wall_far_detect_left3" type="RayCast2D" parent="."] +position = Vector2(0, 24) +target_position = Vector2(-30, 0) +collision_mask = 16 + +[node name="wall_far_detect_right" type="RayCast2D" parent="."] +target_position = Vector2(30, 0) +collision_mask = 16 + +[node name="wall_far_detect_right2" type="RayCast2D" parent="."] +position = Vector2(0, -16) +target_position = Vector2(30, 0) +collision_mask = 16 + +[node name="wall_far_detect_right3" type="RayCast2D" parent="."] +position = Vector2(0, 24) +target_position = Vector2(30, 0) collision_mask = 16 [connection signal="animation_finished" from="Death player" to="." method="_on_death_player_animation_finished"]