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

public class WaveController : MonoBehaviour {

	public float moveHeight;
	public float waveTime;
	public float variation;

	private float newHeight, shiftX;
	private BuoyancyEffector2D buoyancy;

	float randomFlow;

	void Start () {
		buoyancy = gameObject.GetComponent<BuoyancyEffector2D>();
		StartCoroutine(RandomNewHeight());
	}
	
	IEnumerator RandomNewHeight() {
		newHeight = moveHeight * (Random.Range(1,variation)/variation);
		shiftX = moveHeight / 2.0f * (Random.Range(1,variation)/variation);
		randomFlow = Random.Range(55,85);
		buoyancy.flowAngle = randomFlow;
		iTween.MoveBy(gameObject, iTween.Hash("x", shiftX, "y", -newHeight, "time", waveTime/2.0f, "easeType", iTween.EaseType.easeInOutSine));
		yield return new WaitForSeconds(waveTime/2.0f);
		randomFlow = Random.Range(125,155);
		buoyancy.flowAngle = randomFlow;
		iTween.MoveBy(gameObject, iTween.Hash("x", -shiftX, "y", newHeight, "time", waveTime/2.0f, "easeType", iTween.EaseType.easeInOutSine));
		yield return new WaitForSeconds(waveTime/2.0f);
		StartCoroutine(RandomNewHeight());
	}
}
