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

public class EnemyManager : MonoBehaviour
{
    [Header("Lime Guys")]
    [SerializeField] GameObject acidite1;
    [SerializeField] GameObject acidite2;
    [SerializeField] GameObject acidite3;
    [SerializeField] GameObject commangle;


    [Header("Numbers")]
    [SerializeField] int xPosition;
    [SerializeField] int yPosition;
    private int wave;
    private float time;
    [SerializeField] int difficultyScale;
    [SerializeField] float timeUntilNextSpawn;
    private float tempValue;
    [SerializeField] float timerScaling;
    [SerializeField] int timeUntilAcidite2;
    [SerializeField] int timeUntilAcidite3;
    [SerializeField] int timeUntilCommangle;
    [SerializeField] int timeUntilFinalWaves;

    void Start()
    {
        tempValue = timeUntilNextSpawn;
    }
    // Update is called once per frame
    void Update()
    {
        UpdateTime();
        EnemySpawn();
    }

    void UpdateTime()
    {
        time += Time.deltaTime;
        tempValue -= Time.deltaTime;
        timeUntilNextSpawn = (1/(time + 140)) * 1400;
        if (time >= 300)
        {
            timeUntilNextSpawn = timeUntilNextSpawn / 10;
        }
    }
    void EnemySpawn()
    {
        if (tempValue <= 0)
        {
            tempValue += timeUntilNextSpawn;
            if (time <= timeUntilAcidite2)
            {
                GameObject p = Instantiate(acidite1, new Vector2(xPosition, RandomYValue()), Quaternion.identity);
            }
            else if (time <= timeUntilAcidite3)
            {
                GameObject p = Instantiate(acidite1, new Vector2(xPosition, RandomYValue()), Quaternion.identity);
                GameObject q = Instantiate(acidite2, new Vector2(xPosition, RandomYValue()), Quaternion.identity);
            }
            else if (time <= timeUntilCommangle)
            {
                GameObject p = Instantiate(acidite1, new Vector2(xPosition, RandomYValue()), Quaternion.identity);
                GameObject q = Instantiate(acidite2, new Vector2(xPosition, RandomYValue()), Quaternion.identity);
                GameObject r = Instantiate(acidite3, new Vector2(xPosition, RandomYValue()), Quaternion.identity);
            }
            else if (time <= timeUntilFinalWaves)
            {
                GameObject p = Instantiate(acidite1, new Vector2(xPosition, RandomYValue()), Quaternion.identity);
                GameObject q = Instantiate(acidite2, new Vector2(xPosition, RandomYValue()), Quaternion.identity);
                GameObject r = Instantiate(acidite3, new Vector2(xPosition, RandomYValue()), Quaternion.identity);
                GameObject s = Instantiate(commangle, new Vector2(xPosition, RandomYValue()), Quaternion.identity);
            }
            else
            {
                GameObject p = Instantiate(acidite1, new Vector2(xPosition, RandomYValue()), Quaternion.identity);
                GameObject q = Instantiate(acidite2, new Vector2(xPosition, RandomYValue()), Quaternion.identity);
                GameObject r = Instantiate(acidite2, new Vector2(xPosition, RandomYValue()), Quaternion.identity);
                GameObject s = Instantiate(acidite2, new Vector2(xPosition, RandomYValue()), Quaternion.identity);
                GameObject t = Instantiate(acidite3, new Vector2(xPosition, RandomYValue()), Quaternion.identity);
                GameObject u = Instantiate(acidite3, new Vector2(xPosition, RandomYValue()), Quaternion.identity);
                GameObject v = Instantiate(acidite3, new Vector2(xPosition, RandomYValue()), Quaternion.identity);
                GameObject w = Instantiate(acidite3, new Vector2(xPosition, RandomYValue()), Quaternion.identity);
                GameObject y = Instantiate(commangle, new Vector2(xPosition, RandomYValue()), Quaternion.identity);
                GameObject z = Instantiate(commangle, new Vector2(xPosition, RandomYValue()), Quaternion.identity);
            }
        }
    }

    public float RandomYValue()
    {
        int value = Random.Range(0, 7);
        float valuef = (float)value + 1.5f;
        return valuef;
    }
}
