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

public class PoserAss : MonoBehaviour {

	bool isNormal=false;
	private bool[] movements=new bool[64000];
	private int currentPose = 0;


	// Use this for initialization
	void Start () {
	//	InvokeRepeating ("changePose", 1f, 1f);
		StartCoroutine(Pose());
		initPoses ();
	}
	
	// Update is called once per frame
	void Update () {
		GameManager.instance.PoserAssPosition = transform.position.y;
	}

	public void changePose()
	{
		if (isNormal) {
			//GameManager.instance.SpawnManagerInstance.Spawn (movements [currentPose]);
			GameManager.instance.SpawnManagerInstance.Next (movements [currentPose+1]);
			if (movements[currentPose]) {
				assDown ();
			} else {
				AssUp ();
			}
		
			isNormal = false;
			currentPose++;
		} else {
			assNormal ();
			isNormal = true;
		}


//		Vector3 newPos = new Vector3 (transform.position.x, Random.Range (GameManager.instance.MaxDownAss, GameManager.instance.MaxUpAss), transform.position.y);
//		transform.DOMove (newPos, .112f);


	}

	public void assDown()
	{
		moveAss( GameManager.instance.MaxDownAss+0.25f);
	}

	public void AssUp()
	{
		moveAss( GameManager.instance.MaxUpAss);

	}

	public void assNormal()
	{
		moveAss( 2.73f);

	}


	private void moveAss(float assPos)
	{
		DOTween.Kill ("playermove");
		transform.DOMove ( new Vector3 (transform.position.x, assPos, transform.position.y),GameManager.instance.CurrentGameSpeed/2f).SetTarget("playermove");
	
	}

	private void initPoses()
	{
		int n;
		for(n=0;n<64000;n++)
		{
			movements [n] = (0==Random.Range (0, 2));
				}
	}

	IEnumerator Pose() {
		while (!GameManager.instance.GameOver) {
			changePose ();
			yield return new WaitForSeconds (GameManager.instance.CurrentGameSpeed);
		}
	}



}
