Skip to main content
GameDev.net gamedev.net
🔒 Locked

Generating caves

Started by peter_b May 3, 2004 at 12:50 PM 5 replies 750+ views
Original Post
peter_b
peter_b
Hello Im looking for an algorithm suited for generating 2D top-view tile caves (no big spaces, just narrow passages, kinda like the pacman map). It dosn''t have to be labyrith-like with only one correct way. Iv seen alot of nice algorithms for generating landscapes, heightmaps etc, but iv never really looked into terrain generation before and i don''t know how well those could apply to this task, with appropriate filters of course. But does anyone know any algorithm that would be suited for this kind of task? Thanks in advance.
Shields up! Rrrrred alert!
Fruny
Fruny
If you want to hand-generate them, like, with a graphical tool, here's how you can go about it.

Generate a height map, then take a slice out of it. That is, consider that heights below some minimum value and heights above some maximum value are "rock".

With the GIMP (2.0.0)
* Filter-Render-Clouds-Solid Noise
* Layer-Color-Threshold

Then, if you wish you can generate two more heighmaps, one for the ground, one for the ceiling, or more generally 'distort' it along the Y axis.

Sample output:



[edited by - Fruny on May 3, 2004 2:39:33 PM]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Fingers_
Fingers_
You could look at "rogue-likes" (nethack, dungeon crawl, moria)... These games use maps like you describe, and many of them are open-source. Another thing to google for is maze generators.
RuneLancer
RuneLancer
I haven''t actually tried this but I just got an idea.

First, generate a midpoint displacement map. Google for it if you''re not sure what that is (sorry, I''m in a bit of a rush ). Set a lower threshold so that it "clips" at, say, 50 (assuming your values go from 0-255). If you render that as a heightmap you should have a straight floor and various hills here and there.

Next, subtract 50 from every point on your map so that it goes from 0 to 205 (we "clipped" at 50, remember?) and multiply by, say, 3 (with 255 being the max value). This''ll give you steeper "hills" and in some places, pillars and walls, if you render it.

Use that to render the "floor", then flip it upside down and use it to render the ceilling. (Not sure if that made sense...) Voila! Cave! Admittedly, it''d be a little symetrical, but I suppose it could work. If you try this, please post screenshots, because I''m curious what it''d look like. I might give it a shot too and post screenshots of my own.
RuneLancer
RuneLancer
It looks like crap because of the amount of effort I put into it (edited the source in one of my old VB landscape renderers) but you get the idea...



Something rendered with, y''know, a little more than what I''m doing here could have some pretty good results I guess. Not bad for an idea I pulled out of my rear on the fly, I suppose. Though this is more "natural" and less "dungeon" like...
Squirm
Squirm
I''m actually doing something similar, although in 3D, taking very similar lines to what people have suggested here. However, I found that taking a single slice through a heightmap (or in my case, an isosurface through 3D noise) didn''t give the results I wanted. It looked too much like a random blob and not enough like a cave I could play a game in.

The approach I''ve taken now is to generate the cave as a random set of rooms and a random set of connections between them, all nice and neat, but represented as field strengths (field > 0 = rock, field < 0 = corridor). This means a room is a spherical field and a corridor is a cylindrical field. Then, to make it more cavelike and less "tidy" I add a noise field, and some turbulence. In your 2D case, you would define the cave system as a set of canal-like structures in a flat world, add a 2D heightmap to it, and _then_ take the slice through the middle.

Here''s a badly rendered view from on top of mine (out of date, with turbulence but without the noise ... you should get the idea):
http://homepage.ntlworld.com/andrew.newman207/stuff/dungeon.jpg
JTippetts
JTippetts
Metaballs(aka blobs). Or, in the case of 2D caves, metacircles. Each metacircle is a 2D field of decreasing strength centered about a point. Adjacent blobs sum their fields together in the regions where they overlap. Take some threshold field value, and trace an edge connecting all points in the field that have this threshold value. With a large collection of metacircles of various sizes, you can generate some pretty interesting globular caves.

Metaballs at Siggraph.


Also, as Fingers_ suggested, you could do some research into roguelikes.
DungeonDweller -- A page with some good articles and snippets.
Simugraph -- An index of various roguelike programming articles


World of Golem

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.