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

namespace Machete {

	public class GameManager : MonoBehaviour {

    public static int Points = 0;
    public static GameManager Instance {
      get { return instance; }
    }
    static GameManager instance;

    public float RemainingRatio {
      get { return 1.0f - (float)remainingTicks / (float)ticksToEnd; }
    }

    [SerializeField]
    int ticksToEnd = 240;
    int remainingTicks;

    void Awake() {
      Points = 0;
      // Singleton it.
      if (instance != null) {
        Destroy(this);
        return;
      }
      instance = this;
    }

    void Start() {
      remainingTicks = ticksToEnd;
      Ticker.Instance.OnTick += OnTick;
    }

    void OnTick() {
      remainingTicks--;
      if (remainingTicks == 0) {
        EndGame();
      }
    }

    public void EndGame() {
      Ticker.Instance.OnTick -= OnTick;
      Ticker.Instance.ToggleStop(true);
      SceneManager.LoadScene("Final");
    }
	}
}
