Show Lua Errors on-screen, example.lua shows many squares

This commit is contained in:
RadsammyT 2026-05-21 20:21:19 -04:00
commit 4d33aa54b9
No known key found for this signature in database
3 changed files with 107 additions and 15 deletions

View file

@ -14,36 +14,51 @@
-- must be in the unsigned 32-bit integer range: 0 to 2^32-1.
-- clear() -- Clear the buffer.
-- }
--
-- A function named `draw()` must be declared in the script. This is ran every frame.
--
-- ]]
local SQUARE_WIDTH = 10
local SQUARE_HEIGHT = 5
local SQUARE_X = 0
local SQUARE_Y = 0
local SQUARE_COUNT = 25
local squares = {}
local SQUARE_VX = 1
local SQUARE_VY = 1
for i = 0, SQUARE_COUNT-1 do
local vx = 1
local vy = 1
if math.random(1, 2) == 2 then vx = -vx end
if math.random(1, 2) == 2 then vy = -vy end
squares[#squares+1] = {
x = math.random(1, ly.width - SQUARE_WIDTH),
y = math.random(1, ly.height - SQUARE_HEIGHT),
vx = vx,
vy = vy,
color = math.random(0xFFFFFF)
}
end
local timer = os.clock()
local color = math.random(0xFFFFFF)
function draw()
-- Rather than progressing the animation by frame, do it based on
-- seconds, like from os.clock().
if timer + 0.025 < os.clock() then
ly.clear()
SQUARE_X = SQUARE_X + SQUARE_VX
SQUARE_Y = SQUARE_Y + SQUARE_VY
for x = SQUARE_X, SQUARE_X + SQUARE_WIDTH do
for y = SQUARE_Y, SQUARE_Y + SQUARE_HEIGHT do
ly.putCell(string.byte(' '), 0, color, x, y)
for i, v in ipairs(squares) do
v.x = v.x + v.vx
v.y = v.y + v.vy
for x = v.x, v.x + SQUARE_WIDTH do
for y = v.y, v.y + SQUARE_HEIGHT do
ly.putCell(string.byte(' '), 0, v.color, x, y)
end
end
if v.x <= 0 then v.vx = 1; v.color = math.random(0xFFFFFF) end
if v.x + SQUARE_WIDTH >= ly.width-1 then v.vx = -1; v.color = math.random(0xFFFFFF) end
if v.y <= 0 then v.vy = 1; v.color = math.random(0xFFFFFF) end
if v.y + SQUARE_HEIGHT >= ly.height-1 then v.vy = -1; v.color = math.random(0xFFFFFF) end
end
if SQUARE_X <= 0 then SQUARE_VX = 1; color = math.random(0xFFFFFF) end
if SQUARE_X + SQUARE_WIDTH >= ly.width-1 then SQUARE_VX = -1; color = math.random(0xFFFFFF) end
if SQUARE_Y <= 0 then SQUARE_VY = 1; color = math.random(0xFFFFFF) end
if SQUARE_Y + SQUARE_HEIGHT >= ly.height-1 then SQUARE_VY = -1; color = math.random(0xFFFFFF) end
timer = os.clock()
end
end