Not sure if anything this frivolous is normally shared on here but as a relative noob I was so damn happy with this I had to share it with someone!

The game I’m creating has rogue like elements so I wanted a randomly generated map that would provide branches, and therefore choices, in the early part of the game but ultimately funnel you to a single goal. So I created this. Looking forward to incorporating it into my nascent game.

Thanks as usual especially to Ignatz and his tutes for helping me to grasp the power of tables.

```
-- Map Exp
-- Use this function to perform your initial setup
function setup()
displayMode(OVERLAY)
parameter.integer("branchprob",0, 100, 5)
-- parameter.integer("size", 1, 1000, 1)
size = 25
parameter.action("Resetmap", function() tablegen() end )
tablegen()
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
pushStyle()
pushMatrix()
translate(-400, 0)
background(40, 40, 50)
fill(175, 23, 22, 255)
strokeWidth(size/8)
for y=1,35 do
for x=1,61 do
if x>31 then swing = -1
elseif x<31 then swing = 1
else swing = 0
end
if bigmap[x][y] == 1 then
line(size * x, size * y, size * x, size * (y+1))
elseif bigmap[x][y] == 2 then
line(size * x, size * y, size * (x-1), size * (y+1))
line(size * x, size * y, size * (x+1), size * (y+1))
elseif bigmap[x][y] == 3 then
line(size * x, size * y, size * (x+swing), size * (y+1))
end
end
end
strokeWidth(size/10)
for y=1,35 do
for x=1,61 do
if bigmap[x][y] ~= 0 then
ellipse(size * x,size*y, size/2)
end
end
end
popMatrix()
popStyle()
-- This sets the line thickness
-- Do your drawing here
end
function tablegen()
bigmap={}
for i=1,100 do
table.insert(bigmap,{})
end
for y=1,35 do
for x=1,61 do
bigmap[x][y]=0
end
end
bigmap[31][1] = 1
for y=1,15 do
for x=1,61 do
local branchprob = branchprob + x
if bigmap[x][y] == 1 then
if math.random(1,100) <= branchprob then
bigmap[x][y+1] = 2
else
bigmap[x][y+1] = 1
end
elseif bigmap[x][y] == 2 then
if math.random(1,100) <= branchprob then
bigmap[x-1][y+1] = 2
else
bigmap[x-1][y+1] = 1
end
if math.random(1,100) <= branchprob then
bigmap[x+1][y+1] = 2
else
bigmap[x+1][y+1] = 1
end
end
end
for y=16,35 do
for x=1,61 do
local consolprob = (math.abs(x-31) * 3) + (2 *y) + (branchprob*1.5)
if bigmap[x][y] == 1 then
if math.random(1,100) <= consolprob then
bigmap[x][y+1] = 3
elseif math.random(1,100) <= (branchprob/2) then
bigmap[x][y+1] = 2
else
bigmap[x][y+1] = 1
end
elseif bigmap[x][y] == 2 then
if math.random(1,100) <= consolprob then
bigmap[x-1][y+1] = 3
elseif math.random(1,100) <= (branchprob/2) then
bigmap[x-1][y+1] = 2
else
bigmap[x-1][y+1] = 1
end
if math.random(1,100) <= consolprob then
bigmap[x+1][y+1] = 3
elseif math.random(1,100) <= (branchprob/2) then
bigmap[x+1][y+1] = 2
else
bigmap[x+1][y+1] = 1
end
elseif bigmap[x][y] ==3 then
if x>31 then
if math.random(1,100) <= consolprob then
bigmap[x-1][y+1] = 3
else
bigmap[x-1][y+1] = 1
end
elseif x<31 then
if math.random(1,100) <= consolprob then
bigmap[x+1][y+1] = 3
else
bigmap[x+1][y+1] = 1
end
else bigmap[x][y+1] = 1
end
end
end
end
end
end
```