class Flag extends Sprite {
    constructor(x, y, width = 20, height = 80, imagePath = null, game) {
        super(x, y, width, height);
        this.image = null;

        if (imagePath) {
            this.image = new Image();
            this.image.src = imagePath;
        }
        this.game = game;
    }

    update(sprites) {
        for (let s of sprites) {
            if (s instanceof Player && CollisionManager.isColliding(this, s)) {
                this.game.changeLevel(2); // or this.game.nextLevel() if needed
            }
        }
        return false;
    }

    draw(ctx) {
        if (this.image && this.image.complete) {
            ctx.drawImage(this.image, this.x, this.y, this.width, this.height);
        } else {
            ctx.fillStyle = 'red';
            ctx.fillRect(this.x, this.y, this.width, this.height);
        }
    }
}
