using UnityEngine;
using System.Collections;

public enum Facing {N = 1, S = -1, E = 2, W = -2, NE = 3, NW = 4, SE = -4, SW = -3};

public class AnimatedObjectScript : MonoBehaviour {

	// Use this for initialization
	private Facing direcao = Facing.S;
	public Facing Direcao{
		get
		{
			return direcao;
		}
		set
		{
			this.direcao = value;
		}
	}

	void Start () {
		this.Direcao = Facing.S;
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	public Facing identificarDirecao(float vSpeed, float hSpeed){
		Facing retorno;
		if(hSpeed == 0){
			if(vSpeed > 0){ //moving north
				retorno = Facing.N;
			} else { //moving south
				retorno = Facing.S;
			}
		} else if (hSpeed > 0) { //moving East
			if (vSpeed == 0){
				retorno = Facing.E;
			} else if (vSpeed > 0){
				retorno = Facing.NE;
			} else {
				retorno = Facing.SE;
			}
		} else { //moving West
			if (vSpeed == 0) {
				retorno = Facing.W;
			} else if (vSpeed > 0){
				retorno = Facing.NW;
			} else {
				retorno = Facing.SW;
			}
		}
		return retorno;
	}

	public Vector2 retornarDirecao(){
		Vector2 retorno;
		switch (Direcao) {
			case Facing.N: retorno = new Vector2(0, 1); break;
			case Facing.S: retorno = new Vector2(0, -1); break;
			case Facing.E: retorno = new Vector2(1, 0); break;
			case Facing.W: retorno = new Vector2(-1, 0); break;
			case Facing.NE: retorno = new Vector2(1, 1); break;
			case Facing.NW: retorno = new Vector2(-1, 1); break;
			case Facing.SE: retorno = new Vector2(1, -1); break;
			case Facing.SW: retorno = new Vector2(-1, -1); break;
			default: retorno = new Vector2(0, -1); break; //default is south, just to be sure it returns something.
		}
		retorno.Normalize();
		return retorno;
	}
}
