Skip to content

Instantly share code, notes, and snippets.

@nielsvanvelzen
Last active December 12, 2015 18:36
Show Gist options
  • Save nielsvanvelzen/74d1413e4d2c143a260a to your computer and use it in GitHub Desktop.
Save nielsvanvelzen/74d1413e4d2c143a260a to your computer and use it in GitHub Desktop.
LUA script for game engine.
local width = 1600
local height = 900
window.create(width, height, "LuaGame") -- width, height, title
canvas.init();
local ticks = 0
local x = 0
local y = 0
local xBackwards = false
local yBackwards = false
while not window.shouldClose() do
ticks = ticks + 1
local size = 100 * math.sin(ticks / window.getFramesPerSecond()) + 200
if xBackwards then
x = x - 1
else
x = x + 1
end
if yBackwards then
y = y - 1
else
y = y + 1
end
if x < 0 then
x = 0
xBackwards = false
elseif x > width - size * 2 then
x = width - size * 2
xBackwards = true
end
if y < 0 then
y = 0
yBackwards = false
elseif y > height - size then
y = height - size
yBackwards = true
end
canvas.reset()
canvas.beginFrame(width, height, 1.0)
canvas.beginPath()
canvas.rect(x, y, size * 2, size) -- x, y, width, height
canvas.fillColor(1.0, 0.0, 0.0, 1.0) -- red, green, blue, alpha floats
canvas.fill()
canvas.endFrame();
window.update()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment