using UnityEngine;
using System.Collections;

public class BoidController : MonoBehaviour
{
    public float minVelocity = 5;
    public float maxVelocity = 20;
    public float randomness = 1;
    public int flockSize = 20;
    public GameObject matter, antimatter;

    public Vector3 flockCenter;
    public Vector3 flockVelocity;

    void Start()
    {
        for (var i = 0; i < flockSize; i++)
        {
            Vector3 position = new Vector3(
                Random.value * collider.bounds.size.x,
                Random.value * collider.bounds.size.y,
                Random.value * collider.bounds.size.z
            ) - collider.bounds.extents;


            float w = 500 * Mathf.Sqrt(Random.Range(0.1f, 1f));
            float t = 2 * Mathf.PI * Random.Range(0, 1f);
            float x = w * Mathf.Cos(t);
            float y = w * Mathf.Sin(t);

            Vector3 newPos = new Vector3(x, y, 0);

            if (Random.Range(0, 2) == 0)
            {
                GameObject boid = Instantiate(matter, newPos, transform.rotation) as GameObject;
                boid.name = "Matter";
                boid.GetComponent<Particle>().Init(transform, newPos);
                boid.GetComponent<Particle>().SetController(gameObject);
            }
            else
            {
                GameObject boid = Instantiate(antimatter, newPos, transform.rotation) as GameObject;
                boid.name = "Antimatter";
                boid.GetComponent<Particle>().Init(transform, newPos);
                boid.GetComponent<Particle>().SetController(gameObject);
            }
            
        }
    }
}