buttonControlledThrow() simplification

This commit is contained in:
Sage Vaillancourt 2025-02-05 23:45:26 -05:00
parent 8319b554ec
commit eb28a628f2
1 changed files with 3 additions and 4 deletions

View File

@ -766,16 +766,12 @@ end
function buttonControlledThrow(thrower, throwFlyMs, forbidThrowHome) function buttonControlledThrow(thrower, throwFlyMs, forbidThrowHome)
local targetBase local targetBase
if playdate.buttonIsPressed(playdate.kButtonLeft) then if playdate.buttonIsPressed(playdate.kButtonLeft) then
throwBall(Bases[Third].x, Bases[Third].y, playdate.easingFunctions.linear, throwFlyMs)
targetBase = Bases[Third] targetBase = Bases[Third]
elseif playdate.buttonIsPressed(playdate.kButtonUp) then elseif playdate.buttonIsPressed(playdate.kButtonUp) then
throwBall(Bases[Second].x, Bases[Second].y, playdate.easingFunctions.linear, throwFlyMs)
targetBase = Bases[Second] -- TODO - or shortstop - whoever's closer targetBase = Bases[Second] -- TODO - or shortstop - whoever's closer
elseif playdate.buttonIsPressed(playdate.kButtonRight) then elseif playdate.buttonIsPressed(playdate.kButtonRight) then
throwBall(Bases[First].x, Bases[First].y, playdate.easingFunctions.linear, throwFlyMs)
targetBase = Bases[First] targetBase = Bases[First]
elseif not forbidThrowHome and playdate.buttonIsPressed(playdate.kButtonDown) then elseif not forbidThrowHome and playdate.buttonIsPressed(playdate.kButtonDown) then
throwBall(Bases[Home].x, Bases[Home].y, playdate.easingFunctions.linear, throwFlyMs)
targetBase = Bases[Home] targetBase = Bases[Home]
else else
return false return false
@ -784,9 +780,12 @@ function buttonControlledThrow(thrower, throwFlyMs, forbidThrowHome)
local closestFielder = utils.getNearestOf(fielders, targetBase.x, targetBase.y, function(fielder) local closestFielder = utils.getNearestOf(fielders, targetBase.x, targetBase.y, function(fielder)
return fielder ~= thrower return fielder ~= thrower
end) end)
throwBall(targetBase.x, targetBase.y, playdate.easingFunctions.linear, throwFlyMs)
closestFielder.target = targetBase closestFielder.target = targetBase
secondsSinceLastRunnerMove = 0 secondsSinceLastRunnerMove = 0
offenseMode = Offense.running offenseMode = Offense.running
return true return true
end end