Add inning count selection to main menu.
This commit is contained in:
parent
8943eef73f
commit
bb95ef5a63
|
@ -2,6 +2,7 @@
|
||||||
---@class MainMenu
|
---@class MainMenu
|
||||||
MainMenu = {
|
MainMenu = {
|
||||||
mainGameUpdateFunction = nil,
|
mainGameUpdateFunction = nil,
|
||||||
|
---@type fun(settings: Settings)
|
||||||
mainGameInitFunction = nil,
|
mainGameInitFunction = nil,
|
||||||
}
|
}
|
||||||
-- selene: allow(shadowing)
|
-- selene: allow(shadowing)
|
||||||
|
@ -19,8 +20,15 @@ function MainMenu.start(config)
|
||||||
playdate.update = MainMenu.update
|
playdate.update = MainMenu.update
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local inningCountSelection = 3
|
||||||
|
|
||||||
local function startGame()
|
local function startGame()
|
||||||
MainMenu.mainGameInitFunction()
|
MainMenu.mainGameInitFunction({
|
||||||
|
finalInning = inningCountSelection,
|
||||||
|
homeTeamSprites = HomeTeamSprites,
|
||||||
|
awayTeamSprites = AwayTeamSprites,
|
||||||
|
})
|
||||||
|
playdate.resetElapsedTime()
|
||||||
playdate.update = MainMenu.mainGameUpdateFunction
|
playdate.update = MainMenu.mainGameUpdateFunction
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -61,40 +69,32 @@ end
|
||||||
|
|
||||||
local currentLogo = nil
|
local currentLogo = nil
|
||||||
|
|
||||||
local inningCountSelection = 3
|
|
||||||
|
|
||||||
function playdate.upButtonDown()
|
|
||||||
inningCountSelection = inningCountSelection + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
function playdate.downButtonDown()
|
|
||||||
inningCountSelection = math.max(1, inningCountSelection - 1)
|
|
||||||
end
|
|
||||||
|
|
||||||
local itr = 0
|
|
||||||
|
|
||||||
local t = playdate.timer.new(1000)
|
|
||||||
t:reset()
|
|
||||||
function t.updateCallback()
|
|
||||||
itr = itr + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
function MainMenu.update()
|
function MainMenu.update()
|
||||||
playdate.timer.updateTimers()
|
playdate.timer.updateTimers()
|
||||||
crankStartPos = crankStartPos or playdate.getCrankPosition()
|
crankStartPos = crankStartPos or playdate.getCrankPosition()
|
||||||
|
|
||||||
|
gfx.clear()
|
||||||
|
|
||||||
if playdate.getCrankChange() ~= 0 then
|
if playdate.getCrankChange() ~= 0 then
|
||||||
local crankOffset = (crankStartPos - playdate.getCrankPosition()) % 360
|
local crankOffset = (crankStartPos - playdate.getCrankPosition()) % 360
|
||||||
currentLogo = arrayElementFromCrank(Logos, crankOffset).image
|
currentLogo = arrayElementFromCrank(Logos, crankOffset).image
|
||||||
replaceAwayLogo(currentLogo)
|
replaceAwayLogo(currentLogo)
|
||||||
end
|
end
|
||||||
|
|
||||||
gfx.clear()
|
if currentLogo then
|
||||||
if playdate.buttonIsPressed(playdate.kButtonA) then
|
currentLogo:drawScaled(20, C.Center.y + 40, 3)
|
||||||
startGame()
|
end
|
||||||
|
|
||||||
|
if playdate.buttonJustPressed(playdate.kButtonA) then
|
||||||
|
startGame()
|
||||||
|
end
|
||||||
|
if playdate.buttonJustPressed(playdate.kButtonUp) then
|
||||||
|
inningCountSelection = inningCountSelection + 1
|
||||||
|
end
|
||||||
|
if playdate.buttonJustPressed(playdate.kButtonDown) then
|
||||||
|
inningCountSelection = inningCountSelection - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
gfx.drawText(tostring(itr), 200, 120)
|
|
||||||
GameLogo:drawCentered(C.Center.x, 50)
|
GameLogo:drawCentered(C.Center.x, 50)
|
||||||
|
|
||||||
StartFont:drawTextAligned("Press A to start!", C.Center.x, 140, kTextAlignment.center)
|
StartFont:drawTextAligned("Press A to start!", C.Center.x, 140, kTextAlignment.center)
|
||||||
|
|
44
src/main.lua
44
src/main.lua
|
@ -53,6 +53,16 @@ local fielding = Fielding.new()
|
||||||
-- GLOBAL STATE --
|
-- GLOBAL STATE --
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
--- Well, maybe not "Settings", but passive state that probably won't change much, if at all, during a game.
|
||||||
|
---@class Settings
|
||||||
|
local settings = {
|
||||||
|
finalInning = 3,
|
||||||
|
---@type SpriteCollection
|
||||||
|
awayTeamSprites = nil,
|
||||||
|
---@type SpriteCollection
|
||||||
|
homeTeamSprites = nil,
|
||||||
|
}
|
||||||
|
|
||||||
local deltaSeconds = 0
|
local deltaSeconds = 0
|
||||||
local ball = Ball.new(gfx.animator)
|
local ball = Ball.new(gfx.animator)
|
||||||
|
|
||||||
|
@ -181,7 +191,7 @@ end
|
||||||
local function nextHalfInning()
|
local function nextHalfInning()
|
||||||
pitchTracker:reset()
|
pitchTracker:reset()
|
||||||
local currentlyFieldingTeam = battingTeam == teams.home and teams.away or teams.home
|
local currentlyFieldingTeam = battingTeam == teams.home and teams.away or teams.home
|
||||||
local gameOver = inning == 9 and teams.away.score ~= teams.home.score
|
local gameOver = inning == settings.finalInning and teams.away.score ~= teams.home.score
|
||||||
if not gameOver then
|
if not gameOver then
|
||||||
fielding:celebrate()
|
fielding:celebrate()
|
||||||
secondsSinceLastRunnerMove = -7
|
secondsSinceLastRunnerMove = -7
|
||||||
|
@ -199,12 +209,12 @@ local function nextHalfInning()
|
||||||
battingTeam = currentlyFieldingTeam
|
battingTeam = currentlyFieldingTeam
|
||||||
playdate.timer.new(2000, function()
|
playdate.timer.new(2000, function()
|
||||||
if battingTeam == teams.home then
|
if battingTeam == teams.home then
|
||||||
battingTeamSprites = HomeTeamSprites
|
battingTeamSprites = settings.homeTeamSprites
|
||||||
runnerBlipper = HomeTeamBlipper
|
runnerBlipper = HomeTeamBlipper
|
||||||
fieldingTeamSprites = AwayTeamSprites
|
fieldingTeamSprites = settings.awayTeamSprites
|
||||||
else
|
else
|
||||||
battingTeamSprites = AwayTeamSprites
|
battingTeamSprites = settings.awayTeamSprites
|
||||||
fieldingTeamSprites = HomeTeamSprites
|
fieldingTeamSprites = settings.homeTeamSprites
|
||||||
runnerBlipper = AwayTeamBlipper
|
runnerBlipper = AwayTeamBlipper
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
@ -521,7 +531,9 @@ function mainGameUpdate()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function mainGameInit()
|
---@param s Settings
|
||||||
|
local function mainGameInit(s)
|
||||||
|
settings = s
|
||||||
fielding:resetFielderPositions(teams.home.benchPosition)
|
fielding:resetFielderPositions(teams.home.benchPosition)
|
||||||
playdate.timer.new(2000, function()
|
playdate.timer.new(2000, function()
|
||||||
launchBall(C.PitchStartX, C.PitchStartY, playdate.easingFunctions.linear, nil, false)
|
launchBall(C.PitchStartX, C.PitchStartY, playdate.easingFunctions.linear, nil, false)
|
||||||
|
@ -530,10 +542,10 @@ local function mainGameInit()
|
||||||
BootTune:setFinishCallback(function()
|
BootTune:setFinishCallback(function()
|
||||||
TinnyBackground:play()
|
TinnyBackground:play()
|
||||||
end)
|
end)
|
||||||
battingTeamSprites = AwayTeamSprites
|
battingTeamSprites = settings.awayTeamSprites
|
||||||
fieldingTeamSprites = HomeTeamSprites
|
fieldingTeamSprites = settings.homeTeamSprites
|
||||||
HomeTeamBlipper = blipper.new(100, HomeTeamSprites.smiling, HomeTeamSprites.lowHat)
|
HomeTeamBlipper = blipper.new(100, settings.homeTeamSprites.smiling, settings.homeTeamSprites.lowHat)
|
||||||
AwayTeamBlipper = blipper.new(100, AwayTeamSprites.smiling, AwayTeamSprites.lowHat)
|
AwayTeamBlipper = blipper.new(100, settings.awayTeamSprites.smiling, settings.awayTeamSprites.lowHat)
|
||||||
runnerBlipper = battingTeam == teams.away and AwayTeamBlipper or HomeTeamBlipper
|
runnerBlipper = battingTeam == teams.away and AwayTeamBlipper or HomeTeamBlipper
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -543,14 +555,10 @@ local function init()
|
||||||
playdate.setMenuImage(gfx.image.new("images/game/menu-image.png"))
|
playdate.setMenuImage(gfx.image.new("images/game/menu-image.png"))
|
||||||
playdate.getSystemMenu():addMenuItem("Restart game", function() end) -- TODO?
|
playdate.getSystemMenu():addMenuItem("Restart game", function() end) -- TODO?
|
||||||
|
|
||||||
-- TODO: A lot of stuff ends up hinky here, because animators are ticking from the moment they initialize.
|
MainMenu.start({
|
||||||
-- TODO: Much needs to be redesigned to only init when a game is *actually* starting.
|
mainGameUpdateFunction = mainGameUpdate,
|
||||||
-- MainMenu.start({
|
mainGameInitFunction = mainGameInit,
|
||||||
-- mainGameUpdateFunction = mainGameUpdate,
|
})
|
||||||
-- mainGameInitFunction = mainGameInit,
|
|
||||||
-- })
|
|
||||||
playdate.update = mainGameUpdate
|
|
||||||
mainGameInit()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
init()
|
init()
|
||||||
|
|
Loading…
Reference in New Issue