local openedBoxFlag = "opened_pandoras_box"

local killboxX = getLevel().Bounds.Left + 288
local killboxY = getLevel().Bounds.Top + 352
local killbox = false

function onBegin()
    makeUnskippable()

    for _, entity in ipairs(getAllEntities("Killbox")) do
        if entity.Position.X == killboxX and entity.Position.Y == killboxY then
            killbox = entity

            break
        end
    end

end

function onEnd(level, wasSkipped)
    if not getFlag(openedBoxFlag) then
        for _, entity in ipairs(getAllEntities("CrystalStaticSpinner")) do
            engine.Scene.Entities:Remove(entity)
        end

    else
        if killbox then
            engine.Scene.Entities:Remove(killbox)
        end
    end
end