diff --git a/src/main.lua b/src/main.lua index a5d70d8..1b1202b 100644 --- a/src/main.lua +++ b/src/main.lua @@ -48,6 +48,9 @@ local Screen = { local Center = xy(Screen.W / 2, Screen.H / 2) +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 GrassBackground = gfx.image.new("images/game/grass.png") --[[@as pd_image]] local PlayerFrown = gfx.image.new("images/game/player-frown.png") --[[@as pd_image]] @@ -72,16 +75,36 @@ local PitchFlyMs = 1050 local PitchStartX = 195 local PitchStartY , PitchEndY = 105, 240 -local PitchesX = { - -- Fastball - 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 ballAnimatorY = gfx.animator.new(0, BallOffscreen, BallOffscreen, playdate.easingFunctions.linear) +local ballAnimatorX = gfx.animator.new(0, BallOffscreen, BallOffscreen, playdate.easingFunctions.linear) -local PitchAnimatorY = gfx.animator.new(PitchFlyMs, PitchStartY, PitchEndY, playdate.easingFunctions.linear) +local Pitches = { + -- 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 = 90 local BatOffset = xy(10, 25) @@ -91,10 +114,12 @@ local batTip = xy(0, 0) local TagDistance = 20 +local SmallestBallRadius = 6 + local ball = { x = Center.x --[[@as number]], y = Center.y --[[@as number]], - size = 6, + size = SmallestBallRadius, heldBy = nil --[[@type Runner | nil]], } @@ -107,14 +132,11 @@ local Modes = { 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 -- ...that might lose some of the magic of both. Compromise available? idk -local ballFloatAnimator = gfx.animator.new(2000, -60, 0, easingHill) +local ballFloatAnimator = gfx.animator.new(2000, -60, 0, easingHill) local BallSizeMs = 2000 -local ballSizeAnimator = gfx.animator.new(BallSizeMs, 9, 6, easingHill) +local ballSizeAnimator = gfx.animator.new(BallSizeMs, 9, SmallestBallRadius, easingHill) local HitMult = 20 @@ -220,7 +242,7 @@ function throwBall(destX, destY, easingFunc, flyTimeMs, floaty, customBallScaler ballSizeAnimator = customBallScaler else -- TODO? Scale based on distance? - ballSizeAnimator = gfx.animator.new(flyTimeMs, 9, 6, easingHill) + ballSizeAnimator = gfx.animator.new(flyTimeMs, 9, SmallestBallRadius, easingHill) end ballAnimatorY = gfx.animator.new(flyTimeMs, ball.y, destY, easingFunc) ballAnimatorX = gfx.animator.new(flyTimeMs, ball.x, destX, easingFunc) @@ -238,8 +260,16 @@ local catcherThrownBall = false function pitch() catcherThrownBall = false 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() ballAnimatorY:reset() @@ -515,6 +545,10 @@ function init() playdate.timer.new(2000, function() throwBall(PitchStartX, PitchStartY, playdate.easingFunctions.linear, nil, false) end) + BootTune:play() + BootTune:setFinishCallback(function() + TinnyBackground:play() + end) end function tryToThrowOut(self) @@ -536,7 +570,7 @@ local batAngleDeg function updateBatting() if ball.y < BallOffscreen then ball.y = ballAnimatorY:currentValue() + ballFloatAnimator:currentValue() - ball.size = 6 + ball.size = SmallestBallRadius -- ballFloatAnimator:currentValue() end batAngleDeg = (playdate.getCrankPosition() + CrankOffsetDeg) % 360 @@ -571,7 +605,7 @@ function updateBatting() playdate.easingFunctions.outQuint, 2000, 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] diff --git a/src/sounds/boot-tune-organy.wav b/src/sounds/boot-tune-organy.wav new file mode 100644 index 0000000..3929754 Binary files /dev/null and b/src/sounds/boot-tune-organy.wav differ diff --git a/src/sounds/boot-tune.wav b/src/sounds/boot-tune.wav new file mode 100644 index 0000000..4c066e1 Binary files /dev/null and b/src/sounds/boot-tune.wav differ diff --git a/src/sounds/tinny-background.wav b/src/sounds/tinny-background.wav new file mode 100644 index 0000000..8ff5238 Binary files /dev/null and b/src/sounds/tinny-background.wav differ