This part has overlapping!
Als rewritten:
Code: Select all
local function setBlockOutline (block)
local d = 1/20
local m = {} -- map of outlines
local tiles = block.tiles -- list of tiles as {x1,y1, x2,y2, x3,y3 ...}
for i = 1, #tiles, 2 do
local x, y = tiles[i], tiles[i+1]
if not m[y] then
m[y] = {}
end
if not m[y][x] then
m[y][x] = true
end
end
local lines = {}
for y, xs in pairs (m) do
for x, tabl in pairs (xs) do
local h1 = m[y-1] and m[y-1][x]
local v1 = m[y] and m[y][x-1]
local h2 = m[y+1] and m[y+1][x]
local v2 = m[y] and m[y][x+1]
if not h1 then
table.insert (lines, {x+d,y+d, x+1-d, y+d})
end
if not h2 then
table.insert (lines, {x+d,y+1-d, x+1-d, y+1-d})
end
if not v1 then
table.insert (lines, {x+d,y+d, x+d, y+1-d})
end
if not v2 then
table.insert (lines, {x+1-d,y+d, x+1-d, y+1-d})
end
end
end
block.lines = lines
end