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:
@@ -105,8 +105,8 @@ function draw()
|
||||
renderer.rect(5, game.vars.paddle_left_y, PADDLE_WIDTH, PADDLE_HEIGHT, true, true)
|
||||
renderer.rect(game.width() - 5 - PADDLE_WIDTH, game.vars.paddle_right_y, PADDLE_WIDTH, PADDLE_HEIGHT, true, true)
|
||||
|
||||
-- Draw puck
|
||||
renderer.circle(game.vars.puck_x, game.vars.puck_y, PUCK_RADIUS, true, true)
|
||||
-- Draw puck (convert to integers)
|
||||
renderer.circle(math.floor(game.vars.puck_x + 0.5), math.floor(game.vars.puck_y + 0.5), PUCK_RADIUS, true, true)
|
||||
|
||||
-- Draw scores
|
||||
renderer.text(game.width() / 2 - 30, 5, tostring(game.vars.paddle_left_score), true)
|
||||
|
||||
Reference in New Issue
Block a user