gravité: appliquée de la même manière que la marche
Nombre fixe de frames pour l'accélération. Il reste à appliquer le saut et on à la base.
This commit is contained in:
25
princesse.gd
25
princesse.gd
@@ -12,13 +12,11 @@ var gravity: int = ProjectSettings.get("physics/2d/default_gravity")
|
|||||||
var _double_jump_charged := false
|
var _double_jump_charged := false
|
||||||
|
|
||||||
@export var WALKING_SPEED = 400
|
@export var WALKING_SPEED = 400
|
||||||
|
@export var FALLING_SPEED = 400
|
||||||
@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 X_SPEED_AIR_DECEL =[0, 0.2, 0.6, 0.8, 0.9, 0.9, 1,
|
@export var X_SPEED_AIR_DECEL =[0, 0.1, 0.6, 1]
|
||||||
1.1, 1.1, 1.1, 1.2, 1.2, 1.2,
|
@export var FALL_SPEED_TABLE = [0, 0.1, 0.15, 0.2, 0.3, 0.6, 0.9, 1]
|
||||||
1.2, 1.2, 1.3, 1.4, 1.5, 1.6,
|
|
||||||
1.8, 1.9, 3]
|
|
||||||
@export var FALL_SPEED_TABLE = [0, 0.4]
|
|
||||||
@export var JUMP_SPEED_TABLE = [0, 0.4, 0.8, 1.2, 1.6, 2, 2.4, 2.8, 3, 3, 4, 5]
|
@export var JUMP_SPEED_TABLE = [0, 0.4, 0.8, 1.2, 1.6, 2, 2.4, 2.8, 3, 3, 4, 5]
|
||||||
@export var KICK_SPEED_TABLE = [0, 0.2, 0.4, 0.6, 1, 1.6, 2.4, 3]
|
@export var KICK_SPEED_TABLE = [0, 0.2, 0.4, 0.6, 1, 1.6, 2.4, 3]
|
||||||
|
|
||||||
@@ -38,6 +36,9 @@ var walking : bool = false
|
|||||||
var walking_step: int = -1
|
var walking_step: int = -1
|
||||||
var init_decel: bool = true
|
var init_decel: bool = true
|
||||||
|
|
||||||
|
var jumping : bool = false
|
||||||
|
var falling_step : int = -1
|
||||||
|
|
||||||
func walk(direction:int) -> int:
|
func walk(direction:int) -> int:
|
||||||
var table = X_SPEED_TABLE
|
var table = X_SPEED_TABLE
|
||||||
if walking:
|
if walking:
|
||||||
@@ -56,14 +57,23 @@ func walk(direction:int) -> int:
|
|||||||
return speed * direction
|
return speed * direction
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
func fall() -> int:
|
||||||
|
if jumping or is_on_floor():
|
||||||
|
falling_step = -1
|
||||||
|
return velocity.y
|
||||||
|
else:
|
||||||
|
falling_step = min(falling_step+1, FALL_SPEED_TABLE.size()-1)
|
||||||
|
return FALL_SPEED_TABLE[falling_step] * FALLING_SPEED
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
if Input.is_action_just_pressed("jump" + action_suffix):
|
if Input.is_action_just_pressed("jump" + action_suffix):
|
||||||
pass
|
pass
|
||||||
elif Input.is_action_just_released("jump" + action_suffix) and velocity.y < 0.0:
|
elif Input.is_action_just_released("jump" + action_suffix) and velocity.y < 0.0:
|
||||||
# The player let go of jump early, reduce vertical momentum.
|
# The player let go of jump early, reduce vertical momentum.
|
||||||
pass
|
pass
|
||||||
# Fall.
|
|
||||||
velocity.y = minf(400, velocity.y + gravity * delta)
|
velocity.y = fall()
|
||||||
|
|
||||||
walking = Input.is_action_pressed("move_left" + action_suffix) or Input.is_action_pressed("move_right" + action_suffix)
|
walking = Input.is_action_pressed("move_left" + action_suffix) or Input.is_action_pressed("move_right" + action_suffix)
|
||||||
velocity.x = walk(
|
velocity.x = walk(
|
||||||
@@ -90,6 +100,7 @@ func _physics_process(delta: float) -> void:
|
|||||||
|
|
||||||
func get_new_animation(is_shooting := false) -> String:
|
func get_new_animation(is_shooting := false) -> String:
|
||||||
var animation_new: String
|
var animation_new: String
|
||||||
|
|
||||||
if is_on_floor():
|
if is_on_floor():
|
||||||
if walking_step > 0:
|
if walking_step > 0:
|
||||||
animation_new = "walk"
|
animation_new = "walk"
|
||||||
|
|||||||
@@ -202,6 +202,7 @@ height = 52.0
|
|||||||
[node name="Princesse" type="CharacterBody2D"]
|
[node name="Princesse" type="CharacterBody2D"]
|
||||||
script = ExtResource("1_dkp7s")
|
script = ExtResource("1_dkp7s")
|
||||||
WALKING_SPEED = 100
|
WALKING_SPEED = 100
|
||||||
|
FALLING_SPEED = 100
|
||||||
|
|
||||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||||
sprite_frames = SubResource("SpriteFrames_q52wx")
|
sprite_frames = SubResource("SpriteFrames_q52wx")
|
||||||
|
|||||||
Reference in New Issue
Block a user