using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
using UnityEngine.Audio;


public class GameManager :PersistantSingleton<GameManager> {

	public Text ScoreTextPlayer2;
	public GameObject ScoreTextGameObjPlayer2;
	public GameObject Player2ScorePopUp;
	public GameObject Poser;
	[HideInInspector]
	public float PoserAssPosition;

	public float MaxUpAss;
	public float MaxDownAss;

	[HideInInspector]
	public float StepAss;

	public PoserAss MyInstanceOfAss;

	public SpawnManager SpawnManagerInstance;

	private AudioSource Music;


	public float chkPositionErrorLimit=.25f;

	//public float CurrentGameSpeed=2f;
	[HideInInspector]
	public float CurrentGameSpeed=2.12f;
	//public float CurrentGameSpeed=1.06f;
//	public float CurrentGameSpeed=.53f;
//	public float CurrentGameSpeed=.265f;
	//public float CurrentGameSpeed=.13f;
	//public float CurrentGameSpeed=.06f;



	public bool GameOver=false;



	private float startTime;
	private int player2Score=0;

	// Use this for initialization
	void Start () {
		startTime = Time.time;

	//	CurrentGameSpeed=2.12f;
	//	CurrentGameSpeed=.53f;
		CurrentGameSpeed=.50f;
		StepAss = CurrentGameSpeed*2;
		//Music = GetComponent<AudioSource> ();
	//	Music.Play ();


	}
	
	// Update is called once per frame
	void Update () {
		/*
		CurrentGameSpeed -= 0.001f;
		if (CurrentGameSpeed < 0.25f) {
			CurrentGameSpeed = 0.25f;
		}
*/

		//time passed in seconds from the starting of the game
		if ((Time.time - startTime)>212) {
			GameOver = true;
		}



		/*

		float[] spectrum = new float[256];

		AudioListener.GetSpectrumData( spectrum, 0, FFTWindow.Rectangular );

		for( int i = 1; i < spectrum.Length-1; i++ )
		{
			Debug.DrawLine( new Vector3( i - 1, spectrum[i] + 10, 0 ), new Vector3( i, spectrum[i + 1] + 10, 0 ), Color.red );
			Debug.DrawLine( new Vector3( i - 1, Mathf.Log( spectrum[i - 1] ) + 10, 2 ), new Vector3( i, Mathf.Log( spectrum[i] ) + 10, 2 ), Color.cyan );
			Debug.DrawLine( new Vector3( Mathf.Log( i - 1 ), spectrum[i - 1] - 10, 1 ), new Vector3( Mathf.Log( i ), spectrum[i] - 10, 1 ), Color.green );
			Debug.DrawLine( new Vector3( Mathf.Log( i - 1 ), Mathf.Log( spectrum[i - 1] ), 3 ), new Vector3( Mathf.Log( i ), Mathf.Log( spectrum[i] ), 3 ), Color.blue );
		}

*/
		
	}

	public void Player2AddScore(GameObject senderObject)
	{
		//ScoreTextGameObjPlayer2.transform.DOShakePosition (1f);
		player2Score++;
		ScoreTextPlayer2.text = player2Score.ToString();
		//GameObject ScorePop=Instantiate (Player2ScorePopUp, senderObject.transform.position,Quaternion.identity);
		//ScorePop.GetComponent<Player2PointIdendifier> ().GotoPosition = Poser.transform.position;
	}
}
