using UnityEngine;
using System.Collections;

public class PowerManager : MonoBehaviour {

	public GameObject pac;
	public GameObject[] monsters;

	public float length;
	public float warningTime;
	public float warningDelay;

	private float time;
	private float warning;
	private bool power;

	private bool blue;
	// Use this for initialization
	void Start () {
		time = 0;
		warning = 0;
		power = false;
		blue = false;
	}
	
	// Update is called once per frame
	void Update () {
		if (power) {
			time += Time.deltaTime;
		}

		if (time >= length) {
			time = 0;
			warning = 0;
			power = false;
			pac.SendMessage("PowerDone");
			foreach (GameObject monster in monsters) {
				monster.SendMessage("ChangeColorNormal");
				blue = false;
			}
		} else if (time >= warningTime) {
			warning += Time.deltaTime;
			if (warning >= warningDelay) {
				warning = 0;
				foreach (GameObject monster in monsters) {
					if (blue) {
						monster.SendMessage("ChangeColorNormal");
					} else {
						monster.SendMessage("ChangeColorBlue");
					}
				}
				if (blue) {
					blue = false;
				} else {
					blue = true;

				}
			}
		}
	}

	void PowerPellet() {
		foreach (GameObject monster in monsters) {
			monster.SendMessage("ChangeColorBlue");
			blue = true;
		}
		time = 0;
		power = true;
		pac.SendMessage("PowerStart");
	}
}
	