extends CharacterBody2D

@onready var sprite_2d: Sprite2D = $Sprite2D

const SPEED = 300.0
const JUMP_VELOCITY = -420.0


func _physics_process(delta: float) -> void:
	if not is_on_floor():
		velocity += get_gravity() / 2 * delta

	if Input.is_action_just_pressed("ui_accept") and is_on_floor():
		velocity.y = JUMP_VELOCITY

	var direction := Input.get_axis("ui_left", "ui_right")
	if direction:
		velocity.x = direction * SPEED
		sprite_2d.flip_h = direction > 0
	else:
		velocity.x = move_toward(velocity.x, 0, SPEED)
	move_and_slide()
