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

public class GameManager : MonoBehaviour {

    public static GameManager instance;

    //wieviele patienten
    public int patienten;
    public int patientenkonvertiert;
    public int maxpatienten;

    //Welches LEvel bin ich
    public int aktuelleslvl;

    //Drehbewegung
    public float dehbewegung;
    //Movement
    public float moveSpeed = 5;
    // loook
    public Quaternion LOOK;

    // Richtung facing
    public float xRichtung;
    public float yRichtung;
    public bool right;
    public bool up;

    //Timer
    public float activebeacons;
    public float beacontimer;
    private float beaconprogress = 0.5f;
    public float beaconamount;
    

    //Infektionsstärke | Anzahl der Infizierten
    public float infectionPower;

    //Aktionspunkte
    public float curap;
    public float maxap = 100;


    void Awake()
    {
        if (instance == null)
        {
            instance = this;
            DontDestroyOnLoad(gameObject);
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }
        infectionPower = 1;
        beaconamount = 0;
        activebeacons = 0;
    }
    // Use this for initialization
    void Start () {

        
        maxap = 100;
        curap = maxap;
        aktuelleslvl += 0;
        maxpatienten = patienten;
        



    }

	// Update is called once per frame
	void Update () {

        //Movement Vector and true false direction looking
        Vector3 movement_vector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
        //Check, in welche Rintung sich der Spieler bewegt
        if (movement_vector != Vector3.zero)
        {
            xRichtung = movement_vector.x;
            yRichtung = movement_vector.z;
        }
        if (xRichtung > 0) { right = true; }
        if (xRichtung < 0) { right = false; }
        if (yRichtung > 0) { up = true; }
        if (yRichtung < 0) { up = false; }

        if (Input.GetButtonUp("Fire3"))
        {
            SceneManager.LoadScene("lvl_02");
            
            
        }
        
    

        //Wenn die Leiste voll ist -> Spiel ist vorbei GameOver neue Scene
        beaconamount += (beaconprogress * Time.deltaTime * activebeacons);

        if (beaconamount >= 100 || infectionPower <= 0)
        {
            //Game Over
            SceneManager.LoadScene("GameOver");
            Destroy(this);
        }


        if ( patientenkonvertiert == maxpatienten )
        {
            SceneManager.LoadScene("GameOverGood");
            Destroy(this);
        }


        if (Input.GetButtonUp("Fire2"))
        {
            moveSpeed += 2;
            dehbewegung += 0.4f;
            beaconamount -= 200;

        }
        if (Input.GetButtonUp("Fire3"))
        {
            SceneManager.LoadScene("lvl_02");


        }



    }

}
