using UnityEngine;
using System.Collections;

public class JogadorVermelho : MonoBehaviour{

    public float velocidade;

    public Transform spritePlayer;
    private Animator animator;
    public Pilha p1 = new Pilha();

    // Use this for initialization
    void Start() {
        animator = spritePlayer.GetComponent<Animator>();
        //p1 = p1.GetComponent<Pilha>();
    }

    // Update is called once per frame
    void Update() {
        Movimentacao();
    }

    void Movimentacao()
    {
        if (Input.GetAxisRaw("HorizontalLetra") > 0)
        {
            transform.Translate(Vector2.right * velocidade * Time.deltaTime);
        }

        if (Input.GetAxisRaw("HorizontalLetra") < 0)
        {
            transform.Translate(-Vector2.right * velocidade * Time.deltaTime);
        }

        if (Input.GetAxisRaw("VerticalLetra") > 0)
        {
            transform.Translate(Vector2.up * velocidade * Time.deltaTime);
        }

        if (Input.GetAxisRaw("VerticalLetra") < 0)
        {
            transform.Translate(-Vector2.up * velocidade * Time.deltaTime);
        }

        animator.SetFloat("Horizontal", Input.GetAxisRaw("HorizontalLetra"));
        animator.SetFloat("Vertical", Input.GetAxisRaw("VerticalLetra"));
    }

    /*void OnCollisionStay2D(Collision2D co)
    {
        if (co.gameObject.name == "JogadorAzul")
        {
            Debug.Log("LOL");
            co.rigidbody.isKinematic = true;
        }
    }*/
    /*void OnCollisionEnter2D(Collision2D co)
    {
        if (co.gameObject.name == "JogadorAzul")
        {
            Debug.Log("LOL");
            co.rigidbody.isKinematic = true;
        }
    }*/

    /*void OnCollisionExit2D(Collision2D co)
    {
        if (co.gameObject.name == "JogadorAzul")
            co.rigidbody.isKinematic = false;
    }*/

    void OnTriggerEnter2D(Collider2D co)
    {
        Debug.Log("Peak: " + p1.Peek_mystakc().ToString());
        Debug.Log("Cod: " + co.gameObject.tag + " (UnityEngine.GameObject)");
        //Debug.Log("Proximo " + p1.Peek_mystakc().ToString());

        if (co.gameObject.tag + " (UnityEngine.GameObject)" == (p1.Peek_mystakc().ToString()))
        {
            Debug.Log("entrei");

            p1.Pop_mystack();
            //p1.Plota_myStack_Vazia();
            p1.Plota_mystack();
            //p1.Plota_auxstack();
        }

    }
}