Draw fans in the stands

This commit is contained in:
Sage Vaillancourt 2025-02-20 15:21:20 -05:00
parent 56c0c27d75
commit 384a14fe5f
3 changed files with 38 additions and 0 deletions

36
src/draw/fans.lua Normal file
View File

@ -0,0 +1,36 @@
local gfx <const>, C <const> = playdate.graphics, C
fans = {}
local FanImages <const> = { DarkSkinFan, LightSkinFan }
local FanWidth <const>, FanHeight <const> = FanImages[1]:getSize()
local BgWidth <const>, BgHeight <const> = GrassBackground:getSize()
local AudienceImage1 <const> = gfx.image.new(BgWidth, BgHeight)
local AudienceImage2 <const> = gfx.image.new(BgWidth, BgHeight)
local height = 0
while height < BgHeight do
local width = 0
while width < BgWidth do
gfx.pushContext(AudienceImage1)
local image = FanImages[math.random(#FanImages)]
local jiggle = math.random(5)
image:draw(width + jiggle, height)
gfx.popContext()
gfx.pushContext(AudienceImage2)
image:draw(width + jiggle + math.random(0, 2), height)
gfx.popContext()
width = width + FanWidth
end
height = height + FanHeight - 10
end
local AudienceMovement = gfx.animation.blinker.new(200, 200, true)
AudienceMovement:start()
function fans.draw()
local currentImage = AudienceMovement.on and AudienceImage1 or AudienceImage2
currentImage:draw(-400, -720)
end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 42 KiB

View File

@ -39,6 +39,7 @@ import 'npc.lua'
import 'pitching.lua'
import 'draw/box-score.lua'
import 'draw/fans.lua'
import 'draw/fielder.lua'
import 'draw/overlay.lua'
import 'draw/panner.lua'
@ -592,6 +593,7 @@ function Game:update()
local offsetX, offsetY = self.panner:get(self.state.deltaSeconds)
gfx.setDrawOffset(offsetX, offsetY)
fans.draw()
GrassBackground:draw(-400, -720)
---@type { y: number, drawAction: fun() }[]