ldd-CC/tron

225 lines
5.2 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local scr_x, scr_y = term.getSize()
local grid = {
x1 = -80,
y1 = -80,
x2 = 80,
y2 = 80,
border = "#",
voidcol = "f",
forecol = "8",
backcol = "7",
edgecol = "0"
}
local scrollX = 0
local scrollY = 0
local player = {
x = 0,
y = 0,
color = colors.blue
}
local control = {
up = keys.up,
down = keys.down,
left = keys.left,
right = keys.right,
lookUp = keys.w,
lookDown = keys.s,
lookLeft = keys.a,
lookRight = keys.d,
release = keys.space
}
-- keeps track of where you are
local gamemode = ""
-- foreground grid
local gridFore = {
"+-------",
"| ",
"| ",
"| ",
"| "
}
-- background grid
local gridBack = {
"+------------",
"| ",
"| ",
"| ",
"| ",
"| ",
"| ",
"| "
}
--draws grid and background at scroll 'x' and 'y'
local drawGrid = function(x, y)
x, y = math.floor(x + 0.5), math.floor(y + 0.5)
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
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
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
elseif gridBack[backY]:sub(backX,backX) ~= " " then
bg[1][sy] = bg[1][sy] .. gridBack[backY]:sub(backX,backX)
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
local deepCopy
deepCopy = function(tbl)
local output = {}
for k,v in pairs(tbl) do
if type(v) == "table" then
output[k] = deepCopy(v)
else
output[k] = v
end
end
return output
end
local makeMenu = function(options, x, y)
local cpos = 1
local cursor = "> "
local render = function()
for i = 1, #options do
term.setCursorPos(x, y + (i - 1))
if i == cpos then
term.setTextColor(colors.white)
term.write(cursor .. options[i])
else
term.setTextColor(colors.gray)
term.write((" "):rep(#cursor) .. options[i])
end
end
end
-- finish please
end
local titleScreen = function()
local logo = {
{
"",
" •ƒƒƒƒƒƒƒƒƒ•—ƒƒƒƒƒƒƒ‹‹ ‡‡ƒƒƒ‹‹ Ÿ‹ •ƒƒ•",
" •ƒƒƒ”€—ƒƒƒ•‚ƒƒƒƒƒ‹€€€Š —€Ÿƒƒƒ€” •‚‚ •€€•",
" •€• ‚‚ƒƒ•€€—€€€”€€••€€‹‹ •€€•",
" •€• —ƒ”‹“ƒƒ‹€€€•€€•€€€•€€••€•ˆƒ€€•",
" •€• •€• ‚‹€€‹€Š€‹‡€Ÿ…•€• ‚‚€•",
" •€• •€• ‹€‚‹ ‹‹€€€Ÿ‡‡ •€• ‹‹•",
"   Š ‚‹‡  ‚…",
},
{
"",
" f7777777777777777777f f77777f 7f f777",
" f99979999979999999999f 799999799 77f7 f997",
" 799 79999f997ffff9977997f f997",
" 799 7797777fffff997ffff9977997797997",
" 799 799 799977f7797fff7997799 79797",
" 799 799 7797f 797999997 799 797",
" 777 777 7777 7777777 777 77",
},
{
"",
" 7999999999f9999999997 7999997 97 799f",
" 7777997777f77777779997 997777997 997f 799f",
" 997 f7777799ffff799f99997 799f",
" 997 997f9997fff799ffff799f997ff7999f",
" 997 997 f7999fff999777997f997 f799f",
" 997 997 f9997 f7999977f 997 f7f",
" fff fff ffff fffffff fff ff",
}
}
local drawLogo = function(x, y, darkmod)
local cx, cy = term.getCursorPos()
for iy = 1, #logo[1] do
term.setCursorPos(x,y+(iy-1))
term.blit(logo[1][iy], logo[2][iy], logo[3][iy])
end
term.setCursorPos(cx,cy)
end
term.clear()
drawLogo(3,2)
end
titleScreen()
-- test background drawing
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
end
parallel.waitForAny(getInput, gridDemo)