using UnityEngine;
using System.Collections;

public class Level1 : MonoBehaviour {

    public float timeToStart = 1;
    public float fadeSpeed = 0.3f;

    private Texture2D fadeTexture;
    private float alpha = 1.0f;
    private int fadeDir = -1;
    private bool winning = false;
    private bool losing = false;

    void Start()
    {
        fadeTexture = new Texture2D(1,1);
        fadeTexture.SetPixel(0, 0, Color.black);
    }
	
	// Update is called once per frame
	void Update () 
    {
        if (timeToStart != -1)
        {
            timeToStart -= Time.deltaTime;
            if (timeToStart <= 0)
            {
                timeToStart = -1;
                FlameGUI.PlayMessage("Try to find the exit", 2f);
            }
        }

        if (alpha >= 1.0)
        {
            if (winning)
                Application.LoadLevel("Level2");
            if (losing)
                Application.LoadLevel("Level1");
        }
	}

    void OnGUI()
    {
        alpha += fadeDir * fadeSpeed * Time.deltaTime;
        alpha = Mathf.Clamp01(alpha);

        Color col = new Color(0, 0, 0, alpha);
        GUI.color = col;
        GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), fadeTexture);
    }

    void Win()
    {
        winning = true;
        fadeDir = 1;
    }

    void Lose()
    {
        losing = true;
        fadeDir = 1;
    }
}
