using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

public class TitleControl : MonoBehaviour{
    public float Temp1;
    public float TempDarken;
    public int DarkenTimes;
    public float Temp2;
    public Transform dark;
    private bool starting;
    private ParticleSystem ps1;

    public AudioClip clickSound;

    private AudioSource audioSource;
    // Use this for initialization
    void Start ()
    {
        audioSource = GetComponent<AudioSource>();
        ps1 = transform.FindChild("MysticWaves").GetComponent<ParticleSystem>();
        starting = false;
        ScoreManager.Instance.score = 0;
        ScoreManager.Instance.highScore = PlayerPrefs.GetInt("HighScore", 0);
    }
    public bool isStarting()
    {
        return starting;
    }
    void OnMouseDown()
    {
        if (!starting)
        {
            starting = true;
            StartCoroutine(StartGame());

        }
    }

    IEnumerator StartGame()
    {
        audioSource.PlayOneShot(clickSound);
        ps1.Emit(1);
        dark.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 0);
        dark.position = new Vector2(0, dark.position.y);
        //useSprites[i].GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 1);
        yield return new WaitForSeconds(Temp1);
        for (float i = 0; i < TempDarken*DarkenTimes; i += TempDarken)
        {
            dark.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, i / (float)(TempDarken * DarkenTimes));
            yield return new WaitForSeconds(TempDarken);
        }
        dark.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 1);
        SceneManager.LoadSceneAsync("main");
        //Application.LoadLevel("main");


        //mainCamera.GetComponent<Shaker>().StartShake();
        //Destroy(Player.gameObject, 0.5f);
    }
}
