# Random map for rogue like game

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
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

``````

@epicurus101 - dude that’s really cool and an approach I’ve never seen before for generating rogue like maps - well done.

This is why I love playing the Codea game!

It’s a great feeling when you see something you’ve managed to create literally out of nothing into something real and useful.

I can see this making a really good “overworld” style map where each “room” is then randomly generated from a set seed so you can revisit old rooms (or even use the random number as an index into a set of pre-generated rooms similar to the “Binding of Issac”

One comment I would make however is if possible, try and stop it from making too many single branches as it looks like you’d get a lot of linear rooms with just north / south exits, although I do like how each level will have a single start / end - great for cueing up boss fights and starting the player at a safe spawn point.

Kudos to you.

nice work!

it’s the kind of work we like to see shared

PS maybe you can limit the number of single branches by allowing (say) a maximum of three rooms in a row without branching

Thanks for the feedback! The map is intended to be “one way”, from bottom to top, and each point represents an area of particular terrain where the player will have to win a certain number of battles before they can move on. Players get a degree of choice over the environments they move through, which will influence the battles they play at each stage. So it’s not a freestyle dungeon crawler, which makes it simpler.

The branchprob parameter is intended to change things up a bit (before the halfway stage). Increase it and reset the map to get more branching. I haven’t decided yet what “ideal” branching looks like for my purposes.

But you’re right you can still end up with a lot of straight lines. Also, I’m going to find a way to introduce more cross-linkings in the later stages, to prevent it becoming too linear. It’s a work in progress maybe!

Well you’re off to a good start, it’s an interesting take on procedural generation.