Procedural map generation

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
fridays18
Citizen
Posts: 90
Joined: Tue Nov 01, 2022 3:24 pm

Procedural map generation

Post by fridays18 »

Hello, im making a rougelike right now and although I have just made premade maps in the past and cycled through randomly in the past this time around I want to add random generation, the map is supposed to be a maze that will have a couple values, 1(wall),0 (floor), 2 (exit), 3(item), 4(jump scare). I want it so that each time the player finishs a level a map is made with these values. Does anyone know of any libraries or tutorials that could help me out? Any help is appreciated :)

Demo of what the map/tilemap should end up looking like after generation minus 3 and 4(the values)

Code: Select all

	tilemap = {
		{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
   		 {1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1},
    		{1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1},
		{1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1},
		{1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1},
		{1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1},
		{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
		{1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1},
		{1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1},
		{1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1},
		{1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1},
		{1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1},
		{1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1},
		{1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    }
User avatar
darkfrei
Party member
Posts: 1197
Joined: Sat Feb 08, 2020 11:09 pm

Re: Procedural map generation

Post by darkfrei »

:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
BrotSagtMist
Party member
Posts: 657
Joined: Fri Aug 06, 2021 10:30 pm

Re: Procedural map generation

Post by BrotSagtMist »

Consider this is a small map and computers are pretty fast.
You can just bruteforce a map by doing creating/checking a few hundred times and it will still be fast enough to work without loading times.

I do have the same map design in one game, my procedure is:
Pick random point to turn it into a floor, extrude in random direction given that left and right of the new floor tile is no already existing floor tile. Repeat a few times.
Repeat picking points and extruding in that manner a few times.
Pick a random floor tile, walk every possible way from there, if we can walk long enough the point and the tile we walked to are now entry and exit.
If the way is not long enough, repeat picking another point.
If it fails several times, repeat from the beginning and create another map.

My game makes like 200-300 maps that way before starting a new round but the calculation time for that is barely noticeable even of on the oldest hardware.
obey
User avatar
fridays18
Citizen
Posts: 90
Joined: Tue Nov 01, 2022 3:24 pm

Re: Procedural map generation

Post by fridays18 »

BrotSagtMist wrote: Tue Dec 13, 2022 3:57 pm Consider this is a small map and computers are pretty fast.
You can just bruteforce a map by doing creating/checking a few hundred times and it will still be fast enough to work without loading times.

I do have the same map design in one game, my procedure is:
Pick random point to turn it into a floor, extrude in random direction given that left and right of the new floor tile is no already existing floor tile. Repeat a few times.
Repeat picking points and extruding in that manner a few times.
Pick a random floor tile, walk every possible way from there, if we can walk long enough the point and the tile we walked to are now entry and exit.
If the way is not long enough, repeat picking another point.
If it fails several times, repeat from the beginning and create another map.

My game makes like 200-300 maps that way before starting a new round but the calculation time for that is barely noticeable even of on the oldest hardware.
That sounds perfect! Do you still have any code form that project id love to check it out as a reference since if not too sure how I would go about certain things like checking if entrance to exit working or the actual randomization of the map(I have a general idea but its pretty hypothetical)
User avatar
fridays18
Citizen
Posts: 90
Joined: Tue Nov 01, 2022 3:24 pm

Re: Procedural map generation

Post by fridays18 »

darkfrei wrote: Tue Dec 13, 2022 3:30 pm Any reference? https://www.google.com/search?q=site:lo ... procedural
Like reference to how it should look?
User avatar
BrotSagtMist
Party member
Posts: 657
Joined: Fri Aug 06, 2021 10:30 pm

Re: Procedural map generation

Post by BrotSagtMist »

You may just grab the entire game: https://pmprog.itch.io/desktop-labyrinth
And while you are at it, can you tell me if it starts without border decoration?
Somehow this doesnt seem to work in every case and i really dont know why.
obey
User avatar
fridays18
Citizen
Posts: 90
Joined: Tue Nov 01, 2022 3:24 pm

Re: Procedural map generation

Post by fridays18 »

fridays18 wrote: Tue Dec 13, 2022 4:02 pm
BrotSagtMist wrote: Tue Dec 13, 2022 3:57 pm Consider this is a small map and computers are pretty fast.
You can just bruteforce a map by doing creating/checking a few hundred times and it will still be fast enough to work without loading times.

I do have the same map design in one game, my procedure is:
Pick random point to turn it into a floor, extrude in random direction given that left and right of the new floor tile is no already existing floor tile. Repeat a few times.
Repeat picking points and extruding in that manner a few times.
Pick a random floor tile, walk every possible way from there, if we can walk long enough the point and the tile we walked to are now entry and exit.
If the way is not long enough, repeat picking another point.
If it fails several times, repeat from the beginning and create another map.

My game makes like 200-300 maps that way before starting a new round but the calculation time for that is barely noticeable even of on the oldest hardware.
That sounds perfect! Do you still have any code form that project id love to check it out as a reference since if not too sure how I would go about certain things like checking if entrance to exit working or the actual randomization of the map(I have a general idea but its pretty hypothetical)


Executed idea =

Code: Select all

function newMap()
	player.tile_x,player.title_y = 6, 2 
	tilemap = {
		{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
		{1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1},
    {1, math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), 1},
		{1, math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), 1},
		{1, math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), 1},
		{1, math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), 1},
		{1, math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), 1},
		{1, math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), 1},
		{1, math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), 1},
		{1, math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), 1},
		{1, math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), 1},
		{1, math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), 1},
		{1, math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), 1},
		{1, math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), 1},
		{1, math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), 1},
		{1, math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), math.random(0,1), 1},
		{1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    }
	
end
which although technically works it makes impossible mazes that end up looking like this
Screen Shot 2022-12-13 at 11.10.39 AM.png
Screen Shot 2022-12-13 at 11.10.39 AM.png (48.43 KiB) Viewed 2789 times
User avatar
fridays18
Citizen
Posts: 90
Joined: Tue Nov 01, 2022 3:24 pm

Re: Procedural map generation

Post by fridays18 »

BrotSagtMist wrote: Tue Dec 13, 2022 4:11 pm You may just grab the entire game: https://pmprog.itch.io/desktop-labyrinth
And while you are at it, can you tell me if it starts without border decoration?
Somehow this doesnt seem to work in every case and i really dont know why.
Just checked it out it looks cool! but how would I go about checking if a start position leads to the end since im pretty lost of that front. I made the generation(linked in another reply) and I would know how to even do the map reset if a strict path is true but im lost when it comes to this. Did you use a pathfinding lib?
User avatar
BrotSagtMist
Party member
Posts: 657
Joined: Fri Aug 06, 2021 10:30 pm

Re: Procedural map generation

Post by BrotSagtMist »

At this point i am really sorry this code is so hard to read (i wrote that in a day).
But the concept i explained above are basically just lines 258-299 in that main.lua file.
There is nothing more to it.
obey
User avatar
fridays18
Citizen
Posts: 90
Joined: Tue Nov 01, 2022 3:24 pm

Re: Procedural map generation

Post by fridays18 »

BrotSagtMist wrote: Tue Dec 13, 2022 4:34 pm At this point i am really sorry this code is so hard to read (i wrote that in a day).
But the concept i explained above are basically just lines 258-299 in that main.lua file.
There is nothing more to it.
If its not too much to ask can you send a screenshot of it?
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Semrush [Bot] and 6 guests