using UnityEngine;
using System.Collections;

public class RepeatingZoomPill : Pill {
	
	private float startZoom = Data.owlHeight;
	private float endZoom = Data.owlHeight / 4.0f;
	private float zoomTime = 1.0f;
	private float timeLeft;
	
	private float angleChange;

	private bool inZoom = true;

	private bool endGame = false;
	private float initialY;
	
	private Camera camera;
	
	public override void attach(World world, Camera camera, Owl owl) {
		timeLeft = zoomTime;
		this.camera = camera;
	}
	
	public override void update(float dt, float totalTimeLeft) {
		timeLeft -= dt;
		Debug.Log ("Time left: " + timeLeft);
		float y;
		if (inZoom) y = Interpolate.EaseOutQuad (startZoom, endZoom - startZoom, zoomTime - timeLeft, zoomTime);
		else y = Interpolate.EaseOutQuad (endZoom, startZoom - endZoom, zoomTime - timeLeft, zoomTime);

		if (timeLeft <= 0.0f) {
			inZoom = !inZoom;
			timeLeft += zoomTime;
		}

		if (totalTimeLeft < zoomTime && !endGame) {
			endGame = true;
			initialY = camera.transform.position.y;
		}
		if (endGame) {
			y = Interpolate.EaseOutQuad (initialY, initialY - startZoom, zoomTime - totalTimeLeft, zoomTime);
		}
		camera.transform.position = new Vector3(camera.transform.position.x, y, camera.transform.position.z);

		fixYAxis(camera);
	}
	
	public override Color getColor() {
		return Color.red;
	}
}
