princesse/comamndes: ajout du dash
La princesse peut dasher à volonté pour l'instant. Il reste à relier ça avec la consomation de fromage pour les pêts.
This commit is contained in:
93
princesse.gd
93
princesse.gd
@@ -16,14 +16,16 @@ var gravity: int = ProjectSettings.get("physics/2d/default_gravity")
|
|||||||
# Constantes de déplacement à pimper dans l'inspecteur
|
# Constantes de déplacement à pimper dans l'inspecteur
|
||||||
#
|
#
|
||||||
################################################################################
|
################################################################################
|
||||||
@export var WALKING_SPEED = 400
|
@export var WALKING_SPEED = 155
|
||||||
@export var FALLING_SPEED = 400
|
@export var FALLING_SPEED = 230
|
||||||
@export var JUMPING_SPEED = 400
|
@export var JUMPING_SPEED = 220
|
||||||
|
var DASH_SPEED = WALKING_SPEED * 2
|
||||||
@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 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.6, 0.7, 0.8, 0.9, 1, 1, 1, 1, 1, 1]
|
@export var KICK_SPEED_TABLE = [0.6, 0.7, 0.8, 0.9, 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]
|
||||||
|
|
||||||
# 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
|
||||||
@@ -76,6 +78,12 @@ var falling_step : int = -1 # Où en est la princess dans son acceleration de ch
|
|||||||
var pressing_wall = false # Princesse est elle en contact avec un mur ?
|
var pressing_wall = false # Princesse est elle en contact avec un mur ?
|
||||||
var grab_wall = false # Je joueur veut-il et peut-il s'accrocher au mur ?
|
var grab_wall = false # Je joueur veut-il et peut-il s'accrocher au mur ?
|
||||||
|
|
||||||
|
# Variables d'état relative au dash
|
||||||
|
var dashing : bool = false
|
||||||
|
var dash_step : int = -1
|
||||||
|
var dash_direction_x : int = 1
|
||||||
|
var dash_direction_y : int = 1
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Gestion d'avec quoi Princesse collisionne
|
# Gestion d'avec quoi Princesse collisionne
|
||||||
@@ -93,7 +101,7 @@ func init_walk_state():
|
|||||||
|
|
||||||
func walk(direction:int) -> float:
|
func walk(direction:int) -> float:
|
||||||
# Fait marcher le personnage.
|
# Fait marcher le personnage.
|
||||||
if kicking:
|
if kicking or dashing:
|
||||||
init_walk_state()
|
init_walk_state()
|
||||||
return velocity.x
|
return velocity.x
|
||||||
|
|
||||||
@@ -185,7 +193,7 @@ func walk(direction:int) -> float:
|
|||||||
|
|
||||||
func fall() -> float:
|
func fall() -> float:
|
||||||
# fait tomber princesse
|
# fait tomber princesse
|
||||||
if jumping or kicking:
|
if jumping or kicking or dashing:
|
||||||
falling_step = -1
|
falling_step = -1
|
||||||
return velocity.y
|
return velocity.y
|
||||||
if is_on_floor_only():
|
if is_on_floor_only():
|
||||||
@@ -210,7 +218,7 @@ func fall() -> float:
|
|||||||
|
|
||||||
func jump() -> float:
|
func jump() -> float:
|
||||||
# fait sauter princesse
|
# fait sauter princesse
|
||||||
if not jumping or kicking:
|
if not jumping or kicking or dashing:
|
||||||
return velocity.y
|
return velocity.y
|
||||||
|
|
||||||
if not is_on_ceiling() and jump_key_counter > 0 and jump_key_counter % JUMPING_KEY_COUNTER_THRESHOLD == 0:
|
if not is_on_ceiling() and jump_key_counter > 0 and jump_key_counter % JUMPING_KEY_COUNTER_THRESHOLD == 0:
|
||||||
@@ -226,24 +234,51 @@ func jump() -> float:
|
|||||||
end_jump()
|
end_jump()
|
||||||
return velocity.y
|
return velocity.y
|
||||||
|
|
||||||
|
func end_jump():
|
||||||
|
# termine le saut de Princesse
|
||||||
|
jumping = false
|
||||||
|
jumping_step = -1
|
||||||
|
jump_key_counter = 0
|
||||||
|
|
||||||
func kick() -> void:
|
func kick() -> void:
|
||||||
# fait sauter princesse
|
# fait kicker la princesse
|
||||||
if not kicking:
|
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:
|
||||||
kick_step = -1
|
kick_step = -1
|
||||||
kicking=false
|
kicking=false
|
||||||
|
velocity.rotated(0)
|
||||||
|
|
||||||
|
func dash() -> void:
|
||||||
|
# fait dasher la princesse
|
||||||
|
if not dashing:
|
||||||
|
return
|
||||||
|
|
||||||
|
if dash_step >= 0:
|
||||||
|
dash_step -= 1
|
||||||
|
var doubley = 1
|
||||||
|
var doublex = 1
|
||||||
|
if abs(dash_direction_y) and not abs(dash_direction_x):
|
||||||
|
doubley=1.1
|
||||||
|
if abs(dash_direction_x) and not abs(dash_direction_y):
|
||||||
|
doublex=1.1
|
||||||
|
velocity.y = DASH_SPEED_TABLE[dash_step] * DASH_SPEED * dash_direction_y * doubley
|
||||||
|
velocity.x = DASH_SPEED_TABLE[dash_step] * DASH_SPEED * dash_direction_x * doublex
|
||||||
|
else:
|
||||||
|
cancel_dash()
|
||||||
|
|
||||||
|
func cancel_dash() -> void:
|
||||||
|
dash_step = -1
|
||||||
|
dashing=false
|
||||||
|
|
||||||
func end_jump():
|
|
||||||
# termine le saut de Princesse
|
|
||||||
jumping = false
|
|
||||||
jumping_step = -1
|
|
||||||
jump_key_counter = 0
|
|
||||||
|
|
||||||
func choose_animation_orientation() -> void:
|
func choose_animation_orientation() -> void:
|
||||||
# Oriente l'animation correctement en fonction de laquelle on joue et de
|
# Oriente l'animation correctement en fonction de laquelle on joue et de
|
||||||
@@ -277,7 +312,8 @@ func move_and_handle_collisions() -> void:
|
|||||||
layer_of_collision = PhysicsServer2D.body_get_collision_layer(tile_rid)
|
layer_of_collision = PhysicsServer2D.body_get_collision_layer(tile_rid)
|
||||||
if layer_of_collision == PICS_BLOCK_LAYER:
|
if layer_of_collision == PICS_BLOCK_LAYER:
|
||||||
get_tree(). reload_current_scene()
|
get_tree(). reload_current_scene()
|
||||||
|
if dashing and not is_on_floor():
|
||||||
|
cancel_dash()
|
||||||
|
|
||||||
func get_coyote(table: Array):
|
func get_coyote(table: Array):
|
||||||
var result = false
|
var result = false
|
||||||
@@ -339,6 +375,34 @@ func read_input() -> void:
|
|||||||
if kicking:
|
if kicking:
|
||||||
direction = kick_direction
|
direction = kick_direction
|
||||||
|
|
||||||
|
if Input.is_action_just_pressed("dash" + action_suffix):
|
||||||
|
if not dashing:
|
||||||
|
dashing = true
|
||||||
|
dash_step = DASH_SPEED_TABLE.size()-1
|
||||||
|
var axis_x = Input.get_axis(
|
||||||
|
"move_left" + action_suffix,
|
||||||
|
"move_right" + action_suffix
|
||||||
|
)
|
||||||
|
if not is_zero_approx(axis_x):
|
||||||
|
if axis_x < 0:
|
||||||
|
dash_direction_x = -1
|
||||||
|
else:
|
||||||
|
dash_direction_x = 1
|
||||||
|
else:
|
||||||
|
dash_direction_x = 0
|
||||||
|
var axis_y = Input.get_axis(
|
||||||
|
"move_up" + action_suffix,
|
||||||
|
"move_down" + action_suffix
|
||||||
|
)
|
||||||
|
if not is_zero_approx(axis_y):
|
||||||
|
if axis_y < 0:
|
||||||
|
dash_direction_y = -1
|
||||||
|
else:
|
||||||
|
dash_direction_y = 1
|
||||||
|
else:
|
||||||
|
dash_direction_y = 0
|
||||||
|
print("dash x", axis_x, "y", axis_y)
|
||||||
|
|
||||||
func compute_state() -> void:
|
func compute_state() -> void:
|
||||||
# Met à jour une partie de l'état de la princesse
|
# Met à jour une partie de l'état de la princesse
|
||||||
# gestion du coyote time sur le contact au sol
|
# gestion du coyote time sur le contact au sol
|
||||||
@@ -378,6 +442,7 @@ func _physics_process(delta: float) -> void:
|
|||||||
velocity.y = fall()
|
velocity.y = fall()
|
||||||
velocity.x = walk(direction)
|
velocity.x = walk(direction)
|
||||||
kick()
|
kick()
|
||||||
|
dash()
|
||||||
move_and_handle_collisions()
|
move_and_handle_collisions()
|
||||||
play_animation()
|
play_animation()
|
||||||
|
|
||||||
|
|||||||
@@ -204,9 +204,6 @@ collision_mask = 113
|
|||||||
slide_on_ceiling = false
|
slide_on_ceiling = false
|
||||||
floor_constant_speed = true
|
floor_constant_speed = true
|
||||||
script = ExtResource("1_dkp7s")
|
script = ExtResource("1_dkp7s")
|
||||||
WALKING_SPEED = 155
|
|
||||||
FALLING_SPEED = 230
|
|
||||||
JUMPING_SPEED = 220
|
|
||||||
KICK_JUMP_LIMITER = 0.7
|
KICK_JUMP_LIMITER = 0.7
|
||||||
COYOTE_LENGTH = 5
|
COYOTE_LENGTH = 5
|
||||||
WALK_INCR_AIR = 4
|
WALK_INCR_AIR = 4
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ move_left={
|
|||||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null)
|
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
crouch={
|
move_down={
|
||||||
"deadzone": 0.5,
|
"deadzone": 0.5,
|
||||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":0,"key_label":4194322,"unicode":0,"echo":false,"script":null)
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":0,"key_label":4194322,"unicode":0,"echo":false,"script":null)
|
||||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":12,"pressure":0.0,"pressed":true,"script":null)
|
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":12,"pressure":0.0,"pressed":true,"script":null)
|
||||||
|
|||||||
Reference in New Issue
Block a user