39 lines
1.1 KiB
GDScript
39 lines
1.1 KiB
GDScript
extends CharacterBody2D
|
|
|
|
const move_speed = 400
|
|
const acceleration = 0.25
|
|
const max_boost_speed = 800
|
|
|
|
var previous_direction = Vector2.ZERO
|
|
var boost_speed = 0
|
|
var flute = null
|
|
|
|
func _ready() -> void:
|
|
flute = load("res://Instrument/Flute.gd").new()
|
|
flute._init()
|
|
|
|
|
|
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")
|
|
|
|
|
|
if direction != Vector2.ZERO:
|
|
if direction.normalized() == previous_direction.normalized():
|
|
if direction.x != 0 and direction.y != 0:
|
|
boost_speed = min(boost_speed + acceleration / 16, (max_boost_speed - move_speed) / 8)
|
|
else:
|
|
boost_speed = min(boost_speed + acceleration, max_boost_speed - move_speed)
|
|
else:
|
|
boost_speed = 0
|
|
|
|
previous_direction = direction
|
|
velocity = direction * (move_speed + boost_speed)
|
|
|
|
if Input.is_action_just_pressed("JOUER_MUSIQUE"):
|
|
flute.jouer_melodie(position)
|
|
pass
|