batter -> baserunning.batter
This commit is contained in:
parent
1a68521bd4
commit
c56cae6527
|
@ -117,6 +117,8 @@ function baserunning.newRunner(self)
|
|||
return new
|
||||
end
|
||||
|
||||
baserunning.batter = baserunning:newRunner()
|
||||
|
||||
---@param self table
|
||||
---@param runnerIndex integer
|
||||
function baserunning.runnerScored(self, runnerIndex)
|
||||
|
|
|
@ -71,8 +71,9 @@ C.SmallestBallRadius = 6
|
|||
|
||||
C.BatLength = 50
|
||||
|
||||
---@alias OffenseState table
|
||||
-- TODO: enums implemented this way are probably going to be difficult to serialize!
|
||||
|
||||
---@alias OffenseState table
|
||||
--- An enum for what state the offense is in
|
||||
---@type table<string, OffenseState>
|
||||
C.Offense = {
|
||||
|
@ -82,9 +83,8 @@ C.Offense = {
|
|||
}
|
||||
|
||||
---@alias Side table
|
||||
|
||||
---@type table<string, Side>
|
||||
--- An enum for which side (offense or defense) a team is on.
|
||||
---@type table<string, Side>
|
||||
C.Sides = {
|
||||
offense = {},
|
||||
defense = {},
|
||||
|
|
39
src/main.lua
39
src/main.lua
|
@ -87,9 +87,6 @@ local outs = 0
|
|||
local inning = 1
|
||||
local offenseState = C.Offense.batting
|
||||
|
||||
---@type Runner | nil
|
||||
local batter = baserunning:newRunner()
|
||||
|
||||
local throwMeter = 0
|
||||
|
||||
-- TODO: Replace with a timer, repeatedly reset, instead of setting to 0
|
||||
|
@ -268,28 +265,28 @@ local function buttonControlledThrow(throwFlyMs, forbidThrowHome)
|
|||
end
|
||||
|
||||
local function nextBatter()
|
||||
batter = nil
|
||||
baserunning.batter = nil
|
||||
playdate.timer.new(2000, function()
|
||||
pitchTracker:reset()
|
||||
if not batter then
|
||||
batter = baserunning:newRunner()
|
||||
if not baserunning.batter then
|
||||
baserunning.batter = baserunning:newRunner()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
local function walk()
|
||||
announcer:say("Walk!")
|
||||
batter.nextBase = C.Bases[C.First]
|
||||
batter.prevBase = C.Bases[C.Home]
|
||||
baserunning.batter.nextBase = C.Bases[C.First]
|
||||
baserunning.batter.prevBase = C.Bases[C.Home]
|
||||
offenseState = C.Offense.walking
|
||||
batter = nil
|
||||
baserunning.batter = nil
|
||||
baserunning:updateForcedRunners()
|
||||
nextBatter()
|
||||
end
|
||||
|
||||
local function strikeOut()
|
||||
local outBatter = batter
|
||||
batter = nil
|
||||
local outBatter = baserunning.batter
|
||||
baserunning.batter = nil
|
||||
outRunner(outBatter --[[@as Runner]], "Strike out!")
|
||||
nextBatter()
|
||||
end
|
||||
|
@ -298,8 +295,8 @@ end
|
|||
local function updateBatting(batDeg, batSpeed)
|
||||
local batAngle = math.rad(batDeg)
|
||||
-- TODO: animate bat-flip or something
|
||||
batBase.x = batter and (batter.x + BatterHandPos.x) or 0
|
||||
batBase.y = batter and (batter.y + BatterHandPos.y) or 0
|
||||
batBase.x = baserunning.batter and (baserunning.batter.x + BatterHandPos.x) or 0
|
||||
batBase.y = baserunning.batter and (baserunning.batter.y + BatterHandPos.y) or 0
|
||||
batTip.x = batBase.x + (C.BatLength * math.sin(batAngle))
|
||||
batTip.y = batBase.y + (C.BatLength * math.cos(batAngle))
|
||||
|
||||
|
@ -325,11 +322,11 @@ local function updateBatting(batDeg, batSpeed)
|
|||
local hitBallScaler = gfx.animator.new(2000, 9 + (mult * mult * 0.5), C.SmallestBallRadius, utils.easingHill)
|
||||
throwBall(ballDestX, ballDestY, playdate.easingFunctions.outQuint, 2000, nil, hitBallScaler)
|
||||
|
||||
batter.nextBase = C.Bases[C.First]
|
||||
batter.prevBase = C.Bases[C.Home]
|
||||
baserunning.batter.nextBase = C.Bases[C.First]
|
||||
baserunning.batter.prevBase = C.Bases[C.Home]
|
||||
baserunning:updateForcedRunners()
|
||||
batter.forcedTo = C.Bases[C.First]
|
||||
batter = nil -- Demote batter to a mere runner
|
||||
baserunning.batter.forcedTo = C.Bases[C.First]
|
||||
baserunning.batter = nil -- Demote batter to a mere runner
|
||||
|
||||
Field:haveSomeoneChase(ballDestX, ballDestY)
|
||||
end
|
||||
|
@ -422,7 +419,7 @@ local function updateGameState()
|
|||
|
||||
-- Walk batter to the plate
|
||||
-- TODO: Ensure batter can't be nil, here
|
||||
baserunning:updateRunner(batter, nil, crankLimited, deltaSeconds)
|
||||
baserunning:updateRunner(baserunning.batter, nil, crankLimited, deltaSeconds)
|
||||
|
||||
if secondsSincePitchAllowed > C.PitchAfterSeconds then
|
||||
if playerOnDefense then
|
||||
|
@ -444,8 +441,8 @@ local function updateGameState()
|
|||
throwBall(C.PitchStartX, C.PitchStartY, playdate.easingFunctions.linear, nil, true)
|
||||
Field:resetFielderPositions()
|
||||
offenseState = C.Offense.batting
|
||||
if not batter then
|
||||
batter = baserunning:newRunner()
|
||||
if not baserunning.batter then
|
||||
baserunning.batter = baserunning:newRunner()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -504,7 +501,7 @@ function playdate.update()
|
|||
|
||||
-- TODO? Scale sprites down as y increases
|
||||
for _, runner in pairs(baserunning.runners) do
|
||||
if runner == batter then
|
||||
if runner == baserunning.batter then
|
||||
if batAngleDeg > 50 and batAngleDeg < 200 then
|
||||
PlayerBack:draw(runner.x, runner.y)
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue