class EnemyGenerator extends Sprite {
    constructor(x, y, spawnInterval = 120, maxEnemies = 5, enemyImage = null) {
        super(x, y, 0, 0);
        this.spawnInterval = spawnInterval; // frames
        this.timer = 0;
        this.enemyImage = enemyImage;
        this.maxEnemies = maxEnemies;
        this.spawnedEnemies = 0;
    }

    update(sprites) {
        this.timer++;

        const existingEnemies = sprites.filter(s => s instanceof Enemy && s.x >= this.x - 300 && s.x <= this.x + 300);

        if (this.timer >= this.spawnInterval && existingEnemies.length < this.maxEnemies) {
            const newEnemy = new Enemy(this.x, this.y, 50, 50, this.enemyImage);
            sprites.push(newEnemy);
            this.timer = 0;
            this.spawnedEnemies++;
        }

        return false;
    }

    draw(ctx) {
        // Optional: visual marker for the generator
        // ctx.fillStyle = 'rgba(255, 0, 0, 0.3)';
        // ctx.fillRect(this.x, this.y, 10, 10);
    }
}
