Move fielder-draw iteration and dance to fielding.lua
Move PlayerImageBlipper to graphics.lua
This commit is contained in:
parent
f67d6262ac
commit
fbbfc3c2e7
|
@ -16,6 +16,7 @@
|
|||
return assetCode
|
||||
end
|
||||
function generatedFileWarning()
|
||||
-- Only in a function to make clear that THIS .lua2p is not the generated file!
|
||||
return "-- GENERATED FILE - DO NOT EDIT\n-- Instead, edit the source file directly: assets.lua2p."
|
||||
end)!!(generatedFileWarning())
|
||||
|
||||
|
|
|
@ -85,6 +85,7 @@ C.BallCatchHitbox = 3
|
|||
C.BaseHitbox = 10
|
||||
|
||||
C.BattingPower = 20
|
||||
C.BatterHandPos = utils.xy(25, 15)
|
||||
|
||||
C.SmallestBallRadius = 6
|
||||
|
||||
|
|
|
@ -20,6 +20,9 @@ local function drawFielderGlove(ball, fielderX, fielderY)
|
|||
end
|
||||
end
|
||||
|
||||
---@param ball Point3d
|
||||
---@param x number
|
||||
---@param y number
|
||||
---@return boolean isHoldingBall
|
||||
function drawFielder(ball, x, y)
|
||||
gfx.fillRect(x, y, 14, 25)
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
---@field fielderTouchingBall Fielder | nil
|
||||
Fielding = {}
|
||||
|
||||
local FielderDanceAnimator <const> = playdate.graphics.animator.new(1, 10, 0, utils.easingHill)
|
||||
FielderDanceAnimator.repeatCount = C.DanceBounceCount - 1
|
||||
|
||||
---@param name string
|
||||
---@param speed number
|
||||
---@return Fielder
|
||||
|
@ -148,3 +151,17 @@ function Fielding:userThrowTo(targetBase, launchBall, throwFlyMs)
|
|||
return userThrowToImpl(self, targetBase, launchBall, throwFlyMs)
|
||||
end)
|
||||
end
|
||||
|
||||
function Fielding:celebrate()
|
||||
FielderDanceAnimator:reset(C.DanceBounceMs)
|
||||
end
|
||||
|
||||
---@param ball Point3d
|
||||
---@return boolean ballIsHeldByAFielder
|
||||
function Fielding:drawFielders(ball)
|
||||
local ballIsHeld = false
|
||||
for _, fielder in pairs(self.fielders) do
|
||||
ballIsHeld = drawFielder(ball, fielder.x, fielder.y + FielderDanceAnimator:currentValue()) or ballIsHeld
|
||||
end
|
||||
return ballIsHeld
|
||||
end
|
||||
|
|
|
@ -38,3 +38,6 @@ function blipper.new(msInterval, image1, image2)
|
|||
end,
|
||||
}
|
||||
end
|
||||
|
||||
--selene: allow(unscoped_variables)
|
||||
PlayerImageBlipper = blipper.new(100, Player, PlayerLowHat)
|
||||
|
|
23
src/main.lua
23
src/main.lua
|
@ -23,6 +23,8 @@ import 'CoreLibs/ui.lua'
|
|||
import 'utils.lua'
|
||||
import 'constants.lua'
|
||||
import 'assets.lua'
|
||||
import 'draw/overlay.lua'
|
||||
import 'draw/fielder.lua'
|
||||
|
||||
import 'action-queue.lua'
|
||||
import 'announcer.lua'
|
||||
|
@ -32,8 +34,6 @@ import 'dbg.lua'
|
|||
import 'fielding.lua'
|
||||
import 'graphics.lua'
|
||||
import 'npc.lua'
|
||||
import 'draw/overlay.lua'
|
||||
import 'draw/fielder.lua'
|
||||
-- stylua: ignore end
|
||||
|
||||
-- selene: allow(shadowing)
|
||||
|
@ -73,18 +73,11 @@ local secondsSincePitchAllowed = -5
|
|||
|
||||
local catcherThrownBall = false
|
||||
|
||||
local BatterHandPos <const> = utils.xy(25, 15)
|
||||
|
||||
local batBase <const> = utils.xy(C.Center.x - 34, 215)
|
||||
local batTip <const> = utils.xy(0, 0)
|
||||
|
||||
local batAngleDeg = C.CrankOffsetDeg
|
||||
|
||||
local PlayerImageBlipper <const> = blipper.new(100, Player, PlayerLowHat)
|
||||
|
||||
local FielderDanceAnimator <const> = gfx.animator.new(1, 10, 0, utils.easingHill)
|
||||
FielderDanceAnimator.repeatCount = C.DanceBounceCount - 1
|
||||
|
||||
---@alias Pitch { x: SimpleAnimator, y: SimpleAnimator, z: SimpleAnimator | nil }
|
||||
|
||||
---@type Pitch[]
|
||||
|
@ -171,7 +164,7 @@ local function nextHalfInning()
|
|||
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
|
||||
FielderDanceAnimator:reset(C.DanceBounceMs)
|
||||
fielding:celebrate()
|
||||
secondsSinceLastRunnerMove = -7
|
||||
fielding:benchTo(currentlyFieldingTeam.benchPosition)
|
||||
announcer:say("SWITCHING SIDES...")
|
||||
|
@ -259,8 +252,8 @@ end
|
|||
local function updateBatting(batDeg, batSpeed)
|
||||
local batAngle = math.rad(batDeg)
|
||||
-- TODO: animate bat-flip or something
|
||||
batBase.x = baserunning.batter and (baserunning.batter.x + BatterHandPos.x) or 0
|
||||
batBase.y = baserunning.batter and (baserunning.batter.y + BatterHandPos.y) or 0
|
||||
batBase.x = baserunning.batter and (baserunning.batter.x + C.BatterHandPos.x) or 0
|
||||
batBase.y = baserunning.batter and (baserunning.batter.y + C.BatterHandPos.y) or 0
|
||||
batTip.x = batBase.x + (C.BatLength * math.sin(batAngle))
|
||||
batTip.y = batBase.y + (C.BatLength * math.cos(batAngle))
|
||||
|
||||
|
@ -458,11 +451,7 @@ function playdate.update()
|
|||
|
||||
GrassBackground:draw(-400, -240)
|
||||
|
||||
local fielderDanceHeight = FielderDanceAnimator:currentValue()
|
||||
local ballIsHeld = false
|
||||
for _, fielder in pairs(fielding.fielders) do
|
||||
ballIsHeld = drawFielder(ball, fielder.x, fielder.y + fielderDanceHeight) or ballIsHeld
|
||||
end
|
||||
local ballIsHeld = fielding:drawFielders(ball)
|
||||
|
||||
if offenseState == C.Offense.batting then
|
||||
gfx.setLineWidth(5)
|
||||
|
|
Loading…
Reference in New Issue