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

public class GlobalC : MonoBehaviour
{
    [SerializeField] private GameObject ropePrefab = null;
    [SerializeField] private Transform ropeContainer = null;

    [SerializeField] private GameObject balloonPrefab = null;
    [SerializeField] private Transform balloonContainer = null;

    [SerializeField] private int balloonCount = 4;
    [SerializeField] private float balloonGroupHeightExpansion = 0.02f;

    // Start is called before the first frame update
    void Awake()
    {
        this.Initialize();   
    }

    public void Initialize()
    {
        this.GenerateBalloonsAndRopes();   
    }

    private void GenerateBalloonsAndRopes()
    {
        for (int i=0; i<this.balloonCount; ++i)
        {
            this.GenerateBalloonsAndRope(i);
        }
    }

    private void GenerateBalloonsAndRope(int i)
    {
        GameObject ropeObject = GameObject.Instantiate(this.ropePrefab, this.ropeContainer);
        LineRenderer rope = ropeObject.GetComponent<LineRenderer>();

        GameObject balloonObject = GameObject.Instantiate(this.balloonPrefab, this.balloonContainer);
        BalloonC balloon = balloonObject.GetComponent<BalloonC>();

        Vector2 position = UnityEngine.Random.insideUnitCircle;
        position.y += i * this.balloonGroupHeightExpansion;
        balloon.transform.localPosition = position;

        balloon.SetRope(rope);
    }
}
