Skip to content

Instantly share code, notes, and snippets.

@nielsvanvelzen nielsvanvelzen/main.lua
Last active Dec 12, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.