Correct draw offset for hits to right field.

This commit is contained in:
Sage Vaillancourt 2025-02-03 20:45:18 -05:00
parent 6dd8469409
commit 6308871692
1 changed files with 9 additions and 13 deletions

View File

@ -1,5 +1,3 @@
local ballBuffer <const> = 5
--- Assumes that background image is of size --- Assumes that background image is of size
--- XXX --- XXX
--- XOX --- XOX
@ -9,19 +7,17 @@ function getDrawOffset(screenW, screenH, ballX, ballY)
if ballY > screenH then if ballY > screenH then
return 0, 0 return 0, 0
end end
if ballY < ballBuffer then offsetY = math.max(0, -1 * ballY)
offsetY = math.max(ballBuffer, -1 * (ballY - ballBuffer))
else if ballX > 0 and ballX < screenW then
offsetY = 0
end
if ballX > 0 and ballX < (screenW - ballBuffer) then
offsetX = 0 offsetX = 0
elseif ballX < ballBuffer then elseif ballX < 0 then
offsetX = math.max(-1 * screenW, -1 * (ballX - ballBuffer)) offsetX = math.max(-1 * screenW, ballX * -1)
elseif ballX > (screenW - ballBuffer) then elseif ballX > screenW then
offsetX = math.min(screenW * 2, -1 * (ballX - ballBuffer)) offsetX = math.min(screenW * 2, (ballX * -1) + screenW)
end end
return offsetX, offsetY
return offsetX * 1.3, offsetY * 1.5
end end
-- selene: allow(unscoped_variables) -- selene: allow(unscoped_variables)