Properly display balls and strikes #3

Merged
sage merged 2 commits from proper-balls-and-strikes-display into main 2025-02-07 20:11:54 -05:00
2 changed files with 17 additions and 3 deletions
Showing only changes of commit 2b436082bb - Show all commits

View File

@ -1014,7 +1014,7 @@ function playdate.update()
drawMinimap()
end
drawScoreboard(0, Screen.H * 0.77, teams, outs, battingTeam, inning)
drawBallsAndStrikes(300, Screen.H * 0.77, balls, strikes)
drawBallsAndStrikes(290, Screen.H - 20, balls, strikes)
announcer:draw(Center.x, 10)
end

View File

@ -6,6 +6,9 @@ local ScoreboardHeight <const> = 55
local Indicator = "> "
local IndicatorWidth <const> = ScoreFont:getTextWidth(Indicator)
local BallStrikeWidth <const> = 60
local BallStrikeHeight <const> = 20
---@param teams any
---@param battingTeam any
---@return string, number, string, number
@ -17,10 +20,21 @@ function getIndicators(teams, battingTeam)
end
function drawBallsAndStrikes(x, y, balls, strikes)
if balls == 0 and strikes == 0 then
return
end
local gfx = playdate.graphics
print("" .. balls .. " - " .. strikes)
gfx.setColor(gfx.kColorBlack)
gfx.fillRect(x, y, 20, ScoreboardHeight)
gfx.fillRect(x, y, BallStrikeWidth, BallStrikeHeight)
local originalDrawMode = gfx.getImageDrawMode()
gfx.setImageDrawMode(gfx.kDrawModeInverted)
local text = tostring(balls) .. " - " .. tostring(strikes)
local textWidth = ScoreFont:getTextWidth(text)
local widthDiff = BallStrikeWidth - textWidth
ScoreFont:drawText(text, x + (widthDiff / 2), y + 4)
Review

Where does the magic 4 come from 🤔

Where does the magic 4 come from 🤔
Review

You're honestly so real for that

You're honestly so real for that
gfx.setImageDrawMode(originalDrawMode)
end
function drawScoreboard(x, y, teams, outs, battingTeam, inning)