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

public class NeutralRandomMove : MonoBehaviour
{

    int horizontal;
    int temp;
    int vertical;

    void Start()
    {
        temp = (int)UnityEngine.Random.Range(0, 3);
        StartCoroutine(RandomDirection());
    }


    void LateUpdate()
    {

        if (gameObject.tag == "Idle")
        {
            if (temp == 0)
            {
                this.transform.Translate(Vector3.right / 2 * Time.deltaTime);
                GetComponent<SpriteRenderer>().flipX = true;
            }
                
            else if (temp == 1)
            {
                this.transform.Translate(Vector3.left / 2 * Time.deltaTime);
                GetComponent<SpriteRenderer>().flipX = false;
            }
                
            else if (temp == 2)
                this.transform.Translate(Vector3.up / 2 * Time.deltaTime);
            else if (temp == 3)
                this.transform.Translate(Vector3.down / 2 * Time.deltaTime);
        }

        if (gameObject.tag == "Neutral")
        {
            if (temp == 0)
            {
                this.transform.Translate(Vector3.right / 5 * Time.deltaTime);
                GetComponent<SpriteRenderer>().flipX = true;
            }
                
            else if (temp == 1)
            {
                this.transform.Translate(Vector3.left / 5 * Time.deltaTime);
                GetComponent<SpriteRenderer>().flipX = false;
            }
                
            else if (temp == 2)
                this.transform.Translate(Vector3.up / 5 * Time.deltaTime);
            else if (temp == 3)
                this.transform.Translate(Vector3.down / 5 * Time.deltaTime);
        }

    }

    private void OnCollisionEnter(Collision other)
    {
        if (gameObject.tag == "Neutral")
            if (other.gameObject.tag == "Neutral" || other.gameObject.tag == "Wall" || other.gameObject.tag == "Varil" || other.gameObject.tag == "Rocks")
                temp = (temp + 1) % 4;
    }

    private IEnumerator RandomDirection()
    {
        yield return new WaitForSeconds(2);
        temp = (int)UnityEngine.Random.Range(0, 4);
        StartCoroutine(RandomDirection());
    }
}
