using UnityEngine;
using System.Collections;

public class Spawner : MonoBehaviour {
    public Transform dotPrefab;
    public Transform finalDotPrefab;
    public Transform[] figurePrefabs;
    public Transform brush;
    public Transform superBrush;

    public void SpawnDots(int ammount)
    {
        for (int i = 0; i < ammount; i++)
        {
            Transform dot = Transform.Instantiate(dotPrefab);
            dot.GetComponent<Rigidbody2D>().velocity = Random.insideUnitCircle * 8;
            dot.SetParent(transform);
        }
    }

    public void SpawnFigures(int ammount)
    {
        for (int i = 0; i < ammount; i++)
        {
            Transform figure = Transform.Instantiate(figurePrefabs[Random.Range(0, 4)]);
            figure.localPosition = new Vector3(0, 0, + 0.02f * i);
            figure.GetComponent<Rigidbody2D>().velocity = Random.insideUnitCircle * 8;
            figure.GetComponent<Rigidbody2D>().angularVelocity = Random.Range(-20, 20);
            figure.SetParent(transform);
        }
    }

    public void Clear()
    {
        foreach (Transform child in transform)
        {
            Destroy(child.gameObject);
        }
    }

    public void SpawnFinalDots(int number)
    {
        for (int i = 0; i < number; i++)
        {
            Transform finalDot = Transform.Instantiate(finalDotPrefab);
            Vector3 tmp = Random.insideUnitCircle;
            finalDot.transform.position = tmp * 2;
            finalDot.GetComponent<Rigidbody2D>().velocity = tmp * 10 + (Vector3)Random.insideUnitCircle * 2;
            finalDot.SetParent(transform);
        }
    }
}
