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

public class KeuhkoScript : MonoBehaviour {

    public GameObject[] bubbles;
    public GameObject keuhk;
    int num;

    public int poppedbubbles;

    bool bunched;

	// Use this for initialization
	void Start () {
        num = 400;
        Physics2D.gravity = new Vector2(0, 0);
        poppedbubbles = 0;
	}
	
	// Update is called once per frame
	void Update () {


        if(poppedbubbles > 0)
        {
            GameObject.Find("QuestTracker").GetComponent<QuestTrackerScript>().Did(0);
        }
        if (poppedbubbles > 100)
        {
            GameObject.Find("QuestTracker").GetComponent<QuestTrackerScript>().Did(1);
        }


        if (num <= 0) return;
		if (Random.Range(0, 150) == 0)
        {
            int r = Random.Range(0, bubbles.Length);
            Vector3 pos = new Vector3(16, -60, 0) + Random.insideUnitSphere * 40;
            pos = new Vector3(pos.x, pos.y, 0);
            bool special = false;
            if (num <= 25)
            { // last guys
                special = true;
            }
            for (int i = 0; i < 25; i++) {
                Vector3 rrr = (Vector3)Random.insideUnitSphere * 10;
                rrr = new Vector3(rrr.x, rrr.y, 0);
                GameObject g = GameObject.Instantiate(bubbles[r], pos + rrr, Quaternion.identity);
                if (special && i == 0)
                {
                    g.AddComponent<SpecialBubble>();
                }
                num--;
            }
        }

        if (num < 50 && bunched == false)
        {
            Vector3 pos = new Vector3(0, 0, 0);
            if (GameObject.Find("player").transform.position.magnitude < 30)
            {
                pos = new Vector3(16, -60, 0);
            }
            bunched = true;
            for (int i = 0; i < 15; i++)
            {
                
                Vector3 rrr = (Vector3)Random.insideUnitSphere * 10;
                rrr = new Vector3(rrr.x, rrr.y, 0);
                GameObject.Instantiate(keuhk, pos + rrr, Quaternion.identity);
                num--;
            }
            GameObject.Find("QuestTracker").GetComponent<QuestTrackerScript>().ShowSpecial("YOU'VE GOT COMPANY!");
        }
	}

}
