Allow for more complex pitches.

Add some very mid music.
This commit is contained in:
Sage Vaillancourt 2025-02-04 11:30:18 -05:00
parent fb991e48df
commit 1d55c27fa2
4 changed files with 54 additions and 20 deletions

View File

@ -48,6 +48,9 @@ local Screen <const> = {
local Center <const> = xy(Screen.W / 2, Screen.H / 2) local Center <const> = xy(Screen.W / 2, Screen.H / 2)
local BootTune <const> = playdate.sound.sampleplayer.new("sounds/boot-tune.wav")
-- local BootTune <const> = playdate.sound.sampleplayer.new("sounds/boot-tune-organy.wav")
local TinnyBackground <const> = playdate.sound.sampleplayer.new("sounds/tinny-background.wav")
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 pd_image]] 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 pd_image]] local PlayerFrown <const> = gfx.image.new("images/game/player-frown.png") --[[@as pd_image]]
@ -72,16 +75,36 @@ local PitchFlyMs <const> = 1050
local PitchStartX <const> = 195 local PitchStartX <const> = 195
local PitchStartY <const>, PitchEndY <const> = 105, 240 local PitchStartY <const>, PitchEndY <const> = 105, 240
local PitchesX <const> = { local ballAnimatorY = gfx.animator.new(0, BallOffscreen, BallOffscreen, playdate.easingFunctions.linear)
-- Fastball local ballAnimatorX = gfx.animator.new(0, BallOffscreen, BallOffscreen, playdate.easingFunctions.linear)
gfx.animator.new(0, PitchStartX, PitchStartX, playdate.easingFunctions.linear),
-- Slider
gfx.animator.new(PitchFlyMs, PitchStartX - 20, PitchStartX, easingHill),
-- Curve ball
gfx.animator.new(PitchFlyMs, PitchStartX + 20, PitchStartX, easingHill),
}
local PitchAnimatorY <const> = gfx.animator.new(PitchFlyMs, PitchStartY, PitchEndY, playdate.easingFunctions.linear) local Pitches <const> = {
-- Fastball
{
x = gfx.animator.new(0, PitchStartX, PitchStartX, playdate.easingFunctions.linear),
y = gfx.animator.new(PitchFlyMs / 1.3, PitchStartY, PitchEndY, playdate.easingFunctions.linear),
},
-- Slider
{
x = gfx.animator.new(PitchFlyMs, PitchStartX - 20, PitchStartX, easingHill),
y = gfx.animator.new(PitchFlyMs, PitchStartY, PitchEndY, playdate.easingFunctions.linear),
},
-- Curve ball
{
x = gfx.animator.new(PitchFlyMs, PitchStartX + 20, PitchStartX, easingHill),
y = gfx.animator.new(PitchFlyMs, PitchStartY, PitchEndY, playdate.easingFunctions.linear),
},
-- Wobbbleball
{
x = {
currentValue = function()
return PitchStartX + (10 * math.sin((ballAnimatorY:currentValue() - PitchStartY) / 10))
end,
reset = function() end,
},
y = gfx.animator.new(PitchFlyMs * 1.3, PitchStartY, PitchEndY, playdate.easingFunctions.linear),
},
}
local CrankOffsetDeg <const> = 90 local CrankOffsetDeg <const> = 90
local BatOffset <const> = xy(10, 25) local BatOffset <const> = xy(10, 25)
@ -91,10 +114,12 @@ local batTip <const> = xy(0, 0)
local TagDistance <const> = 20 local TagDistance <const> = 20
local SmallestBallRadius <const> = 6
local ball <const> = { local ball <const> = {
x = Center.x --[[@as number]], x = Center.x --[[@as number]],
y = Center.y --[[@as number]], y = Center.y --[[@as number]],
size = 6, size = SmallestBallRadius,
heldBy = nil --[[@type Runner | nil]], heldBy = nil --[[@type Runner | nil]],
} }
@ -107,14 +132,11 @@ local Modes <const> = {
local currentMode = Modes.batting local currentMode = Modes.batting
local ballAnimatorY = gfx.animator.new(0, BallOffscreen, BallOffscreen, playdate.easingFunctions.linear)
local ballAnimatorX = gfx.animator.new(0, BallOffscreen, BallOffscreen, playdate.easingFunctions.linear)
-- TODO? Replace this AND ballSizeAnimator with a ballHeightAnimator -- TODO? Replace this AND ballSizeAnimator with a ballHeightAnimator
-- ...that might lose some of the magic of both. Compromise available? idk -- ...that might lose some of the magic of both. Compromise available? idk
local ballFloatAnimator <const> = gfx.animator.new(2000, -60, 0, easingHill) local ballFloatAnimator = gfx.animator.new(2000, -60, 0, easingHill)
local BallSizeMs = 2000 local BallSizeMs = 2000
local ballSizeAnimator = gfx.animator.new(BallSizeMs, 9, 6, easingHill) local ballSizeAnimator = gfx.animator.new(BallSizeMs, 9, SmallestBallRadius, easingHill)
local HitMult = 20 local HitMult = 20
@ -220,7 +242,7 @@ function throwBall(destX, destY, easingFunc, flyTimeMs, floaty, customBallScaler
ballSizeAnimator = customBallScaler ballSizeAnimator = customBallScaler
else else
-- TODO? Scale based on distance? -- TODO? Scale based on distance?
ballSizeAnimator = gfx.animator.new(flyTimeMs, 9, 6, easingHill) ballSizeAnimator = gfx.animator.new(flyTimeMs, 9, SmallestBallRadius, easingHill)
end end
ballAnimatorY = gfx.animator.new(flyTimeMs, ball.y, destY, easingFunc) ballAnimatorY = gfx.animator.new(flyTimeMs, ball.y, destY, easingFunc)
ballAnimatorX = gfx.animator.new(flyTimeMs, ball.x, destX, easingFunc) ballAnimatorX = gfx.animator.new(flyTimeMs, ball.x, destX, easingFunc)
@ -238,8 +260,16 @@ local catcherThrownBall = false
function pitch() function pitch()
catcherThrownBall = false catcherThrownBall = false
currentMode = Modes.batting currentMode = Modes.batting
ballAnimatorX = PitchesX[math.random(#PitchesX)]
ballAnimatorY = PitchAnimatorY local current = Pitches[math.random(#Pitches)]
ballAnimatorX = current.x
ballAnimatorY = current.y or Pitches[1].y
-- TODO: This would need to be sanely replaced in throwBall() etc.
-- if current.z then
-- ballFloatAnimator = current.z
-- ballFloatAnimator:reset()
-- end
ballAnimatorX:reset() ballAnimatorX:reset()
ballAnimatorY:reset() ballAnimatorY:reset()
@ -515,6 +545,10 @@ function init()
playdate.timer.new(2000, function() playdate.timer.new(2000, function()
throwBall(PitchStartX, PitchStartY, playdate.easingFunctions.linear, nil, false) throwBall(PitchStartX, PitchStartY, playdate.easingFunctions.linear, nil, false)
end) end)
BootTune:play()
BootTune:setFinishCallback(function()
TinnyBackground:play()
end)
end end
function tryToThrowOut(self) function tryToThrowOut(self)
@ -536,7 +570,7 @@ local batAngleDeg
function updateBatting() function updateBatting()
if ball.y < BallOffscreen then if ball.y < BallOffscreen then
ball.y = ballAnimatorY:currentValue() + ballFloatAnimator:currentValue() ball.y = ballAnimatorY:currentValue() + ballFloatAnimator:currentValue()
ball.size = 6 ball.size = SmallestBallRadius -- ballFloatAnimator:currentValue()
end end
batAngleDeg = (playdate.getCrankPosition() + CrankOffsetDeg) % 360 batAngleDeg = (playdate.getCrankPosition() + CrankOffsetDeg) % 360
@ -571,7 +605,7 @@ function updateBatting()
playdate.easingFunctions.outQuint, playdate.easingFunctions.outQuint,
2000, 2000,
nil, nil,
gfx.animator.new(2000, 9 + (mult * mult * 0.5), 6, easingHill) gfx.animator.new(2000, 9 + (mult * mult * 0.5), SmallestBallRadius, easingHill)
) )
fielders.first.target = Bases[First] fielders.first.target = Bases[First]

Binary file not shown.

BIN
src/sounds/boot-tune.wav Normal file

Binary file not shown.

Binary file not shown.