Algorithm for create caves

Started by
6 comments, last by markypooch 8 years, 1 month ago

I want to create caves on my 2d world generated its on a 2d array .

how can i gen like big caves little ones ect..?

thx for read

Advertisement

It sounds as though what you are looking for is land generation algorithms if that's the case there plenty of algorithms that would give you a variable landscape. One of them is Perlin Noise. It is a pseudo-random algorithm that generates a noise texture, that has several applications. There are several links from a google search that shows the process of creating the texture, and the application of it.

Marcus

Land generator is done i want something for do caves on my generated terrain

Perlin noise can generate caves. I use it in my game. Id suggest implementing the algorithm and developing a separate application where you can visually see the values that are generated in the 2D array. It'll make it easier for you to get an understanding of how the algorithm works and how you can use it to generate the caves.

algos that carve out spaces from a level full of solid tiles often yield good results.

open spaces:

sort of a random splat type algo. generate a random location and radius, set those tiles to clear. repeat as necessary. different sizes and combos of sizes will give different results. you can also limit where you splat, big splats near the middle of the level, followed by smaller spats all over, that kind of thing.

hallways:

chains can also be used. generate two random locations, and do a bressingham's line drawing algo between them, clearing tiles as you go. you can also add a radius, clearing all tiles in a radius as you go. this will generate hallways.

winding hallways:

for winding hallways, start with a random location, a random direction, and a random distance. move in that direction for that distance, clearing tiles as you go. then generate a new random direction and distance, and move there, clearing tiles as you go. repeat as necessary. again, a randomly generated radius can also be used. there you clear all tiles in a radius as you move in the random direction for the random distance. you can also generate a random radius at each tile along the path, to give the winding hallway a variable width.

fixing up the map when your done:

set all the tiles along the four edges of the map to solid. place an entrance at an edge, and clear a hallway from the entrance towards the center of the map big enough to guarantee it will always connect with the randomly generated interior space on the map.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

A friend of mine had decent success by throwing random "void" metablob spheres and extracting an isoline from them. Looked quite splotchy to me but I would say maybe his sphere randomizing algo was too high.

+1 for noise. A 2d cave can be generated "simply" and it extends simply to hallways and straight lines as Norman proposes by having a base and height to be perturbed.

Previously "Krohm"

what do you think about pre create 20 or 30 types of caves on arrays and just spawn theys on the terrain and clean all the tiles on the area?

I suppose. But to be honest that sounds like a lot of work when there are algorithms out there (Perlin Noise, but there are others) that can create a very unique, and variable landscape (including vast caverns) that look good, and only need to be coded once, as opposed to you having to statically fill in 20-30 separate arrays for a comparatively small amount of variation.

Marcus

Some people recommend cellular automata for cave generation (as in Conway's game of life, such as e.g. this implementation) I personally have not been able to get them to do something that I really like (maybe, possibly, probably even, my implementation was bugged?), but a lot of proponents of the method seem to agree in unison that it is vastly superior to noise-based algorithms.

This topic is closed to new replies.

Advertisement