using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Robot_BehaviourScript : MonoBehaviour {

    public Vector2 direction;
    private Vector2 location;
    //public Arena arena;
    public Vector2 start_direction;

    public GameObject spriteGO;

    public float size;

    void Start()
    {
        size = 0.16f; //1f / Arena.lengthOfArena;
        //this.GetComponent<Transform>().localScale = new Vector3(size, size, 0);
        direction = start_direction;
        //location = new Vector2(0, Arena.coordinates.Length / 2);
        float xpos = (-(size/2) * (Arena.lengthOfArena-1)) *direction.x;
        this.GetComponent<Transform>().localPosition = new Vector3(xpos, xpos, 0f);

        SpriteRotation();

    }


    public void SpriteRotation()
    {
        spriteGO.GetComponent<Transform>().localEulerAngles = new Vector3(0, 0, -90*direction.x+direction.y*(90-90*direction.y));
    }

    private void Movement()
    {
        if(Input.GetKeyDown(KeyCode.W)) //forward
        {
            Vector3 new_position = GetComponent<Transform>().localPosition;
            new_position.x += direction.x * size/10f;
            new_position.y += direction.y * size/10f;
            GetComponent<Transform>().localPosition = new_position;
        }

        if (Input.GetKeyDown(KeyCode.E)) //Step Right
        {
            Vector3 new_position = GetComponent<Transform>().localPosition;
            new_position.x += direction.y * size / 10f;
            new_position.y -= direction.x * size / 10f;
            GetComponent<Transform>().localPosition = new_position;
        }

        if (Input.GetKeyDown(KeyCode.Q)) //Step Left
        {
            Vector3 new_position = GetComponent<Transform>().localPosition;
            new_position.x -= direction.y * size / 10f;
            new_position.y += direction.x * size / 10f;
            GetComponent<Transform>().localPosition = new_position;
        }

        if (Input.GetKeyDown(KeyCode.D)) //Right
        {
            direction = new Vector2(direction.y, -direction.x);
            SpriteRotation();
        }

        if (Input.GetKeyDown(KeyCode.A)) //Left
        {
            direction = new Vector2(-direction.y, direction.x);
            SpriteRotation();
        }

        if (Input.GetKeyDown(KeyCode.S)) //Turn Around
        {
            direction = new Vector2(-direction.x, -direction.y);
            SpriteRotation();
        }
    }

    public void Win()
    {
        print("WIN!!");
    }

}
