Only draw in-bounds fielders on minimap.

Inject animator into Ball, instead of entire gfx
This commit is contained in:
Sage Vaillancourt 2025-02-09 12:09:31 -05:00
parent 89c37eaf3d
commit 0f83298086
3 changed files with 16 additions and 14 deletions

View File

@ -1,6 +1,6 @@
-- selene: allow(unscoped_variables)
---@class Ball
---@field private gfx pd_graphics_lib
---@field private animator pd_animator_lib
---@field x number
---@field y number
---@field z number
@ -12,11 +12,11 @@
---@field floatAnimator SimpleAnimator
Ball = {}
---@param g pd_graphics_lib
---@param animator pd_animator_lib
---@return Ball
function Ball.new(g)
function Ball.new(animator)
return setmetatable({
gfx = g,
animator = animator,
x = C.Center.x --[[@as number]],
y = C.Center.y --[[@as number]],
z = 0,
@ -29,7 +29,7 @@ function Ball.new(g)
-- TODO? Replace these with a ballAnimatorZ?
-- ...that might lose some of the magic of both. Compromise available? idk
sizeAnimator = utils.staticAnimator(C.SmallestBallRadius),
floatAnimator = g.animator.new(2000, -60, 0, utils.easingHill),
floatAnimator = animator.new(2000, -60, 0, utils.easingHill),
}, { __index = Ball })
end
@ -51,10 +51,10 @@ function Ball:launch(destX, destY, easingFunc, flyTimeMs, floaty, customBallScal
self.sizeAnimator = customBallScaler
else
-- TODO? Scale based on distance?
self.sizeAnimator = self.gfx.animator.new(flyTimeMs, 9, C.SmallestBallRadius, utils.easingHill)
self.sizeAnimator = self.animator.new(flyTimeMs, 9, C.SmallestBallRadius, utils.easingHill)
end
self.yAnimator = self.gfx.animator.new(flyTimeMs, self.y, destY, easingFunc)
self.xAnimator = self.gfx.animator.new(flyTimeMs, self.x, destX, easingFunc)
self.yAnimator = self.animator.new(flyTimeMs, self.y, destY, easingFunc)
self.xAnimator = self.animator.new(flyTimeMs, self.x, destX, easingFunc)
if floaty then
self.floatAnimator:reset(flyTimeMs)
end

View File

@ -5,6 +5,7 @@ local ScoreFont <const> = playdate.graphics.font.new("fonts/font-full-circle.pft
local MinimapSizeX, MinimapSizeY <const> = Minimap:getSize()
local MinimapPosX, MinimapPosY = C.Screen.W - MinimapSizeX, C.Screen.H - MinimapSizeY
local MinimapBoundX, MinimapBoundY = (MinimapSizeX + MinimapPosX), (MinimapSizeY + MinimapPosY)
local MinimapMultX <const> = 0.75 * MinimapSizeX / C.Screen.W
local MinimapOffsetX <const> = MinimapPosX + 5
@ -19,11 +20,12 @@ function drawMinimap(runners, fielders)
local y = (MinimapMultY * runner.y) + MinimapOffsetY
gfx.fillRect(x, y, 8, 8)
end
-- TODO: Don't draw when out of bounds
for _, fielder in pairs(fielders) do
local x = (MinimapMultX * fielder.x) + MinimapOffsetX
local y = (MinimapMultY * fielder.y) + MinimapOffsetY
gfx.drawCircleAtPoint(x, y, 4)
if x > MinimapPosX and x < MinimapBoundX and y > MinimapPosY and y < MinimapBoundY then
gfx.drawCircleAtPoint(x, y, 4)
end
end
end

View File

@ -47,7 +47,7 @@ local fielding = Fielding.new()
local deltaSeconds = 0
local ball = Ball.new(gfx)
local ball = Ball.new(gfx.animator)
---@alias Team { score: number, benchPosition: XyPair }
@ -71,11 +71,10 @@ local offenseState = C.Offense.batting
local throwMeter = 0
-- TODO: Replace with a timer, repeatedly reset, instead of setting to 0
-- TODO: Replace with timers, repeatedly reset, instead of constantly setting to 0
local secondsSinceLastRunnerMove = 0
-- TODO: Replace with a timer, repeatedly reset instead of setting to 0
local secondsSincePitchAllowed = -5
local catcherThrownBall = false
local BatterHandPos <const> = utils.xy(10, 25)
@ -296,6 +295,7 @@ local function updateBatting(batDeg, batSpeed)
end
local ballDestX = ball.x + (ballVelX * C.BattingPower)
local ballDestY = ball.y + (ballVelY * C.BattingPower)
ballDestY = ballDestY - 300
-- Hit!
local hitBallScaler = gfx.animator.new(2000, 9 + (mult * mult * 0.5), C.SmallestBallRadius, utils.easingHill)
launchBall(ballDestX, ballDestY, playdate.easingFunctions.outQuint, 2000, nil, hitBallScaler)