extends CharacterBody2D


const SPEED = 300.0
const JUMP_VELOCITY = -400.0
var lastdir = "down"

func _physics_process(delta: float) -> void:
	var direction := Input.get_vector("ui_left", "ui_right","ui_up", "ui_down")
	velocity = direction * SPEED
	if direction:
		$AnimatedSprite2D.play("marche_" + lastdir)
		match direction:
			Vector2.UP:
				lastdir = "up"
			Vector2.DOWN:
				lastdir = "down"
			Vector2.LEFT:
				lastdir = "left"
			Vector2.RIGHT:
				lastdir = "right"
	else:
		$AnimatedSprite2D.play("idle_" + lastdir)
	move_and_slide()
