From 7f37985996e172e276193f63913342cdae65907d Mon Sep 17 00:00:00 2001 From: Felix Uhl Date: Thu, 12 Jun 2025 12:04:08 +0200 Subject: [PATCH] Basic example with black square cursor on orange background --- exercise1/exercise1.lua | 50 +++++++++++++++++++++++++++++++++++++++++ run.sh | 5 +++++ 2 files changed, 55 insertions(+) create mode 100644 exercise1/exercise1.lua create mode 100755 run.sh diff --git a/exercise1/exercise1.lua b/exercise1/exercise1.lua new file mode 100644 index 0000000..400aa7a --- /dev/null +++ b/exercise1/exercise1.lua @@ -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 \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..fdfc290 --- /dev/null +++ b/run.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +( + cd ../arcan/build || exit + ./arcan -T ../data/scripts -p ../../arcan-exercises/data ../../arcan-exercises/exercise1 +) \ No newline at end of file