Basic example with black square cursor on orange background

This commit is contained in:
Felix Uhl 2025-06-12 12:04:08 +02:00
parent 8c7ab7da10
commit 7f37985996
2 changed files with 55 additions and 0 deletions

50
exercise1/exercise1.lua Normal file
View file

@ -0,0 +1,50 @@
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
local cursor = color_surface(8, 8, 0, 0, 0)
function exercise1()
print("Hello World!")
warning("Hello Warning!")
img = fill_surface(VRESW, VRESH, 0xff, 0x77, 0x00)
cursor_setstorage(WORLDID)
show_image(img)
show_image(cursor)
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(cursor, x, y, TICK_DELAY)
warning("" .. x .. ", " .. y)
end

5
run.sh Executable file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env bash
(
cd ../arcan/build || exit
./arcan -T ../data/scripts -p ../../arcan-exercises/data ../../arcan-exercises/exercise1
)