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

public class GlobalVariables : MonoBehaviour {
    public static bool paused = true;
    public GameObject mPlayer;
    public static float maxSize = 4f;
    public static float minSize = 2f;
    public GameObject bonusSphere;

    public float shotTimer = 0f;
    float TTShoot = 5f;

    private void Awake()
    {
        Observer.gameInitiatedHandler += OnGameInitiated;
        Observer.gameOverHandler += OnGameOver;
        Observer.gameResetHandler += OnGameReset;
        Observer.mouseUpHandler += OnMouseUp;
    }

    void OnGameInitiated()
    {
        mPlayer.SetActive(true);
        paused = false;
    }

    void OnGameOver()
    {
        mPlayer.SetActive(false);
    }

    void OnGameReset()
    {
        paused = true;
    }

    private void OnMouseUp()
    {
        if (shotTimer >= TTShoot)
        {
            Observer.OnShot(this.mPlayer.transform.position);
            shotTimer = 0f;
        }
    }

    private void Update()
    {
        if (paused) return;
        if (shotTimer < TTShoot)
        {
            shotTimer += Time.deltaTime;
            Observer.OnShotBar(shotTimer);
        }
    }
}
