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

public class Enemy : MonoBehaviour {

	//Pick a layer
	public Dictionary<string, GameObject> layers = new Dictionary<string, GameObject>();
	public string layerName = "red";
	public string[] layerNameArray = {"red", "blue", "green", "yellow"};
	
	//Color vars
	public string color;

	//Death
	public GameObject explosion;

	//Movement
	public float localX;
	public float localZ;

	public int damageAmount = 0;
	
	
	// Use this for initialization
	void Start () {
		layers.Add ("red", GameObject.Find ("RedLayer"));
		layers.Add ("blue", GameObject.Find ("BlueLayer"));
		layers.Add ("green", GameObject.Find ("GreenLayer"));
		layers.Add ("yellow", GameObject.Find ("YellowLayer"));
		
		//Random starting position
		layerName = layerNameArray[Random.Range (0, layerNameArray.Length)];

		//Animate based on color
		GetComponent<Animator>().SetTrigger(color);
	}
	
	// Update is called once per frame
	void Update () {

	}

	public string getColor(){
		return color;
	}

	public void killMe(bool getsPoints){
		explosion.transform.position = gameObject.transform.position;
		Instantiate(explosion);
		Destroy (gameObject);//Kill the enemy
		
		//Add points
		if(getsPoints){
			GameObject.Find ("ScriptContainer").GetComponent<ScoreManager>().killedEnemy(name);
		}

		//Free up the dictionary of enemies
		GameObject.Find ("ScriptContainer").GetComponent<EnemyFactory>().enemyKilled(color);
	}

	public void setColor(string color){
		this.color = color;
	}

}
