Correct and further consolidate returnToPitcher()
This commit is contained in:
parent
ad82035ccc
commit
52434fe891
24
src/main.lua
24
src/main.lua
|
@ -262,10 +262,13 @@ function Game:pitch(pitchFlyTimeMs, pitchTypeIndex)
|
||||||
pitchTracker.secondsSinceLastPitch = 0
|
pitchTracker.secondsSinceLastPitch = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Game:pitcherIsOnTheMound()
|
||||||
|
return utils.distanceBetweenPoints(self.fielding.fielders.pitcher, C.PitcherStartPos) < C.BaseHitbox
|
||||||
|
end
|
||||||
|
|
||||||
function Game:pitcherIsReady()
|
function Game:pitcherIsReady()
|
||||||
local pitcher = self.fielding.fielders.pitcher
|
local pitcher = self.fielding.fielders.pitcher
|
||||||
local pitcherIsOnTheMound = utils.distanceBetweenPoints(pitcher, C.PitcherStartPos) < C.BaseHitbox
|
return self:pitcherIsOnTheMound()
|
||||||
return pitcherIsOnTheMound
|
|
||||||
and (
|
and (
|
||||||
self.state.ball.heldBy == pitcher
|
self.state.ball.heldBy == pitcher
|
||||||
or utils.distanceBetweenPoints(pitcher, self.state.ball) < C.BallCatchHitbox
|
or utils.distanceBetweenPoints(pitcher, self.state.ball) < C.BallCatchHitbox
|
||||||
|
@ -473,9 +476,18 @@ function Game:updateNonBatterRunners(appliedSpeed, forcedOnly)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Game:returnToPitcher()
|
function Game:returnToPitcher()
|
||||||
self.fielding:resetEligibility()
|
self.fielding:resetFielderPositions()
|
||||||
self.fielding.fielders.pitcher.catchEligible = true
|
actionQueue:upsert("returnToPitcher", 60 * 1000, function()
|
||||||
self.state.ball:launch(C.PitchStart.x, C.PitchStart.y, playdate.easingFunctions.linear, nil, true)
|
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
|
end
|
||||||
|
|
||||||
---@param throwFly number
|
---@param throwFly number
|
||||||
|
@ -573,9 +585,7 @@ function Game:updateGameState()
|
||||||
elseif self.state.offenseState == C.Offense.homeRun then
|
elseif self.state.offenseState == C.Offense.homeRun then
|
||||||
self:updateNonBatterRunners(C.WalkedRunnerSpeed * 2, false)
|
self:updateNonBatterRunners(C.WalkedRunnerSpeed * 2, false)
|
||||||
if #self.baserunning.runners == 0 then
|
if #self.baserunning.runners == 0 then
|
||||||
self.baserunning:pushNewBatter()
|
|
||||||
-- Give the player a moment to enjoy their home run.
|
-- Give the player a moment to enjoy their home run.
|
||||||
self.fielding:resetFielderPositions()
|
|
||||||
playdate.timer.new(1500, function()
|
playdate.timer.new(1500, function()
|
||||||
self:returnToPitcher()
|
self:returnToPitcher()
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Reference in New Issue