2018-11-13 20:02:55 +00:00
|
|
|
local scr_x, scr_y = term.getSize()
|
|
|
|
|
|
|
|
local grid = {
|
2018-11-13 20:39:29 +00:00
|
|
|
x1 = -80,
|
|
|
|
y1 = -80,
|
|
|
|
x2 = 80,
|
|
|
|
y2 = 80,
|
2018-11-13 20:06:05 +00:00
|
|
|
border = "#",
|
2018-11-13 20:02:55 +00:00
|
|
|
voidcol = "f",
|
|
|
|
forecol = "8",
|
|
|
|
backcol = "7",
|
|
|
|
edgecol = "0"
|
|
|
|
}
|
|
|
|
|
|
|
|
local scrollX = 0
|
|
|
|
local scrollY = 0
|
|
|
|
|
|
|
|
local player = {
|
|
|
|
x = 0,
|
|
|
|
y = 0,
|
|
|
|
color = colors.blue
|
|
|
|
}
|
|
|
|
|
2018-11-13 20:17:08 +00:00
|
|
|
local gridFore = {
|
|
|
|
"+-------",
|
|
|
|
"| ",
|
|
|
|
"| ",
|
|
|
|
"| ",
|
|
|
|
"| "
|
2018-11-13 20:39:29 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
local gridBack = {
|
|
|
|
"+------------",
|
|
|
|
"| ",
|
|
|
|
"| ",
|
|
|
|
"| ",
|
|
|
|
"| ",
|
|
|
|
"| ",
|
|
|
|
"| ",
|
|
|
|
"| "
|
2018-11-13 20:17:08 +00:00
|
|
|
}
|
2018-11-13 20:18:54 +00:00
|
|
|
for y = 1, #gridFore do
|
2018-11-13 20:17:08 +00:00
|
|
|
gridFore[y] = gridFore[y]:gsub("#","\127")
|
2018-11-13 20:17:32 +00:00
|
|
|
end
|
2018-11-13 20:17:08 +00:00
|
|
|
|
2018-11-13 20:02:55 +00:00
|
|
|
--draws grid and background at scroll 'x' and 'y'
|
|
|
|
local drawGrid = function(x, y)
|
2018-11-13 20:11:07 +00:00
|
|
|
x, y = math.floor(x + 0.5), math.floor(y + 0.5)
|
2018-11-13 20:02:55 +00:00
|
|
|
local bg = {{},{},{}}
|
|
|
|
local foreX, foreY
|
|
|
|
local backX, backY
|
|
|
|
local adjX, adjY
|
|
|
|
for sy = 1, scr_y do
|
|
|
|
bg[1][sy] = ""
|
|
|
|
bg[2][sy] = ""
|
|
|
|
bg[3][sy] = ""
|
|
|
|
for sx = 1, scr_x do
|
|
|
|
adjX = (sx - x)
|
|
|
|
adjY = (sy - y)
|
|
|
|
foreX = 1 + (sx - x) % #gridFore[1]
|
|
|
|
foreY = 1 + (sy - y) % #gridFore
|
2018-11-13 20:39:29 +00:00
|
|
|
backX = 1 + math.floor(sx - (x / 3)) % #gridBack[1]
|
|
|
|
backY = 1 + math.floor(sy - (y / 3)) % #gridBack
|
|
|
|
if adjX < grid.x1 or adjX > grid.x2 or adjY < grid.y1 or adjY > grid.y2 then
|
|
|
|
bg[1][sy] = bg[1][sy] .. " "
|
|
|
|
bg[2][sy] = bg[2][sy] .. grid.voidcol
|
|
|
|
bg[3][sy] = bg[3][sy] .. grid.voidcol
|
|
|
|
elseif adjX == grid.x1 or adjX == grid.x2 or adjY == grid.y1 or adjY == grid.y2 then
|
2018-11-13 20:02:55 +00:00
|
|
|
bg[1][sy] = bg[1][sy] .. grid.border
|
|
|
|
bg[2][sy] = bg[2][sy] .. grid.voidcol
|
|
|
|
bg[3][sy] = bg[3][sy] .. grid.edgecol
|
|
|
|
else
|
|
|
|
if gridFore[foreY]:sub(foreX,foreX) ~= " " then
|
|
|
|
bg[1][sy] = bg[1][sy] .. gridFore[foreY]:sub(foreX,foreX)
|
|
|
|
bg[2][sy] = bg[2][sy] .. grid.forecol
|
|
|
|
bg[3][sy] = bg[3][sy] .. grid.voidcol
|
2018-11-13 20:06:05 +00:00
|
|
|
elseif gridBack[backY]:sub(backX,backX) ~= " " then
|
|
|
|
bg[1][sy] = bg[1][sy] .. gridBack[backY]:sub(backX,backX)
|
2018-11-13 20:02:55 +00:00
|
|
|
bg[2][sy] = bg[2][sy] .. grid.backcol
|
|
|
|
bg[3][sy] = bg[3][sy] .. grid.voidcol
|
|
|
|
else
|
|
|
|
bg[1][sy] = bg[1][sy] .. " "
|
|
|
|
bg[2][sy] = bg[2][sy] .. grid.voidcol
|
|
|
|
bg[3][sy] = bg[3][sy] .. grid.voidcol
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for sy = 1, scr_y do
|
|
|
|
term.setCursorPos(1,sy)
|
|
|
|
term.blit(bg[1][sy], bg[2][sy], bg[3][sy])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- test background drawing
|
|
|
|
|
2018-11-13 20:39:29 +00:00
|
|
|
local evt
|
|
|
|
local keysDown = {}
|
|
|
|
local getInput = function()
|
|
|
|
while true do
|
|
|
|
evt = {os.pullEvent()}
|
|
|
|
if evt[1] == "key" then
|
|
|
|
keysDown[evt[2]] = true
|
|
|
|
elseif evt[1] == "key_up" then
|
|
|
|
keysDown[evt[2]] = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local gridDemo = function()
|
|
|
|
while true do
|
|
|
|
if keysDown[keys.left] then
|
|
|
|
scrollX = scrollX + 1
|
|
|
|
end
|
|
|
|
if keysDown[keys.right] then
|
|
|
|
scrollX = scrollX - 1
|
|
|
|
end
|
|
|
|
if keysDown[keys.up] then
|
|
|
|
scrollY = scrollY + 1
|
|
|
|
end
|
|
|
|
if keysDown[keys.down] then
|
|
|
|
scrollY = scrollY - 1
|
|
|
|
end
|
|
|
|
drawGrid(scrollX, scrollY)
|
|
|
|
sleep(0.05)
|
|
|
|
end
|
2018-11-13 20:02:55 +00:00
|
|
|
end
|
2018-11-13 20:39:29 +00:00
|
|
|
parallel.waitForAny(getInput, gridDemo)
|