using UnityEngine;
using System.Collections;
public enum SideHit{Left,Right,Bottom,None};
public class Chunk : MonoBehaviour
{
	public World w;
	public SideHit sideHit = SideHit.None;
	public Side left;
	public Side right;
	public Side bottom;
	public int XLocation = 0; // used for creating the next tile
	public int YLocation = 0; // used for creating the next tile
	// Use this for initialization
	void Awake() 
	{
		w = GameObject.FindGameObjectWithTag("World").GetComponent<World>();
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	public void DetermineSide()
	{
		if(left !=null)
		{
			if(left.WasHit)
			{
				sideHit = SideHit.Left;
				w.CreateNewChunk(sideHit,this);
			}
		}
		if(right !=null)
		{
			if(right.WasHit)
			{
				sideHit = SideHit.Right;
				w.CreateNewChunk(sideHit,this);
			}
		}
		if(bottom !=null)
		{
			 if(bottom.WasHit)
			{
				sideHit = SideHit.Bottom;
				w.CreateNewChunk(sideHit,this);
			}
		}

	}

	public void LeftAligned()
	{
		Destroy(right.gameObject);
	}
	public void RightAligned()
	{
		Destroy(left.gameObject);
	}
}
