So I'm making a game using love2d where the player will find himself in an zombie infested city but I don't want the city/map to be just the same all the time, so I want to create a random map/city generator, but I don't know where to start, I maybe can make my own but the result would probably be not what I wanted, as I don't want tiles getting placed all over the place messily(it won't look like a city then), I want random set of tiles getting placed in the world/map like buildings get placed randomly throughout the world/map, I hope someone can help me with this as this is really hard for me...
Like stated by Shiro in a comment , it's difficult to give a precise answer. I can suggest a possible starting point.
Use random voronoi generation where , given a set of random points P , each point in space is weighted relative to the distance from the nearest p in P.
Now , instead of considering euclidean distance use Manhattan distance and you get something like this :
then adjoust the gradient to obtain this
There are simple ways to generate cities, depending on your needs.
Some time ago, I wanted to generate cities for a fantasy setting, so I started playing with a generator. Like I said in another SE post: "rough on the edges" is an understatement. But it suits my needs (it may meet your needs too).
Some terms I use internally:
- A tile is the smallest unit I handle; on the image one of the small houses fills almost a full tile.
- A block is a group of NxM tiles.
And this is how I generate it:
First I generate a central feature, such as the block with the "fountain" (let's call this block a town square). I decide its width and height and place it near the center.
Then I try generating "blocks" for as long as I can:
- Generate a block size (somewhere between 2x2 and 5x5).
- Iterate through the image and decide where to place it. For this a weight is assigned depending on adjacency to other blocks (similar to what I explained on this post).
- Place the block if a suitable location is found. When no suitable location is found, go on to the next step.
Once all blocks have been placed, I can add houses and buildings for each block. I took care of leaving a gap between blocks and another between houses. Some buildings use four tiles (2x2).
Finally, I do the actual drawing in an image.
You should do some research about l-systems, they allow you to specify some basic rules and then procedurally generate the map.
You could for example specify that every building must be surrounded by roads, and every road must continue in a straight line or eventually end, and every road is surrounded by buildings or empty space. Then, the algorithm will start "substituting" a building with a building surrounded by roads, a road piece with a full road... until you have a complete city.
Read the answer to this question for a more detailed explanation: Using L-Systems to procedurally generate cities