using Godot;
using System;

public partial class Player : CharacterBody2D
{
	[Export] float Speed;
	[Export] AnimationPlayer anim;
	[Export] Camera2D cam;
	
	[ExportGroup("controls")]
	[Export] Control menu;


	public float PixelSize = 1.0f;

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


	
		Vector2 direction = Input.GetVector("left", "right", "up", "down");
		direction = direction.Normalized();
		if (direction != Vector2.Zero)
		{
			velocity = direction * Speed * (float)delta;
		}
		else
		{
			velocity.X = Mathf.MoveToward(Velocity.X, 0, Speed);
			velocity.Y = Mathf.MoveToward(Velocity.Y, 0, Speed);

			velocity = velocity.Round();
		}
		
		
		if(Input.IsActionPressed("quit"))
		{
			Input.MouseMode = Input.MouseModeEnum.Visible;
			anim.Play("paused");
			GetTree().Paused= true;
		}
		else if(velocity.X > 0)
		{
			anim.Play("right");
		}
		else if (velocity.X < 0)
		{
			anim.Play("left");
		}
		else if (velocity.Y > 0)
		{
			anim.Play("down");
		}
		else if (velocity.Y < 0)
		{
			anim.Play("up");
		}
		else
		{
			anim.Play("idle");
			
		}
		

		Velocity = velocity;
		MoveAndSlide();

		Position = Position.Round();
	}
}
