using UnityEngine;

public class MultiplierSpawner : Spawner
{
    public GameObject multiplierPrefab;

    public SpriteRenderer gameBoardSpriteRenderer;

    public WorldFiller worldFiller;

    private Bounds multiplierBounds;

    private Bounds gameBoardBounds;

    private float spawnTimer = 0f;

    private Vector2 spawnPosition;

    private bool isActive = true;

    private static float spawnProbability = 0.1f;

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        gameBoardBounds = gameBoardSpriteRenderer.bounds;
        multiplierBounds = multiplierPrefab.GetComponent<SpriteRenderer>().bounds;
        Reset();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        spawnTimer += Time.fixedDeltaTime;

        if (spawnTimer >= 1f && isActive && isSpawning)
        {
            spawnTimer = 0f;
            if (Random.value < spawnProbability)
            {
                spawnPosition = worldFiller.GetRandomPositionInFreeAreas(multiplierBounds);
                GameObject multiplier = Instantiate(multiplierPrefab, spawnPosition, Quaternion.identity);
                isActive = false;
            }
        }
    }

    public void Reset()
    {
        isActive = true;
        spawnTimer = 0f;
    }
}
