Add some quick MenuMusic

And extract a bit more pitchTracker logic
This commit is contained in:
Sage Vaillancourt 2025-02-18 15:50:22 -05:00
parent 2d812f2046
commit aebbc35bac
5 changed files with 46 additions and 40 deletions

View File

@ -41,6 +41,8 @@ BootTune = playdate.sound.sampleplayer.new("music/BootTune.wav")
BootTuneOrgany = playdate.sound.sampleplayer.new("music/BootTuneOrgany.wav")
-- luacheck: ignore
TinnyBackground = playdate.sound.sampleplayer.new("music/TinnyBackground.wav")
-- luacheck: ignore
MenuMusic = playdate.sound.sampleplayer.new("music/MenuMusic.wav")
Logos = {
{ name = "Base", image = playdate.graphics.image.new("images/game/logos/Base.png") },

View File

@ -11,6 +11,7 @@ local StartFont <const> = gfx.font.new("fonts/Roobert-20-Medium.pft")
--- Will replace playdate.update when the menu is done.
---@param next { new: fun(settings: Settings): { update: fun(self) } }
function MainMenu.start(next)
MenuMusic:play(0)
MainMenu.next = next
playdate.update = MainMenu.update
end
@ -25,6 +26,7 @@ local function startGame()
})
playdate.resetElapsedTime()
transitionBetween(MainMenu, next)
MenuMusic:setPaused(true)
end
local function pausingEaser(baseEaser)

View File

@ -490,11 +490,7 @@ function Game:updateGameState()
end
if self.state.offenseState == C.Offense.batting then
if self.state.ball.y < C.StrikeZoneStartY then
pitchTracker.recordedPitchX = nil
elseif not pitchTracker.recordedPitchX then
pitchTracker.recordedPitchX = self.state.ball.x
end
pitchTracker:recordIfPassed(self.state.ball)
local pitcher = self.fielding.fielders.pitcher
if utils.distanceBetween(pitcher.x, pitcher.y, C.PitcherStartPos.x, C.PitcherStartPos.y) < C.BaseHitbox then

BIN
src/music/MenuMusic.wav Normal file

Binary file not shown.

View File

@ -250,10 +250,8 @@ function utils.totalScores(stats)
end
PitchOutcomes = {
Strike = {},
StrikeOut = {},
Ball = {},
Walk = {},
StrikeOut = "StrikeOut",
Walk = "Walk",
}
pitchTracker = {
@ -263,39 +261,47 @@ pitchTracker = {
strikes = 0,
balls = 0,
reset = function(self)
self.strikes = 0
self.balls = 0
end,
---@param didSwing boolean
---@param fieldingTeamInningData TeamInningData
updatePitchCounts = function(self, didSwing, fieldingTeamInningData)
if not self.recordedPitchX then
return
end
local currentPitchingStats = fieldingTeamInningData.pitching
if didSwing or self.recordedPitchX > C.StrikeZoneStartX and self.recordedPitchX < C.StrikeZoneEndX then
self.strikes = self.strikes + 1
currentPitchingStats.strikes = currentPitchingStats.strikes + 1
if self.strikes >= 3 then
self:reset()
return PitchOutcomes.StrikeOut
end
else
self.balls = self.balls + 1
currentPitchingStats.balls = currentPitchingStats.balls + 1
if self.balls >= 4 then
self:reset()
return PitchOutcomes.Walk
end
end
end,
}
function pitchTracker:reset()
self.strikes = 0
self.balls = 0
end
function pitchTracker:recordIfPassed(ball)
if ball.y < C.StrikeZoneStartY then
self.recordedPitchX = nil
elseif not pitchTracker.recordedPitchX then
self.recordedPitchX = ball.x
end
end
---@param didSwing boolean
---@param fieldingTeamInningData TeamInningData
function pitchTracker:updatePitchCounts(didSwing, fieldingTeamInningData)
if not self.recordedPitchX then
return
end
local currentPitchingStats = fieldingTeamInningData.pitching
if didSwing or self.recordedPitchX > C.StrikeZoneStartX and self.recordedPitchX < C.StrikeZoneEndX then
self.strikes = self.strikes + 1
currentPitchingStats.strikes = currentPitchingStats.strikes + 1
if self.strikes >= 3 then
self:reset()
return PitchOutcomes.StrikeOut
end
else
self.balls = self.balls + 1
currentPitchingStats.balls = currentPitchingStats.balls + 1
if self.balls >= 4 then
self:reset()
return PitchOutcomes.Walk
end
end
end
-----------------
-- Throw Meter --
-----------------