2025-01-24 09:53:10 +01:00
|
|
|
extends CharacterBody2D
|
|
|
|
|
2025-01-24 11:38:05 +01:00
|
|
|
const move_speed = 400
|
2025-01-24 12:07:11 +01:00
|
|
|
const acceleration = 0.25
|
|
|
|
const max_boost_speed = 800
|
|
|
|
|
|
|
|
var previous_direction = Vector2.ZERO
|
|
|
|
var boost_speed = 0
|
|
|
|
|
2025-01-24 09:53:10 +01:00
|
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
|
|
move_and_slide()
|
|
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
|
|
var direction : Vector2 = Vector2.ZERO
|
|
|
|
direction.x = Input.get_action_raw_strength("BOUGER_DROITE") - Input.get_action_raw_strength("BOUGER_GAUCHE")
|
|
|
|
direction.y = Input.get_action_raw_strength("BOUGER_BAS") - Input.get_action_raw_strength("BOUGER_HAUT")
|
|
|
|
|
2025-01-24 12:07:11 +01:00
|
|
|
|
|
|
|
if direction != Vector2.ZERO:
|
|
|
|
if direction == previous_direction:
|
|
|
|
boost_speed = min(boost_speed + acceleration, max_boost_speed - move_speed)
|
|
|
|
else:
|
|
|
|
boost_speed = 0
|
|
|
|
previous_direction = direction
|
|
|
|
velocity = direction * (move_speed + boost_speed)
|
|
|
|
print(velocity)
|
2025-01-24 11:38:05 +01:00
|
|
|
pass
|