Only draw in-bounds fielders on minimap.
Inject animator into Ball, instead of entire gfx
This commit is contained in:
parent
89c37eaf3d
commit
0f83298086
16
src/ball.lua
16
src/ball.lua
|
@ -1,6 +1,6 @@
|
||||||
-- selene: allow(unscoped_variables)
|
-- selene: allow(unscoped_variables)
|
||||||
---@class Ball
|
---@class Ball
|
||||||
---@field private gfx pd_graphics_lib
|
---@field private animator pd_animator_lib
|
||||||
---@field x number
|
---@field x number
|
||||||
---@field y number
|
---@field y number
|
||||||
---@field z number
|
---@field z number
|
||||||
|
@ -12,11 +12,11 @@
|
||||||
---@field floatAnimator SimpleAnimator
|
---@field floatAnimator SimpleAnimator
|
||||||
Ball = {}
|
Ball = {}
|
||||||
|
|
||||||
---@param g pd_graphics_lib
|
---@param animator pd_animator_lib
|
||||||
---@return Ball
|
---@return Ball
|
||||||
function Ball.new(g)
|
function Ball.new(animator)
|
||||||
return setmetatable({
|
return setmetatable({
|
||||||
gfx = g,
|
animator = animator,
|
||||||
x = C.Center.x --[[@as number]],
|
x = C.Center.x --[[@as number]],
|
||||||
y = C.Center.y --[[@as number]],
|
y = C.Center.y --[[@as number]],
|
||||||
z = 0,
|
z = 0,
|
||||||
|
@ -29,7 +29,7 @@ function Ball.new(g)
|
||||||
-- TODO? Replace these with a ballAnimatorZ?
|
-- TODO? Replace these with a ballAnimatorZ?
|
||||||
-- ...that might lose some of the magic of both. Compromise available? idk
|
-- ...that might lose some of the magic of both. Compromise available? idk
|
||||||
sizeAnimator = utils.staticAnimator(C.SmallestBallRadius),
|
sizeAnimator = utils.staticAnimator(C.SmallestBallRadius),
|
||||||
floatAnimator = g.animator.new(2000, -60, 0, utils.easingHill),
|
floatAnimator = animator.new(2000, -60, 0, utils.easingHill),
|
||||||
}, { __index = Ball })
|
}, { __index = Ball })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -51,10 +51,10 @@ function Ball:launch(destX, destY, easingFunc, flyTimeMs, floaty, customBallScal
|
||||||
self.sizeAnimator = customBallScaler
|
self.sizeAnimator = customBallScaler
|
||||||
else
|
else
|
||||||
-- TODO? Scale based on distance?
|
-- 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
|
end
|
||||||
self.yAnimator = self.gfx.animator.new(flyTimeMs, self.y, destY, easingFunc)
|
self.yAnimator = self.animator.new(flyTimeMs, self.y, destY, easingFunc)
|
||||||
self.xAnimator = self.gfx.animator.new(flyTimeMs, self.x, destX, easingFunc)
|
self.xAnimator = self.animator.new(flyTimeMs, self.x, destX, easingFunc)
|
||||||
if floaty then
|
if floaty then
|
||||||
self.floatAnimator:reset(flyTimeMs)
|
self.floatAnimator:reset(flyTimeMs)
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,7 @@ local ScoreFont <const> = playdate.graphics.font.new("fonts/font-full-circle.pft
|
||||||
|
|
||||||
local MinimapSizeX, MinimapSizeY <const> = Minimap:getSize()
|
local MinimapSizeX, MinimapSizeY <const> = Minimap:getSize()
|
||||||
local MinimapPosX, MinimapPosY = C.Screen.W - MinimapSizeX, C.Screen.H - MinimapSizeY
|
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 MinimapMultX <const> = 0.75 * MinimapSizeX / C.Screen.W
|
||||||
local MinimapOffsetX <const> = MinimapPosX + 5
|
local MinimapOffsetX <const> = MinimapPosX + 5
|
||||||
|
@ -19,12 +20,13 @@ function drawMinimap(runners, fielders)
|
||||||
local y = (MinimapMultY * runner.y) + MinimapOffsetY
|
local y = (MinimapMultY * runner.y) + MinimapOffsetY
|
||||||
gfx.fillRect(x, y, 8, 8)
|
gfx.fillRect(x, y, 8, 8)
|
||||||
end
|
end
|
||||||
-- TODO: Don't draw when out of bounds
|
|
||||||
for _, fielder in pairs(fielders) do
|
for _, fielder in pairs(fielders) do
|
||||||
local x = (MinimapMultX * fielder.x) + MinimapOffsetX
|
local x = (MinimapMultX * fielder.x) + MinimapOffsetX
|
||||||
local y = (MinimapMultY * fielder.y) + MinimapOffsetY
|
local y = (MinimapMultY * fielder.y) + MinimapOffsetY
|
||||||
|
if x > MinimapPosX and x < MinimapBoundX and y > MinimapPosY and y < MinimapBoundY then
|
||||||
gfx.drawCircleAtPoint(x, y, 4)
|
gfx.drawCircleAtPoint(x, y, 4)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local BallStrikeMarginY <const> = 4
|
local BallStrikeMarginY <const> = 4
|
||||||
|
|
|
@ -47,7 +47,7 @@ local fielding = Fielding.new()
|
||||||
|
|
||||||
local deltaSeconds = 0
|
local deltaSeconds = 0
|
||||||
|
|
||||||
local ball = Ball.new(gfx)
|
local ball = Ball.new(gfx.animator)
|
||||||
|
|
||||||
---@alias Team { score: number, benchPosition: XyPair }
|
---@alias Team { score: number, benchPosition: XyPair }
|
||||||
|
|
||||||
|
@ -71,11 +71,10 @@ local offenseState = C.Offense.batting
|
||||||
|
|
||||||
local throwMeter = 0
|
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
|
local secondsSinceLastRunnerMove = 0
|
||||||
|
|
||||||
-- TODO: Replace with a timer, repeatedly reset instead of setting to 0
|
|
||||||
local secondsSincePitchAllowed = -5
|
local secondsSincePitchAllowed = -5
|
||||||
|
|
||||||
local catcherThrownBall = false
|
local catcherThrownBall = false
|
||||||
|
|
||||||
local BatterHandPos <const> = utils.xy(10, 25)
|
local BatterHandPos <const> = utils.xy(10, 25)
|
||||||
|
@ -296,6 +295,7 @@ local function updateBatting(batDeg, batSpeed)
|
||||||
end
|
end
|
||||||
local ballDestX = ball.x + (ballVelX * C.BattingPower)
|
local ballDestX = ball.x + (ballVelX * C.BattingPower)
|
||||||
local ballDestY = ball.y + (ballVelY * C.BattingPower)
|
local ballDestY = ball.y + (ballVelY * C.BattingPower)
|
||||||
|
ballDestY = ballDestY - 300
|
||||||
-- Hit!
|
-- Hit!
|
||||||
local hitBallScaler = gfx.animator.new(2000, 9 + (mult * mult * 0.5), C.SmallestBallRadius, utils.easingHill)
|
local hitBallScaler = gfx.animator.new(2000, 9 + (mult * mult * 0.5), C.SmallestBallRadius, utils.easingHill)
|
||||||
launchBall(ballDestX, ballDestY, playdate.easingFunctions.outQuint, 2000, nil, hitBallScaler)
|
launchBall(ballDestX, ballDestY, playdate.easingFunctions.outQuint, 2000, nil, hitBallScaler)
|
||||||
|
|
Loading…
Reference in New Issue