Some of you may know how much I enjoy random content generation. Last night I was thinking to myself, "how could I easily generate a random city for use in, I don't know, a zombie game?" I came up with this post. I have not implemented this yet, but I don't see how it could be particularly difficult.
First, you need a simple grid of streets and lots (to place buildings or other features in). This is the framework for your city.
Second, you will randomly remove some lots from the city and replace them with some non-city feature (such as a forest, a lake, whatever). You need to store the location of the streets from these blocks that you have removed because they will be used later.
Next, you will create an invisible maze structure (the hunt and kill algorithm is simple to implement and works fine) which is layered over your city.
The walls of the maze (purple lines) now tell us what parts of the city are supposed to be somehow walled off.
The fourth step is to randomly remove some (not all) of the streets that are blocked by a wall in the maze. You need to save these locations because they will later be turned into a feature such as a blocked alleyway.
This picture shows what information you should have at this point. The yellow lines indicate that something needs to be on that street to block players from crossing (fire, rubble, dead bodies, whatever). The blue lines (which are the streets that were removed in the second step) indicate you need some way to cross whatever random feature you have placed here (a path through the forest, a tunnel through a mountain, a boat to cross a lake, etc).
The last step is to generate your buildings. Divide the remaining lots into four quadrants, and place the walls for the buildings. Some buildings can be more than one quadrant big, you just have to make sure you don't extend it past a wall in our invisible maze. In this picture, yellow means "this area needs to be blocked."
You can then make your buildings more interesting by placing things inside them, or perhaps making some of them 2-3 stories tall with stairs, etc.
Other stuff to do
You can add all sorts of details to your basic city such as sidewalks, benches, night lights, manholes (which you could then create sewer systems for!), traffic lights, etc.
Anyone have any suggestions on ways to improve this? I am terrible at explaining things, so if you have any questions about something, just ask. Thanks for reading!
Mar 18 2013, 6:07 am