diff --git a/src/main.lua b/src/main.lua index 1e057f9..9b54622 100644 --- a/src/main.lua +++ b/src/main.lua @@ -381,6 +381,10 @@ function Game:strikeOut() self:nextBatter() end +function Game:saveToFile() + playdate.datastore.write(self, "data", true) +end + local SwingBackDeg = 30 local SwingForwardDeg = 170 @@ -413,6 +417,7 @@ function Game:updateBatting(offenseHandler) end -- Hit! + self:saveToFile() BatCrackReverb:play() self.state.offenseState = C.Offense.running @@ -440,7 +445,8 @@ function Game:updateBatting(offenseHandler) return end - if utils.pointIsSquarelyAboveLine(utils.xy(ballDest.x, ballDest.y), C.OutfieldWall) then + local isHomeRun = utils.pointIsSquarelyAboveLine(ballDest, C.OutfieldWall) + if isHomeRun then playdate.timer.new(flyTimeMs, function() -- Verify that the home run wasn't intercepted if utils.within(1, ball.x, ballDest.x) and utils.within(1, ball.y, ballDest.y) then @@ -503,6 +509,7 @@ function Game:updatePitching(defenseHandler) end if pitchTracker.secondsSinceLastPitch > C.ReturnToPitcherAfterSeconds and not self.state.pitchIsOver then + self:saveToFile() local outcome = pitchTracker:updatePitchCounts(self.state.didSwing, self:fieldingTeamCurrentInning()) if outcome == PitchOutcomes.StrikeOut then self:strikeOut() diff --git a/src/pitching.lua b/src/pitching.lua index 893eaa6..410ac4a 100644 --- a/src/pitching.lua +++ b/src/pitching.lua @@ -1,5 +1,5 @@ ---@alias SimpleAnimator { currentValue: fun(self): number; reset: fun(self, durationMs: number | nil) } ----@alias Pitch fun(ball: Ball): { x: SimpleAnimator, y: SimpleAnimator, z: SimpleAnimator | nil } +---@alias Pitch fun(accuracy: number, ball: Ball): { x: SimpleAnimator, y: SimpleAnimator, z: SimpleAnimator | nil } ---@type pd_graphics_lib local gfx = playdate.graphics