Add basic announcement messages.

Switch to checking based on __types.lua instead of __stub.lua
New font for announcement. Move Full Circle font out of subdirectory.
This commit is contained in:
Sage Vaillancourt 2025-02-02 16:15:29 -05:00
parent 66e3d2bb01
commit 073140f700
8 changed files with 639 additions and 36 deletions

View File

@ -5,7 +5,7 @@ all:
check: check:
stylua -c src/ stylua -c src/
cat __stub.ext.lua <(sed 's/^function/-- selene: allow(unused_variable)\nfunction/' ${PLAYDATE_SDK_PATH}/CoreLibs/__stub.lua) ${SOURCE_FILES} | grep -v '^import' | sed 's/<const>//g' | selene - cat __stub.ext.lua <(sed 's/^function/-- selene: allow(unused_variable)\nfunction/' ${PLAYDATE_SDK_PATH}/CoreLibs/__types.lua) ${SOURCE_FILES} | grep -v '^import' | sed 's/<const>//g' | selene -
lint: lint:
stylua src/ stylua src/

View File

@ -1,31 +1,15 @@
-- A small additional stub to keep Selene from complaining about playdate being missing. -- A small additional stub to keep Selene from complaining about playdate being missing.
-- Strictly, just putting `playdate = {}` would alleviate these warnings, but I've also -- These warning-allieviators could also be injected directly into __types.lua
-- found that this quick structure, *actually* prepended to __stub.lua can help -- Base __types.lua can be found at https://github.com/balpha/playdate-types
-- SumnekoLua (an IntelliJ plugin) better provide autocompletion.
-- selene: allow(unused_variable) -- selene: allow(unused_variable)
-- selene: allow(unscoped_variables) -- selene: allow(unscoped_variables)
playdate = { playdate = playdate
datastore = {},
display = {}, -- selene: allow(unscoped_variables)
file = {}, -- selene: allow(unused_variable)
frameTimer = {}, json = json
geometry = {},
graphics = {}, -- selene: allow(unused_variable)
inputHandlers = {}, -- selene: allow(unscoped_variables)
json = {}, kTextAlignment = kTextAlignment
keyboard = {},
math = {},
menu = {
item = {}
},
pathfinder = {},
simulator = {},
sound = {
sampleplayer = {}
},
string = {},
table = {},
timer = {},
ui = {}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

File diff suppressed because one or more lines are too long

View File

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -4,6 +4,7 @@ import 'CoreLibs/animator.lua'
import 'CoreLibs/easing.lua' import 'CoreLibs/easing.lua'
import 'CoreLibs/graphics.lua' import 'CoreLibs/graphics.lua'
import 'CoreLibs/object.lua' import 'CoreLibs/object.lua'
import 'CoreLibs/timer.lua'
import 'CoreLibs/ui.lua' import 'CoreLibs/ui.lua'
import 'graphics.lua' import 'graphics.lua'
@ -28,10 +29,10 @@ local Screen <const> = {
local Center <const> = xy(Screen.W / 2, Screen.H / 2) local Center <const> = xy(Screen.W / 2, Screen.H / 2)
local BatCrackSound <const> = playdate.sound.sampleplayer.new("sounds/bat-crack-reverb.wav") local BatCrackSound <const> = playdate.sound.sampleplayer.new("sounds/bat-crack-reverb.wav")
local GrassBackground <const> = gfx.image.new("images/game/grass.png") --[[@as PlaydateGraphicsImage]] local GrassBackground <const> = gfx.image.new("images/game/grass.png") --[[@as pd_image]]
local PlayerFrown <const> = gfx.image.new("images/game/player-frown.png") --[[@as PlaydateGraphicsImage]] local PlayerFrown <const> = gfx.image.new("images/game/player-frown.png") --[[@as pd_image]]
local ScoreFont <const> = gfx.font.new("fonts/Full Circle/font-full-circle.pft") local ScoreFont <const> = gfx.font.new("fonts/font-full-circle.pft")
local PlayerImageBlipper <const> = blipper.new(100, "images/game/player.png", "images/game/player-lowhat.png") local PlayerImageBlipper <const> = blipper.new(100, "images/game/player.png", "images/game/player-lowhat.png")
@ -57,8 +58,8 @@ local batTip <const> = xy(0, 0)
local TagDistance <const> = 20 local TagDistance <const> = 20
local ball <const> = { local ball <const> = {
x = Center.x, x = Center.x --[[@as number]],
y = Center.y, y = Center.y --[[@as number]],
size = 6, size = 6,
heldBy = nil --[[@type Runner | nil]], heldBy = nil --[[@type Runner | nil]],
} }
@ -237,11 +238,15 @@ local outs = 0
local homeScore = 0 local homeScore = 0
local awayScore = 0 local awayScore = 0
function updateForcedRunners() end
function outRunner(runnerIndex) function outRunner(runnerIndex)
outs = math.min(3, outs + 1) outs = math.min(3, outs + 1)
outRunners[#outRunners + 1] = runners[runnerIndex] outRunners[#outRunners + 1] = runners[runnerIndex]
table.remove(runners, runnerIndex) table.remove(runners, runnerIndex)
FielderDanceAnimator:reset() FielderDanceAnimator:reset()
updateForcedRunners()
announcer:say("YOU'RE OUT!")
end end
-- TODO: Away score -- TODO: Away score
@ -249,6 +254,7 @@ function score(runnerIndex)
outRunners[#outRunners + 1] = runners[runnerIndex] outRunners[#outRunners + 1] = runners[runnerIndex]
table.remove(runners, runnerIndex) table.remove(runners, runnerIndex)
homeScore = homeScore + 1 homeScore = homeScore + 1
announcer:say("SCORE!")
end end
function updateFielders() function updateFielders()
@ -335,7 +341,7 @@ function updateRunners()
end end
-- TODO: Also move if forced to 😅 -- TODO: Also move if forced to 😅
local autoRun = nearestBaseDistance > 40 and mult * autoRunSpeed local autoRun = (nearestBaseDistance > 40 or runner.forcedTo) and mult * autoRunSpeed
or nearestBaseDistance < 5 and 0 or nearestBaseDistance < 5 and 0
or (nearestBase == runner.nextBase and autoRunSpeed or -1 * autoRunSpeed) or (nearestBase == runner.nextBase and autoRunSpeed or -1 * autoRunSpeed)
mult = autoRun + (appliedSpeed / 20) mult = autoRun + (appliedSpeed / 20)
@ -562,11 +568,11 @@ function drawScoreboard()
gfx.drawText("HOME ", x - 7, y - 38) gfx.drawText("HOME ", x - 7, y - 38)
local homeScoreText = homeScore > 9 and homeScore or " " .. homeScore local homeScoreText = homeScore > 9 and homeScore or " " .. homeScore
gfx.drawText(homeScoreText, x - 7 + numOffsetX, y - 38) gfx.drawText("" .. homeScoreText, x - 7 + numOffsetX, y - 38)
gfx.drawText("AWAY ", x - 7, y - 22) gfx.drawText("AWAY ", x - 7, y - 22)
local awayScoreText = awayScore > 9 and awayScore or " " .. awayScore local awayScoreText = awayScore > 9 and awayScore or " " .. awayScore
gfx.drawText(awayScoreText, x - 7 + numOffsetX, y - 22) gfx.drawText("" .. awayScoreText, x - 7 + numOffsetX, y - 22)
gfx.setImageDrawMode(originalDrawMode) gfx.setImageDrawMode(originalDrawMode)
end end
@ -574,6 +580,7 @@ end
function playdate.update() function playdate.update()
updateGameState() updateGameState()
playdate.graphics.animation.blinker.updateAll() playdate.graphics.animation.blinker.updateAll()
playdate.timer.updateTimers()
gfx.clear() gfx.clear()
@ -614,6 +621,7 @@ function playdate.update()
end end
drawScoreboard() drawScoreboard()
announcer:draw(Center.x, 10)
end end
init() init()

View File

@ -132,3 +132,23 @@ function buildCache(fetcher)
end, end,
} }
end end
local AnnouncementFont <const> = playdate.graphics.font.new("fonts/Roobert-20-Medium.pft")
-- selene: allow(unscoped_variables)
announcer = {}
function announcer.say(self, text, durationMs)
self.text = text
durationMs = durationMs and durationMs or 3000
playdate.timer.new(durationMs, function()
self.text = nil
end)
end
function announcer.draw(self, x, y)
if not self.text then
return
end
AnnouncementFont:drawTextAligned(self.text, x, y, kTextAlignment.center)
end