From 2d6f83a23fe6a5cf4b3fbceb2616ba58aa628c09 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Thu, 20 Feb 2025 00:28:14 -0500 Subject: [PATCH] Add some slight linger time to draw/throwMeter --- src/draw/throw-meter.lua | 16 ++++++++++++++-- src/pitching.lua | 4 ++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/draw/throw-meter.lua b/src/draw/throw-meter.lua index 7f9da4b..13ae750 100644 --- a/src/draw/throw-meter.lua +++ b/src/draw/throw-meter.lua @@ -2,6 +2,7 @@ local gfx = playdate.graphics local ThrowMeterHeight = 50 +local ThrowMeterLingerSec = 1.5 ---@param x number ---@param y number @@ -10,6 +11,7 @@ function throwMeter:draw(x, y) gfx.drawRect(x, y, 14, ThrowMeterHeight) if self.lastReadThrow then -- TODO: If ratio is "perfect", show some additional effect + -- TODO: If meter has moved to a new fielder, empty it. local ratio = (self.lastReadThrow - throwMeter.MinCharge) / (self.idealPower - throwMeter.MinCharge) local height = ThrowMeterHeight * ratio gfx.fillRect(x + 2, y + ThrowMeterHeight - height, 10, height) @@ -19,8 +21,18 @@ function throwMeter:draw(x, y) end function throwMeter:drawNearFielder(fielder) - if not fielder then + if not fielder and not self.lastThrower then return end - throwMeter:draw(fielder.x - 25, fielder.y - 10) + if fielder then + self.lastThrower = fielder + actionQueue:upsert("throwMeterLinger", 200 + ThrowMeterLingerSec * 1000, function() + local dt = 0 + while dt < ThrowMeterLingerSec do + dt = dt + coroutine.yield() + end + self.lastThrower = nil + end) + end + self:draw(self.lastThrower.x - 25, self.lastThrower.y - 10) end diff --git a/src/pitching.lua b/src/pitching.lua index d45f600..829035c 100644 --- a/src/pitching.lua +++ b/src/pitching.lua @@ -119,6 +119,10 @@ throwMeter = { value = 0, idealPower = 50, lastReadThrow = nil, + + --- Used at draw-time only. + ---@type Fielder | nil + lastThrower = nil, } function throwMeter:reset()