using Godot;

public partial class Player : CharacterBody2D
{
	[Export] public const float Speed = 50.0f;

	protected AnimatedSprite2D Sprite;

	public override void _Ready()
	{
		base._Ready();

		Sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D");
	}

	public override void _PhysicsProcess(double delta)
	{
		Vector2 velocity = Velocity;

		// Get the input direction and handle the movement/deceleration.
		// As good practice, you should replace UI actions with custom gameplay actions.
		Vector2 direction = Input.GetVector("character_left", "character_right", "character_up", "character_down");
		if (direction != Vector2.Zero)
		{
			velocity.X = direction.X * Speed;
			velocity.Y = direction.Y * Speed;
		}
		else
		{
			velocity.X = Mathf.MoveToward(Velocity.X, 0, Speed);
			velocity.Y = Mathf.MoveToward(Velocity.Y, 0, Speed);
		}

		Velocity = velocity;
		MoveAndSlide();
	}
}