Procedural Generation 3: Cave Source
I wrote an article awhile back, which is still the most visited article on this site, and I was really proud with the efficiency and look of the caves that the algorithm in the second part of that produced.
Anyways, now that I'm also working in Flash, I decided to write an ActionScript3 version of the algorithm. While doing it, I also made some improvements. Now, it's even slightly faster than before, you can set the minimum or maximum size of cave you desire, and I've added some security features to prevent stack overflow with certain setups.
I've taken a couple of maps created with various settings changed. And, because I'm in a good mood, I'll give out the full source so you can all have a look!

DOWNLOAD SOURCE
That has two files, Main.as and Map.as. The Map class contains the algorithm and functions used to generate the cave. I have commented the file as thoroughly as possible, and wrote a big explanation in Map.as explaining a bit how the algorithm works. The files can be opened with any plain-text viewer if you don't have a Flash editor. If you make any use of it, or re-write it in another language, please email me and let me know! I'd love to see what you've done with it, and hear about any tricks of your own you might have come up with.
After I posted that earlier procedural-generation article, I've been getting pretty steady responses from a topic at TIGSource from people who are creating their own dungeon algorithms, and others who are adapting mine into other languages, such as AS3, Java, and Python. I figured I'd share some of what's going down over there, because even recently there's been some pretty neat stuff popping up!
First off, here is a Flash version of the map-generator, created by Kneecaps. You can click on the map to generate a fresh one.
He was also kind enough to post the source, which you can get here. Next up, forum member Cthulhu32 wrote a version of the same algorithm in Python.
He also posted the full source, which can be viewed here at your pleasure. Such awesome folks!
Then, things started to mix up a bit. Zaratustra created an island generator, which was apparantly for an unfinished game. But it was very cool nevertheless! Click on the picture for the full (4000 x 4000) image.
Epitaph64 was next up, and posted a simple Java terrain generator that uses basic recursion. He also posted about it on his site, with the source files.
Fifth decided to try his hand at creating the cave algorithm, and it worked out really well. In the second shot below, he gave the algorithm slight inclination to spin counter-clockwise, which was a really neat touch. The flexibility is part of the reason why I like the algorithm so much. According to him, the generation time was always instantaneous too, which was great to hear.

Next up was hagel who, inspired by the topic, had decided to experiment with some algorithms written in FreeBASIC. The results were cool, and the source can be downloaded here. His was similar to my cave algorithm, in that it used creeps that moved around and "carved" out the trails. While mine only uses one, though, he set it up so you could change the amount of creeps issued, so the caverns where fairly expanded and less linear than my own, as can be seen below.
He also posted some pics of a platform-level generator as well. The first has only 45-degree slopes, and the second shot uses 23-degree slopes as well.

We had another Java setup from Ina Vegt. She made a maze generator, which creates a maze of boxes that you can navigate through with the character. Be aware the this file will not work in Opera, though. You can play it here.
Finally, another Game Maker user, pgil, came along with a GML version of my cave generator, using tiles and entry/exit points in a similar manner. He even posted the EXE and GMK files for those who want to see it in action or check out the code.
Very recently, roboprez posted another Flash version of the map generator, which can be seen here. Click on the image to iterate, and press space to iterate backwards. The land starts to take more shape each time you iterate.
And finally, Hayden Scott-Baron (also known as Dock) has been working on some procedural generating room techniques, and has come up with some very nice looking results.

And that's it so far! I'm delighted with the response so far, and I've gotten plenty of inspiration and ideas seeing how other people have adapted my scripts and also come up with their own. Hopefully anybody else who is interested will learn a two or things from these source files.
If you like the article, please leave a response! The previous ones got plenty of views, and the better response I get to each post, the more I'm likely to write more related articles and do more research in the future.
Thanks to the folks at TIGSource, and all the visitors! :)
Anyways, now that I'm also working in Flash, I decided to write an ActionScript3 version of the algorithm. While doing it, I also made some improvements. Now, it's even slightly faster than before, you can set the minimum or maximum size of cave you desire, and I've added some security features to prevent stack overflow with certain setups.
I've taken a couple of maps created with various settings changed. And, because I'm in a good mood, I'll give out the full source so you can all have a look!

