Much like the original discussion of procedurally generated content at the Game Developer's Conference by Will Wright was an excuse for him to show off Spore, this is going to be an excuse for me to show off my work.
I'd asked a few months ago if dynamically generated content was possible in Construct and got some mixed replies...it took me a few months to nail the game idea, which obviously has a bearing on progress towards completing it. Needless to say, after nailing the aforementioned idea, and realizing my game was going to be set in the modern era - 1930's to now possibly - not sure exactly when - I set off to make a city generator.
The entire map is held in a 100x100 square array which I feed into a loop to display on the screen. The sprites you see are just 10x10 pixel sprites of solid colors, eventually I will make them about 128x128 and give them art.
The generation process consists of four steps. First I fill the array with blanks, pretty simple. Second is the longest step - the roads. I start out by making a dual lane highway, which right now will always form a cross. Eventually there will be the possibility of straight and maybe turning highways. Then the program will pick a random highway or road, decide what directions are possible for it to go from that point, then branch off in a possible direction and keep going in that direction until it hits something - another street or the boundary of the map. A process which is a lot easier said than done in Construct events. This process will loop about 20-40 times until you get a grid similar to the one you see. The third step is that blank buildings are placed at random along these smaller roads, they don't cluster yet but they should. The fourth and last step is probably the second most complicated one. RCI - Residential, Commercial, Industrial - which is probably a term some of you remember from SimCity. My game is not a strategy game, but for realism I will need these various facilities and thus thought it necessary to add them. The game will choose centers for each zone, and spread the zones into the blank buildings by proximity to these centers...the ones furthest from the centers will be considered "Light Residential", "Light Industrial", or "Light Commercial". Those are the lighter colors you see.
Ladies and gentlemen, I present to you, in no certain order: Brightbourne, Whitemere, Lakegate, and Mossbridge. Four cities I generated in about one percent of the amount of time it took me to make this picture and write this post.
<img src="http://img7.imageshack.us/img7/9673/smallproceduralcitiesin.png">
All of which you may or may not see in my game Crooked sooner or later, depending on how the generator treats you. Crooked is going to be a combination of Trilby: The Art of Theft, Zelda 2, and Spelunky - in that order. That is, assuming I ever finish the game.
<img src="http://img15.imageshack.us/img15/9307/cooltext415895798.png">
Yes...I exaggerated the logo specifically to let you know it's pronounced with two syllables. But back to the subject at hand, procedural generation. A few things I've learned so far. I looked on the web for algorithms, and ended up not finding any...you won't really, especially if you have specific needs. Even if you did find one, it's not going to translate into Construct very well, because Construct is almost conversational in implementation. You just have to imagine how you would draw it, or how it would be. I opened up paint, drew up some roads, and realized I was using 90 degree angles from random points, and that's where I began. Thinking of things literally in that way made it much easier to translate into Construct than trying to think of it mathematically or programmatically. Another thing - doing natural generation has to be a lot easier than doing man-made stuff I would imagine. Random terrain must be a snap compared to this. Anyway, if any of you have any questions, tips, or suggestions, please leave them.
Edit: Posted in general because I don't have a cleanly commented *.cap to upload yet, and while I have plans on making one - this isn't a tutorial yet either.