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

public class SpawnItems : MonoBehaviour {
	public Rigidbody2D itemGood;
	public Rigidbody2D itemBad;
	public Sprite[] GoodSprites;
	public Sprite[] BadSprites;
	public float timePeriod;
	public float timeLow;
	public GameObject RestartObject;

	private float time;

	// Use this for initialization
	void Start () {
		time = 2f;
	}
	
	// Update is called once per frame
	void Update () {
		time += Time.deltaTime;
		if (time > timePeriod) {
			time -= timePeriod;
			timePeriod = timePeriod * 0.9f + timeLow * 0.1f;
			if (timePeriod < 0.6f) {
				timePeriod = 10000000f;
				RestartObject.GetComponent<IntermissionController> ().RunEndChecks ();
			}
			Rigidbody2D itemCloneBody;
			if (Random.value < 0.8f)
				itemCloneBody = (Rigidbody2D) Instantiate (itemGood);
			else
				itemCloneBody = (Rigidbody2D) Instantiate (itemBad);
			itemCloneBody.transform.Rotate (Vector3.forward, 360*Random.value);
			itemCloneBody.velocity = (Vector2) (Quaternion.AngleAxis(70*Random.value-35, Vector3.forward) * transform.position * -1f);
			itemCloneBody.angularVelocity = Random.value * 360 - 180;

			itemCloneBody.transform.position = transform.position;
		}
	}
}