DOWNLOAD SOURCE
That has two files, Main.as and Map.as. The Map class contains the algorithm and functions used to generate the cave. I have commented the file as thoroughly as possible, and wrote a big explanation in Map.as explaining a bit how the algorithm works. The files can be opened with any plain-text viewer if you don't have a Flash editor. If you make any use of it, or re-write it in another language, please email me and let me know! I'd love to see what you've done with it, and hear about any tricks of your own you might have come up with.
After I posted that earlier procedural-generation article, I've been getting pretty steady responses from a topic at TIGSource from people who are creating their own dungeon algorithms, and others who are adapting mine into other languages, such as AS3, Java, and Python. I figured I'd share some of what's going down over there, because even recently there's been some pretty neat stuff popping up!
First off, here is a Flash version of the map-generator, created by Kneecaps. You can click on the map to generate a fresh one.
He was also kind enough to post the source, which you can get here. Next up, forum member Cthulhu32 wrote a version of the same algorithm in Python.
He also posted the full source, which can be viewed here at your pleasure. Such awesome folks!
Then, things started to mix up a bit. Zaratustra created an island generator, which was apparantly for an unfinished game. But it was very cool nevertheless! Click on the picture for the full (4000 x 4000) image.
Epitaph64 was next up, and posted a simple Java terrain generator that uses basic recursion. He also posted about it on his site, with the source files.
Fifth decided to try his hand at creating the cave algorithm, and it worked out really well. In the second shot below, he gave the algorithm slight inclination to spin counter-clockwise, which was a really neat touch. The flexibility is part of the reason why I like the algorithm so much. According to him, the generation time was always instantaneous too, which was great to hear.

Next up was hagel who, inspired by the topic, had decided to experiment with some algorithms written in FreeBASIC. The results were cool, and the source can be downloaded here. His was similar to my cave algorithm, in that it used creeps that moved around and "carved" out the trails. While mine only uses one, though, he set it up so you could change the amount of creeps issued, so the caverns where fairly expanded and less linear than my own, as can be seen below.
He also posted some pics of a platform-level generator as well. The first has only 45-degree slopes, and the second shot uses 23-degree slopes as well.

We had another Java setup from Ina Vegt. She made a maze generator, which creates a maze of boxes that you can navigate through with the character. Be aware the this file will not work in Opera, though. You can play it here.
Finally, another Game Maker user, pgil, came along with a GML version of my cave generator, using tiles and entry/exit points in a similar manner. He even posted the EXE and GMK files for those who want to see it in action or check out the code.
Very recently, roboprez posted another Flash version of the map generator, which can be seen here. Click on the image to iterate, and press space to iterate backwards. The land starts to take more shape each time you iterate.
And finally, Hayden Scott-Baron (also known as Dock) has been working on some procedural generating room techniques, and has come up with some very nice looking results.

And that's it so far! I'm delighted with the response so far, and I've gotten plenty of inspiration and ideas seeing how other people have adapted my scripts and also come up with their own. Hopefully anybody else who is interested will learn a two or things from these source files.
If you like the article, please leave a response! The previous ones got plenty of views, and the better response I get to each post, the more I'm likely to write more related articles and do more research in the future.
Thanks to the folks at TIGSource, and all the visitors! :)









3 Comments:
Wow, all of these are really impressive. I really liked your other articles and it is interesting to see how they can be modified. I still want to try my hand at some procedurally generated content, so the source code you posted up will come in handy!
This is all awesome, I'd like to do this someday if I ever make a simple platform game. The two color brown and blue ones remind me of Worms 2 (http://www.worms2.com). Are you planning on using this soon, or just researching?
This has inspired me to attempt to create a procedurally generated map. It turned out OK using a different logic. I wrote it in C. Keep up the good work, I love these articals, very informative. You should create one based around A* pathfinding.
Post a Comment
<< Home