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

[System.Serializable]
public class JuiceDropper : MonoBehaviour {

	public List<Transform> JuicePrefabs;
	public float DropTimeSpan;
	public float DropInterval;
	public Vector2 PositionDelta;
	public Vector2 PositionOffset;
    public bool Rotate = true;


	private float startTime;
	private float lastDropTime;

	private GameController gc;
	
	
	// Use this for initialization
	void Start () {
		GameObject go = GameObject.Find ("GameController");
		gc = go.GetComponent<GameController>();
	}

	public void StartDropping()
	{
		startTime = Time.time;
		lastDropTime = 0;
	}
	
	
	void FixedUpdate () {
		if(Time.time - startTime > DropTimeSpan)
			return;

		if(Time.time - lastDropTime > DropInterval)
		{
			lastDropTime = Time.time;
            Transform prefab = ListHelper.DrawFromAtRandom(JuicePrefabs);
            Transform juice = (Transform)GameObject.Instantiate(prefab);
			juice.position = transform.position + (Vector3)PositionOffset + (Vector3)(PositionDelta*UnityEngine.Random.Range(0f,1.0f) - PositionDelta*0.5f);
            if (Rotate)
                juice.localEulerAngles = new Vector3(0, 0, Random.Range(0f, 360f));
		}
	}
}
