~ xriss
2017-01-20
Basic fun!
A cut down and basic fun example, we do not make many assumptions so
you are free to configure and setup your code to your own tastes.
There are only two parts that you must provide for fun to work. The
first is a table describing the virtual hardware component setup, eg
the resolution of screen and tilemaps and sprite layers to display.
hardware={
{
component="screen",
size={424,240}, -- lowrez with a 1920x1080 aspect
scale=3, -- draw in a window at 3 times scale
fps=60, -- 60 fps please
},
...
}
This requests the virtual hardware that will be setup before main is
called. system is a global table that will be created according to your
requested hardware and can then be referenced when the main function is
called.
The second is a main function which will be called as a yield-able
co-routine with a table that should be treated as an incoming message.
Use the basic skeleton below to receive need.setup/update/draw
requests. As you can see it is possible to have multiple needs at once
and this call structure allows for a setup, repeat update/draw then cleanup
flow of code within this co-routine.
function main(need)
if not need.setup then need=coroutine.yield() end -- wait for setup request
-- perform setup
local done=false while not done do
need=coroutine.yield()
if need.update then
-- perform update
end
if need.draw then
-- perform draw
end
if need.clean then done=true end -- cleanup requested
end
-- perform cleanup
end