Store animators directly on the `ball` object
This commit is contained in:
parent
9c0d263a29
commit
d74332f685
src
72
src/main.lua
72
src/main.lua
|
@ -42,35 +42,25 @@ local announcer = Announcer:new()
|
|||
local baserunning = Baserunning.new(announcer)
|
||||
local fielding = Fielding.new()
|
||||
|
||||
local PlayerImageBlipper <const> = blipper.new(100, Player, PlayerLowHat)
|
||||
|
||||
local FielderDanceAnimator <const> = gfx.animator.new(1, 10, 0, utils.easingHill)
|
||||
FielderDanceAnimator.repeatCount = C.DanceBounceCount - 1
|
||||
|
||||
---@alias PseudoAnimator { currentValue: fun(self): number; reset: fun(self, durationMs: number | nil) }
|
||||
---@alias Pitch { x: PseudoAnimator, y: PseudoAnimator, z: PseudoAnimator | nil }
|
||||
|
||||
local ballAnimatorX = utils.staticAnimator(C.BallOffscreen)
|
||||
local ballAnimatorY = utils.staticAnimator(C.BallOffscreen)
|
||||
local ballSizeAnimator = utils.staticAnimator(C.SmallestBallRadius)
|
||||
|
||||
-- TODO? Replace this AND ballSizeAnimator with a ballAnimatorZ?
|
||||
-- ...that might lose some of the magic of both. Compromise available? idk
|
||||
local ballFloatAnimator = gfx.animator.new(2000, -60, 0, utils.easingHill)
|
||||
|
||||
local deltaSeconds = 0
|
||||
|
||||
local BatterHandPos <const> = utils.xy(10, 25)
|
||||
|
||||
local batBase <const> = utils.xy(C.Center.x - 34, 215)
|
||||
local batTip <const> = utils.xy(0, 0)
|
||||
|
||||
local ball <const> = {
|
||||
x = C.Center.x --[[@as number]],
|
||||
y = C.Center.y --[[@as number]],
|
||||
z = 0,
|
||||
size = C.SmallestBallRadius,
|
||||
heldBy = nil --[[@type Runner | nil]],
|
||||
|
||||
xAnimator = utils.staticAnimator(C.BallOffscreen),
|
||||
yAnimator = utils.staticAnimator(C.BallOffscreen),
|
||||
|
||||
-- TODO? Replace these with a ballAnimatorZ?
|
||||
-- ...that might lose some of the magic of both. Compromise available? idk
|
||||
sizeAnimator = utils.staticAnimator(C.SmallestBallRadius),
|
||||
floatAnimator = gfx.animator.new(2000, -60, 0, utils.easingHill),
|
||||
}
|
||||
|
||||
---@alias Team { score: number, benchPosition: XYPair }
|
||||
|
@ -102,8 +92,18 @@ local secondsSinceLastRunnerMove = 0
|
|||
local secondsSincePitchAllowed = -5
|
||||
local catcherThrownBall = false
|
||||
|
||||
local BatterHandPos <const> = utils.xy(10, 25)
|
||||
|
||||
local batBase <const> = utils.xy(C.Center.x - 34, 215)
|
||||
local batTip <const> = utils.xy(0, 0)
|
||||
|
||||
local batAngleDeg = C.CrankOffsetDeg
|
||||
|
||||
local PlayerImageBlipper <const> = blipper.new(100, Player, PlayerLowHat)
|
||||
|
||||
local FielderDanceAnimator <const> = gfx.animator.new(1, 10, 0, utils.easingHill)
|
||||
FielderDanceAnimator.repeatCount = C.DanceBounceCount - 1
|
||||
|
||||
---@type Pitch[]
|
||||
local Pitches <const> = {
|
||||
-- Fastball
|
||||
|
@ -125,7 +125,7 @@ local Pitches <const> = {
|
|||
{
|
||||
x = {
|
||||
currentValue = function()
|
||||
return C.PitchStartX + (10 * math.sin((ballAnimatorY:currentValue() - C.PitchStartY) / 10))
|
||||
return C.PitchStartX + (10 * math.sin((ball.yAnimator:currentValue() - C.PitchStartY) / 10))
|
||||
end,
|
||||
reset = function() end,
|
||||
},
|
||||
|
@ -160,15 +160,15 @@ local function throwBall(destX, destY, easingFunc, flyTimeMs, floaty, customBall
|
|||
end
|
||||
|
||||
if customBallScaler then
|
||||
ballSizeAnimator = customBallScaler
|
||||
ball.sizeAnimator = customBallScaler
|
||||
else
|
||||
-- TODO? Scale based on distance?
|
||||
ballSizeAnimator = gfx.animator.new(flyTimeMs, 9, C.SmallestBallRadius, utils.easingHill)
|
||||
ball.sizeAnimator = gfx.animator.new(flyTimeMs, 9, C.SmallestBallRadius, utils.easingHill)
|
||||
end
|
||||
ballAnimatorY = gfx.animator.new(flyTimeMs, ball.y, destY, easingFunc)
|
||||
ballAnimatorX = gfx.animator.new(flyTimeMs, ball.x, destX, easingFunc)
|
||||
ball.yAnimator = gfx.animator.new(flyTimeMs, ball.y, destY, easingFunc)
|
||||
ball.xAnimator = gfx.animator.new(flyTimeMs, ball.x, destX, easingFunc)
|
||||
if floaty then
|
||||
ballFloatAnimator:reset(flyTimeMs)
|
||||
ball.floatAnimator:reset(flyTimeMs)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -179,21 +179,21 @@ local function pitch(pitchFlyTimeMs, pitchTypeIndex)
|
|||
offenseState = C.Offense.batting
|
||||
|
||||
local current = Pitches[pitchTypeIndex]
|
||||
ballAnimatorX = current.x
|
||||
ballAnimatorY = current.y or Pitches[1].y
|
||||
ball.xAnimator = current.x
|
||||
ball.yAnimator = current.y or Pitches[1].y
|
||||
|
||||
-- TODO: This would need to be sanely replaced in throwBall() etc.
|
||||
-- if current.z then
|
||||
-- ballFloatAnimator = current.z
|
||||
-- ballFloatAnimator:reset()
|
||||
-- ball.floatAnimator = current.z
|
||||
-- ball.floatAnimator:reset()
|
||||
-- end
|
||||
|
||||
if pitchFlyTimeMs then
|
||||
ballAnimatorX:reset(pitchFlyTimeMs)
|
||||
ballAnimatorY:reset(pitchFlyTimeMs)
|
||||
ball.xAnimator:reset(pitchFlyTimeMs)
|
||||
ball.yAnimator:reset(pitchFlyTimeMs)
|
||||
else
|
||||
ballAnimatorX:reset()
|
||||
ballAnimatorY:reset()
|
||||
ball.xAnimator:reset()
|
||||
ball.yAnimator:reset()
|
||||
end
|
||||
|
||||
secondsSincePitchAllowed = 0
|
||||
|
@ -376,10 +376,10 @@ local function updateGameState()
|
|||
ball.y = ball.heldBy.y
|
||||
ball.size = C.SmallestBallRadius
|
||||
else
|
||||
ball.x = ballAnimatorX:currentValue()
|
||||
ball.z = ballFloatAnimator:currentValue()
|
||||
ball.y = ballAnimatorY:currentValue() + ball.z
|
||||
ball.size = ballSizeAnimator:currentValue()
|
||||
ball.x = ball.xAnimator:currentValue()
|
||||
ball.z = ball.floatAnimator:currentValue()
|
||||
ball.y = ball.yAnimator:currentValue() + ball.z
|
||||
ball.size = ball.sizeAnimator:currentValue()
|
||||
end
|
||||
|
||||
local playerOnOffense, playerOnDefense = playerIsOn(C.Sides.offense)
|
||||
|
|
Loading…
Reference in New Issue