From 0f832980869f3ace300f65fc14eeef2012c95ef3 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Sun, 9 Feb 2025 12:09:31 -0500 Subject: [PATCH] Only draw in-bounds fielders on minimap. Inject animator into Ball, instead of entire gfx --- src/ball.lua | 16 ++++++++-------- src/draw/overlay.lua | 6 ++++-- src/main.lua | 8 ++++---- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/ball.lua b/src/ball.lua index 8115de6..dbaeb72 100644 --- a/src/ball.lua +++ b/src/ball.lua @@ -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 diff --git a/src/draw/overlay.lua b/src/draw/overlay.lua index c9fbd6c..a19e2bb 100644 --- a/src/draw/overlay.lua +++ b/src/draw/overlay.lua @@ -5,6 +5,7 @@ local ScoreFont = playdate.graphics.font.new("fonts/font-full-circle.pft local MinimapSizeX, MinimapSizeY = Minimap:getSize() local MinimapPosX, MinimapPosY = C.Screen.W - MinimapSizeX, C.Screen.H - MinimapSizeY +local MinimapBoundX, MinimapBoundY = (MinimapSizeX + MinimapPosX), (MinimapSizeY + MinimapPosY) local MinimapMultX = 0.75 * MinimapSizeX / C.Screen.W local MinimapOffsetX = 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 diff --git a/src/main.lua b/src/main.lua index c947601..fcc148d 100644 --- a/src/main.lua +++ b/src/main.lua @@ -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 = 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)