-- selene: allow(shadowing)
local gfx = playdate.graphics

local GloveSizeX, GloveSizeY <const> = Glove:getSize()
local GloveOffX, GloveOffY <const> = GloveSizeX / 2, GloveSizeY / 2

---@param ball Point3d
---@param fielderX number
---@param fielderY number
---@return boolean isHoldingBall
local function drawFielderGlove(ball, fielderX, fielderY)
    local distanceFromBall = utils.distanceBetweenZ(fielderX, fielderY, 0, ball.x, ball.y, ball.z)
    local shoulderX, shoulderY = fielderX + 10, fielderY + 5
    if distanceFromBall > 20 then
        Glove:draw(shoulderX, shoulderY)
        return false
    else
        GloveHoldingBall:draw(ball.x - GloveOffX, ball.y - GloveOffY)
        return true
    end
end

---@return boolean isHoldingBall
function drawFielder(ball, x, y)
    gfx.fillRect(x, y, 14, 25)
    return drawFielderGlove(ball, x, y)
end
