--- Assumes that background image is of size
--- XXX
--- XOX
--- Where each character is the size of the screen, and 'O' is the default view.
function getDrawOffset(screenW, screenH, ballX, ballY)
    local offsetX, offsetY
    if ballY > screenH then
        return 0, 0
    end
    offsetY = math.max(0, -1 * ballY)

    if ballX > 0 and ballX < screenW then
        offsetX = 0
    elseif ballX < 0 then
        offsetX = math.max(-1 * screenW, ballX * -1)
    elseif ballX > screenW then
        offsetX = math.min(screenW * 2, (ballX * -1) + screenW)
    end

    return offsetX * 1.3, offsetY * 1.5
end

-- selene: allow(unscoped_variables)
blipper = {}

--- Build an object that simply "blips" between the given images at the given interval.
--- Expects `playdate.graphics.animation.blinker.updateAll()` to be called on every update.
function blipper.new(msInterval, imagePath1, imagePath2)
    local blinker = playdate.graphics.animation.blinker.new(msInterval, msInterval, true)
    blinker:start()
    return {
        blinker = blinker,
        image1 = playdate.graphics.image.new(imagePath1),
        image2 = playdate.graphics.image.new(imagePath2),
        draw = function(self, disableBlipping, x, y)
            local currentImage = (disableBlipping or self.blinker.on) and self.image2 or self.image1
            currentImage:draw(x, y)
        end,
    }
end
