I’m trying to make a tile map world using 2D table(table in table) but I want more control of where each tile goes.
How do I turn this (scroll down)
function setup()
map={}
w=5
h=3
for x=1,w do
map[x]={}
for y=1,h do
map[x][y]=0
end
map[1][1]={ asset.builtin.Blocks.Grass_Top,
asset.builtin.Blocks.Stone_Coal_Alt,
asset.builtin.Blocks.Sand,
asset.builtin.Blocks.Stone_Diamond_Alt,
asset.builtin.Blocks.Mushroom_Red,
asset.builtin.Blocks.Wheat_Stage4,
asset.builtin.Blocks.Fence_Stone,
asset.builtin.Blocks.Water }
bTab={}
for x=-20,20 do
for y=-20,20 do
table.insert(bTab,{x=x,y=y})
end
end
dx,dy=WIDTH/2,HEIGHT/2
end
end
function draw()
background(0)
s=130
for a,b in pairs(bTab) do
sprite(map[1][1][1],b.x*s+dx,b.y+dy)
sprite(map[1][1][2],b.x*s+dx,b.y+dy+170)
sprite(map[1][1][3],b.x*s+dx,b.y+dy+340)
end
end
function touched(t)
if t.state==MOVING then
dx=dx+t.deltaX
dy=dy+t.deltaY
end
end
Into something like this. So each number corresponds to a tile. That way I can draw my world and have complete control where each tile goes.
TileTable = {
{ 4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,4 },
{ 4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,4 },
{ 4,1,3,1,1,1,1,1,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,4 },
{ 4,1,1,1,1,1,1,1,2,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,4 },
{ 4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4 },
{ 4,1,1,4,1,1,1,1,1,2,2,1,1,4,1,1,1,4,1,4,2,2,1,1,4 },
{ 4,1,1,4,1,1,1,1,4,3,3,4,1,2,1,1,1,2,1,4,1,1,1,1,4 },
{ 4,1,1,4,1,1,1,1,4,3,3,4,1,1,4,1,4,1,1,4,2,2,1,1,4 },
{ 4,1,1,4,1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