diff --git a/.luarc.json b/.luarc.json index 8d52fef..28cda51 100644 --- a/.luarc.json +++ b/.luarc.json @@ -2,7 +2,6 @@ "Lua.runtime.version": "Lua 5.4", "Lua.diagnostics.disable": ["undefined-global", "lowercase-global"], "Lua.diagnostics.globals": ["playdate", "import"], - "Lua.runtime.nonstandardSymbol": ["+=", "-=", "*=", "/="], "Lua.workspace.library": ["/home/sage/Downloads/PlaydateSDK-2.6.2/CoreLibs"], "Lua.workspace.preloadFileSize": 1000 } \ No newline at end of file diff --git a/src/assets.lua b/src/assets.lua index 2a61df9..c59bfab 100644 --- a/src/assets.lua +++ b/src/assets.lua @@ -29,3 +29,17 @@ Minimap = playdate.graphics.image.new("images/game/Minimap.png") --selene: allow(unscoped_variables) GrassBackground = playdate.graphics.image.new("images/game/GrassBackground.png") +--selene: allow(unused_variable) +--selene: allow(unscoped_variables) +BatCrackReverb = playdate.sound.sampleplayer.new("sounds/BatCrackReverb.wav") + +--selene: allow(unused_variable) +--selene: allow(unscoped_variables) +BootTune = playdate.sound.sampleplayer.new("music/BootTune.wav") +--selene: allow(unused_variable) +--selene: allow(unscoped_variables) +BootTuneOrgany = playdate.sound.sampleplayer.new("music/BootTuneOrgany.wav") +--selene: allow(unused_variable) +--selene: allow(unscoped_variables) +TinnyBackground = playdate.sound.sampleplayer.new("music/TinnyBackground.wav") + diff --git a/src/assets.lua2p b/src/assets.lua2p index 93b6c0e..5460604 100644 --- a/src/assets.lua2p +++ b/src/assets.lua2p @@ -20,3 +20,5 @@ function generatedFileWarning() end) !!(generatedFileWarning()) !!(dirLookup('images/game', 'png', 'playdate.graphics.image.new')) +!!(dirLookup('sounds', 'wav', 'playdate.sound.sampleplayer.new')) +!!(dirLookup('music', 'wav', 'playdate.sound.sampleplayer.new')) diff --git a/src/constants.lua b/src/constants.lua index e112d31..12255dd 100644 --- a/src/constants.lua +++ b/src/constants.lua @@ -60,6 +60,8 @@ C.PitchStartY, C.PitchEndY = 105, 240 --- The max distance at which a fielder can tag out a runner. C.TagDistance = 15 +C.BallCatchHitbox = 3 + --- The max distance at which a runner can be considered on base. C.BaseHitbox = 10 diff --git a/src/main.lua b/src/main.lua index 1ee8855..17cb06c 100644 --- a/src/main.lua +++ b/src/main.lua @@ -39,17 +39,11 @@ import 'draw/fielder' -- selene: allow(shadowing) local gfx , C = playdate.graphics, C -local BootTune = playdate.sound.sampleplayer.new("sounds/boot-tune.wav") --- local BootTune = playdate.sound.sampleplayer.new("sounds/boot-tune-organy.wav") -local TinnyBackground = playdate.sound.sampleplayer.new("sounds/tinny-background.wav") -local BatCrackSound = playdate.sound.sampleplayer.new("sounds/bat-crack-reverb.wav") - local PlayerImageBlipper = blipper.new(100, Player, PlayerLowHat) local FielderDanceAnimator = gfx.animator.new(1, 10, 0, utils.easingHill) FielderDanceAnimator.repeatCount = C.DanceBounceCount - 1 --- selene: allow(unused_variable) function fieldersDance() FielderDanceAnimator:reset(C.DanceBounceMs) end @@ -289,15 +283,13 @@ function isTouchingBase(x, y) end) end -local BallCatchHitbox = 3 - --- Returns true only if the given point is touching the ball at its current position ---@param x number ---@param y number ---@return boolean, number function isTouchingBall(x, y) local ballDistance = utils.distanceBetween(x, y, ball.x, ball.y) - return ballDistance < BallCatchHitbox, ballDistance + return ballDistance < C.BallCatchHitbox, ballDistance end ---@param base Base @@ -347,32 +339,34 @@ function outRunner(runner, message) updateForcedRunners() announcer:say(message or "YOU'RE OUT!") - if outs == 3 then - local currentlyFieldingTeam = battingTeam == teams.home and teams.away or teams.home - local gameOver = inning == 9 and teams.away.score ~= teams.home.score - if not gameOver then - fieldersDance() - secondsSinceLastRunnerMove = -7 - benchAllFielders(currentlyFieldingTeam.benchPosition) - announcer:say("SWITCHING SIDES...") - end - while #runners > 0 do - outRunners[#outRunners + 1] = table.remove(runners, #runners) - end - -- Delay to keep end-of-inning on the scoreboard for a few seconds - playdate.timer.new(3000, function() - outs = 0 - battingTeam = currentlyFieldingTeam - if gameOver then - announcer:say("AND THAT'S THE BALL GAME!") - else - resetFielderPositions() - if battingTeam == teams.home then - inning = inning + 1 - end - end - end) + if outs < 3 then + return end + + local currentlyFieldingTeam = battingTeam == teams.home and teams.away or teams.home + local gameOver = inning == 9 and teams.away.score ~= teams.home.score + if not gameOver then + fieldersDance() + secondsSinceLastRunnerMove = -7 + benchAllFielders(currentlyFieldingTeam.benchPosition) + announcer:say("SWITCHING SIDES...") + end + while #runners > 0 do + outRunners[#outRunners + 1] = table.remove(runners, #runners) + end + -- Delay to keep end-of-inning on the scoreboard for a few seconds + playdate.timer.new(3000, function() + outs = 0 + battingTeam = currentlyFieldingTeam + if gameOver then + announcer:say("AND THAT'S THE BALL GAME!") + else + resetFielderPositions() + if battingTeam == teams.home then + inning = inning + 1 + end + end + end) end ---@param runnerIndex number @@ -642,7 +636,7 @@ function updateBatting(batDeg, batSpeed) and utils.pointDirectlyUnderLine(ball.x, ball.y, batBase.x, batBase.y, batTip.x, batTip.y, C.Screen.H) and ball.y < 232 then - BatCrackSound:play() + BatCrackReverb:play() offenseMode = C.Offense.running local ballAngle = batAngle + math.rad(90) diff --git a/src/sounds/boot-tune.wav b/src/music/BootTune.wav similarity index 100% rename from src/sounds/boot-tune.wav rename to src/music/BootTune.wav diff --git a/src/sounds/boot-tune-organy.wav b/src/music/BootTuneOrgany.wav similarity index 100% rename from src/sounds/boot-tune-organy.wav rename to src/music/BootTuneOrgany.wav diff --git a/src/sounds/tinny-background.wav b/src/music/TinnyBackground.wav similarity index 100% rename from src/sounds/tinny-background.wav rename to src/music/TinnyBackground.wav diff --git a/src/sounds/bat-crack-reverb.wav b/src/sounds/BatCrackReverb.wav similarity index 100% rename from src/sounds/bat-crack-reverb.wav rename to src/sounds/BatCrackReverb.wav