1
0
mirror of https://github.com/LDDestroier/CC/ synced 2024-12-14 20:20:29 +00:00

Added user control

This commit is contained in:
LDDestroier 2018-11-13 15:39:29 -05:00 committed by GitHub
parent 8522360d6d
commit df572af20a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

71
tron
View File

@ -1,10 +1,10 @@
local scr_x, scr_y = term.getSize() local scr_x, scr_y = term.getSize()
local grid = { local grid = {
x1 = -60, x1 = -80,
y1 = -60, y1 = -80,
x2 = 60, x2 = 80,
y2 = 60, y2 = 80,
border = "#", border = "#",
voidcol = "f", voidcol = "f",
forecol = "8", forecol = "8",
@ -22,18 +22,18 @@ local player = {
} }
local gridFore = { local gridFore = {
" ", "+-------",
" ", "| ",
" ##### #####", "| ",
" ##### #####", "| ",
" ##### #####", "| "
" ",
" ##### #####",
" ##### #####",
" ##### #####",
} }
local gridBack = { local gridBack = {
"+-------", "+------------",
"| ",
"| ",
"| ",
"| ", "| ",
"| ", "| ",
"| ", "| ",
@ -59,9 +59,13 @@ local drawGrid = function(x, y)
adjY = (sy - y) adjY = (sy - y)
foreX = 1 + (sx - x) % #gridFore[1] foreX = 1 + (sx - x) % #gridFore[1]
foreY = 1 + (sy - y) % #gridFore foreY = 1 + (sy - y) % #gridFore
backX = 1 + math.floor(sx - (x / 2)) % #gridBack[1] backX = 1 + math.floor(sx - (x / 3)) % #gridBack[1]
backY = 1 + math.floor(sy - (y / 2)) % #gridBack 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 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[1][sy] = bg[1][sy] .. grid.border
bg[2][sy] = bg[2][sy] .. grid.voidcol bg[2][sy] = bg[2][sy] .. grid.voidcol
bg[3][sy] = bg[3][sy] .. grid.edgecol bg[3][sy] = bg[3][sy] .. grid.edgecol
@ -90,9 +94,34 @@ end
-- test background drawing -- test background drawing
local y = 0 local evt
for x = grid.x1-10, grid.x2+10 do local keysDown = {}
y = math.sin(math.rad(x * 10)) * 30 local getInput = function()
drawGrid(x, y) 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) sleep(0.05)
end end
end
parallel.waitForAny(getInput, gridDemo)