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

public class HUD : MonoBehaviour {

	bool isPaused = false;
    bool isInGame = true;
	[SerializeField] private int timeCount = 10;
	[SerializeField] private int maxTime = 10;
	Hero hero;
	[SerializeField] private Texture2D livesThree;
	[SerializeField] private Texture2D livesTwo;
	[SerializeField] private Texture2D livesOne;
	[SerializeField] private Texture2D gearImage;

	// Use this for initialization
	void Start () {
		hero = FindObjectOfType<Hero>();
	}
	
	// Update is called once per frame
	void Update () {
		checkKeys();
	}

	void checkKeys()
	{
		timeCount--;
		if ((Input.GetKey(KeyCode.Escape) || Input.GetButton ("Start")) && timeCount <=0) {
			isPaused = !isPaused;
			timeCount = maxTime;
		}
	}


	void OnGUI()
	{
		if (isPaused){
			if (GUI.Button(new Rect((Screen.width)/2,(Screen.height)/2,200,50),"Resume Game")){
				isPaused = false;
			}
			if (GUI.Button(new Rect((Screen.width)/2,(Screen.height/2)+60,200,50),"Quit Game")){
				Application.Quit ();
			};
		} 
        else if (isInGame)
        {
			if (!hero) return;
			switch (hero.getLives())
			{
			case 1: GUI.DrawTexture(new Rect (0,0,livesOne.width/2,livesOne.height/2),livesOne); break;
			case 2: GUI.DrawTexture(new Rect (0,0,livesOne.width/2,livesOne.height/2),livesTwo); break;
			case 3: GUI.DrawTexture(new Rect (0,0,livesOne.width/2,livesOne.height/2),livesThree); break;
			case 0: break;
			}
			if (hero.hasKey ("Gear"))
			for (int i = 0; i < hero.getKeys ()["Gear"]; i++)
			{
				int placement = livesOne.width/2;
				placement += i * gearImage.width/2;
				GUI.DrawTexture(new Rect (placement,0,gearImage.width/2,gearImage.height/2),gearImage);
			}
        }

	}
}
