add camera logic

This commit is contained in:
Justus Wolff
2026-02-15 11:29:23 +01:00
parent f3800ec226
commit fa6b4fc064

View File

@@ -74,12 +74,14 @@ local function newdesign()
y = 1
}
local currentfloor = 1
local camx,camy = 0,0
while true do
-- render buf
reset()
for x=1,dimensions["x"],1 do
for z=1,dimensions["z"],1 do
for x=1+camx,dimensions["x"]+camx,1 do
for z=1+camy,dimensions["z"]+camy,1 do
local currentbuf = buf[posasstring(x, currentfloor, z)]
if currentbuf then
term.setCursorPos(x, z)
@@ -98,6 +100,8 @@ local function newdesign()
-- user input
local event = table.pack(os.pullEvent())
if event[1] == "mouse_click" or event[1] == "mouse_drag" then
event[3] = event[3]+camx
event[4] = event[4]+camy
if event[3] <= dimensions["x"] and event[4] <= dimensions["z"] then
if event[2] == 1 then -- left button, set
buf[posasstring(event[3], currentfloor, event[4])] = true
@@ -107,7 +111,8 @@ local function newdesign()
end
end
end
if event[1] == "key" and keys.getName(event[2]) == "leftCtrl" then -- menu
if event[1] == "key" then
if keys.getName(event[2]) == "leftCtrl" then -- menu
local action = selopt({
"Save",
"Load",
@@ -170,6 +175,25 @@ local function newdesign()
dimensions["z"] = zsize
end
end
if keys.getName(event[2]) == "q" and currentfloor < dimensions["y"] then -- go up
currentfloor = currentfloor + 1
end
if keys.getName(event[2]) == "e" and currentfloor > 1 then -- go down
currentfloor = currentfloor - 1
end
if keys.getName(event[2]) == "w" and camy > 1 then -- pan up
camy = camy - 1
end
if keys.getName(event[2]) == "s" and camy < dimensions["z"] then -- pan down
camy = camy + 1
end
if keys.getName(event[2]) == "a" and camx > 1 then -- pan left
camx = camx - 1
end
if keys.getName(event[2]) == "d" and camx < dimensions["x"] then -- pan right
camx = camx + 1
end
end
end
end