62 lines
No EOL
1.4 KiB
Lua
62 lines
No EOL
1.4 KiB
Lua
function dump(o)
|
|
if type(o) == 'table' then
|
|
local s = '{ '
|
|
for k,v in pairs(o) do
|
|
if type(k) ~= 'number' then k = '"'..k..'"' end
|
|
s = s .. '['..k..'] = ' .. dump(v) .. ','
|
|
end
|
|
return s .. '} '
|
|
else
|
|
return tostring(o)
|
|
end
|
|
end
|
|
|
|
TICK_DELAY = 1 / 25
|
|
|
|
shapes = { }
|
|
function init_shapes()
|
|
if shapes.img ~= nil then hide_image(shapes.img) end
|
|
if shapes.cursor ~= nil then hide_image(shapes.cursor) end
|
|
|
|
shapes.cursor = color_surface(8, 8, 0, 0, 0)
|
|
shapes.img = fill_surface(VRESW, VRESH, 0xff, 0x77, 0x00)
|
|
|
|
show_image(shapes.img)
|
|
show_image(shapes.cursor)
|
|
end
|
|
|
|
function exercise1()
|
|
print("Hello World!")
|
|
warning("Hello Warning!")
|
|
|
|
init_shapes()
|
|
|
|
cursor_setstorage(WORLDID)
|
|
end
|
|
|
|
|
|
function exercise1_input(evtbl)
|
|
if evtbl.source ~= "mouse" then return end
|
|
if evtbl.samples == nil then return end
|
|
x, y = cursor_position()
|
|
sample = evtbl.samples[1]
|
|
if evtbl.subid == 0 then
|
|
move_cursor(sample, y)
|
|
elseif evtbl.subid == 1 then
|
|
move_cursor(x, sample)
|
|
else
|
|
warning("Unknown subid " .. evtbl.subid)
|
|
end
|
|
|
|
end
|
|
|
|
function exercise1_input_end()
|
|
x, y = cursor_position()
|
|
move_image(shapes.cursor, x, y, TICK_DELAY)
|
|
warning("Mouse: " .. x .. ", " .. y)
|
|
end
|
|
|
|
function exercise1_display_state(action, id, state)
|
|
warning("Res: " .. VRESW .. ", " .. VRESH)
|
|
init_shapes()
|
|
end |