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

public class NewGame : MonoBehaviour {

    public GameObject titulo;
    public GameObject menu;
    public GameObject gordon;
    public Canvas canvas;
    public GameObject spot;

    public float speed = 3;

    float distTitulo;
    float distMenu;
    float tempoTitulo = 3f;

    Vector3 posFinalTitulo = new Vector3(0, 5.6f);
    Vector3 posFinalMenu = new Vector3(-12f, -2.61f);

    bool animando;
    bool instanciou = false;

    public void OnNewGame() {
        animando = true;
        canvas.enabled = false;

        tempoTitulo = Time.time;
        distTitulo = Vector3.Distance(titulo.transform.position, posFinalTitulo);
        distMenu = Vector3.Distance(menu.transform.position, posFinalMenu);

        gordon.GetComponent<SpriteRenderer>().sprite = (Sprite) Resources.Load("gordon2", typeof(Sprite));

    }

    void Update() {
        if (animando && !instanciou) {
            float distCovered = (Time.time - tempoTitulo) * speed;
            titulo.transform.position = Vector3.Lerp(titulo.transform.position, posFinalTitulo, distCovered / distTitulo);
            menu.transform.position = Vector3.Lerp(menu.transform.position, posFinalMenu, distCovered / distMenu);

            if (Time.time - tempoTitulo >= 1f) {
                if (System.DateTime.Now.Hour <= 6 || System.DateTime.Now.Hour >= 20) {
                    Instantiate(Resources.Load("dialogoNoite"), spot.transform.position, Quaternion.identity);
                } else {
                    Instantiate(Resources.Load("dialogoDia"), spot.transform.position, Quaternion.identity);
                }
                instanciou = true;
            }
        }
    }

    public void AbreJogo() {
        SceneManager.LoadScene(2);
    }

}
