tw,th = term.getSize()
database = {}
for fx=1,tw,1 do
table.insert(database,fx,{})
for fy=2,th,1 do
table.insert(database[fx],fy,0)
end
end
function block(x,y,id)
table.insert(database[x],y,id)
if id == 0 then
-- Air
term.setBackgroundColor(colors.black)
term.setCursorPos(x,y)
write(database[x][y])
elseif id == 1 then
-- Stone
term.setBackgroundColor(colors.gray)
term.setCursorPos(x,y)
write(database[x][y])
elseif id == 2 then
-- Dirt
term.setBackgroundColor(colors.brown)
term.setCursorPos(x,y)
write(database[x][y])
elseif id == 3 then
-- Grass
term.setBackgroundColor(colors.green)
term.setCursorPos(x,y)
write(database[x][y])
end
end
function getBlockID(x,y)
return database[x][y]
end
-- Initialize
term.clear()
-- Generation
genheight = th / 2
for gencolumn=1,tw,1 do
genheight = genheight + (math.random(1,3) - 2)
for genblock=tw,genheight,-1 do
block(gencolumn,genblock,1)
block(gencolumn,genblock - 1,2)
block(gencolumn,genblock - 2,2)
block(gencolumn,genblock - 3,2)
block(gencolumn,genblock - 4,3)
end
end
-- Player
while true do
event, button, x, y = os.pullEvent("mouse_click")
term.setCursorPos(x,y)
term.setTextColor(colors.red)
term.setBackgroundColor(colors.lightBlue)
write(getBlockID(x,y))
end