Correct and further consolidate returnToPitcher()

This commit is contained in:
Sage Vaillancourt 2025-02-19 17:26:05 -05:00
parent ad82035ccc
commit 52434fe891
1 changed files with 17 additions and 7 deletions

View File

@ -262,10 +262,13 @@ function Game:pitch(pitchFlyTimeMs, pitchTypeIndex)
pitchTracker.secondsSinceLastPitch = 0
end
function Game:pitcherIsOnTheMound()
return utils.distanceBetweenPoints(self.fielding.fielders.pitcher, C.PitcherStartPos) < C.BaseHitbox
end
function Game:pitcherIsReady()
local pitcher = self.fielding.fielders.pitcher
local pitcherIsOnTheMound = utils.distanceBetweenPoints(pitcher, C.PitcherStartPos) < C.BaseHitbox
return pitcherIsOnTheMound
return self:pitcherIsOnTheMound()
and (
self.state.ball.heldBy == pitcher
or utils.distanceBetweenPoints(pitcher, self.state.ball) < C.BallCatchHitbox
@ -473,9 +476,18 @@ function Game:updateNonBatterRunners(appliedSpeed, forcedOnly)
end
function Game:returnToPitcher()
self.fielding:resetEligibility()
self.fielding.fielders.pitcher.catchEligible = true
self.state.ball:launch(C.PitchStart.x, C.PitchStart.y, playdate.easingFunctions.linear, nil, true)
self.fielding:resetFielderPositions()
actionQueue:upsert("returnToPitcher", 60 * 1000, function()
while not self:pitcherIsOnTheMound() do
coroutine.yield()
end
if not self.baserunning.batter then
self.baserunning:pushNewBatter()
end
self.fielding:resetEligibility()
self.fielding.fielders.pitcher.catchEligible = true
self.state.ball:launch(C.PitchStart.x, C.PitchStart.y, playdate.easingFunctions.linear, nil, true)
end)
end
---@param throwFly number
@ -573,9 +585,7 @@ function Game:updateGameState()
elseif self.state.offenseState == C.Offense.homeRun then
self:updateNonBatterRunners(C.WalkedRunnerSpeed * 2, false)
if #self.baserunning.runners == 0 then
self.baserunning:pushNewBatter()
-- Give the player a moment to enjoy their home run.
self.fielding:resetFielderPositions()
playdate.timer.new(1500, function()
self:returnToPitcher()
end)