Fix Lua game float-to-int conversion errors for renderer.circle()
All games had the same issue: renderer.circle() requires integer arguments, but float calculations produced non-integer coordinates. Fixed in all games using math.floor(x + 0.5) for proper rounding: - pong.lua: Ball position - air_hockey.lua: Puck position - asteroids.lua: Asteroid positions - ball.lua: Ball and trail positions, velocity line - breakout.lua: Ball position - flappy_bird.lua: Bird Y position - counter.lua: Last touch marker position - snake.lua: Food position (center calculation) - tic_tac_toe.lua: O circle center position Also fixed floating-point coordinate calculations in ball and line drawing to ensure all coordinates are integers.
This commit is contained in:
@@ -58,14 +58,14 @@ end
|
||||
function draw()
|
||||
renderer.clear(false)
|
||||
|
||||
-- Draw ball
|
||||
renderer.circle(game.vars.ball_x, game.vars.ball_y, game.vars.radius, true, true)
|
||||
-- Draw ball (convert to integers)
|
||||
renderer.circle(math.floor(game.vars.ball_x + 0.5), math.floor(game.vars.ball_y + 0.5), game.vars.radius, true, true)
|
||||
|
||||
-- Draw trail (previous positions)
|
||||
local trail_radius = game.vars.radius - 2
|
||||
if trail_radius > 2 then
|
||||
renderer.circle(game.vars.ball_x - game.vars.vel_x,
|
||||
game.vars.ball_y - game.vars.vel_y,
|
||||
renderer.circle(math.floor(game.vars.ball_x - game.vars.vel_x + 0.5),
|
||||
math.floor(game.vars.ball_y - game.vars.vel_y + 0.5),
|
||||
trail_radius, true, false)
|
||||
end
|
||||
|
||||
@@ -80,5 +80,5 @@ function draw()
|
||||
-- Draw velocity vector
|
||||
local arrow_x = game.vars.ball_x + game.vars.vel_x * 3
|
||||
local arrow_y = game.vars.ball_y + game.vars.vel_y * 3
|
||||
renderer.line(game.vars.ball_x, game.vars.ball_y, arrow_x, arrow_y, true, 2)
|
||||
renderer.line(math.floor(game.vars.ball_x + 0.5), math.floor(game.vars.ball_y + 0.5), math.floor(arrow_x + 0.5), math.floor(arrow_y + 0.5), true, 2)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user