Skip to main content

User login

What is OpenID?
  • Log in using OpenID
  • Cancel OpenID login
  • Create new account
  • Request new password
Register
  • Home
  • Browse
    • 2D Art
    • 3D Art
    • Concept Art
    • Textures
    • Music
    • Sound Effects
    • Documents
    • Featured Tutorials
  • Submit Art
  • Collect
    • My Collections
    • Art Collections
  • Forums
  • FAQ
  • Leaderboards
    • All Time
      • Total Points
      • Comments
      • Favorites (All)
      • Favorites (2D)
      • Favorites (3D)
      • Favorites (Concept Art)
      • Favorites (Music)
      • Favorites (Sound)
      • Favorites (Textures)
    • Weekly
      • Total Points
      • Comments
      • Favorites (All)
      • Favorites (2D)
      • Favorites (3D)
      • Favorites (Concept Art)
      • Favorites (Music)
      • Favorites (Sound)
      • Favorites (Textures)
  • ❤ Donate
Programming

Cave Generation

mcco0055
Tuesday, July 15, 2014 - 11:55
mcco0055's picture

Hi All,

I've created with some help from couple of sources on theory relating cave generation. I was wondering if any one had thoughts on the topic. One such topic is balance, how to handle multiple caves linkage (portals, complete removal), etc.

Here is my work in progress: http://pcmsolutions.ca/cave-gen1.html

Thoughts and ideas are very much appreciated. It's all in the name of art, well the art of programming.

Thanks!

  • Log in or register to post comments
bart
joined 13 years 11 months ago
Tuesday, July 15, 2014 - 14:47
bart's picture

I like the results you're getting with your current generator and I don't feel that there's any need for you to change it drastically.  However, I'm going to suggest a different approach just because I enjoy these kinds of conversations.

  • First off, start with a 2D grid (like you have now).
  • Randomly pick a bunch of points on that grid and designate them as "nodes".  Optionally, make sure they're a minimum distance from all of the other points.  Then, decide how each one of those nodes connects with the others.
  • For each node, pick a random number (perhaps with a minimum and maximum value specified by the user).  Grow each node by one pixel in a random spot on the border of the node that many times (so essentially, you're making the node into a randomly-shaped room that's that many pixels in size.  When you do this, you can either allow nodes to merge naturally or specifically exclude growth that would cause one node to merge with another.
  • For each connection between nodes, check if you can draw a straight line between them without hitting a wall.  If not, dig a straight line from one node to the other, varying the width of the line (along with right/left offset) until you get to it.

Note that this is just off the cuff, so I can't guarantee how well it would work in practice.  However, in theory, the advantage of it would be that you would be able to specify how many "rooms" the cave has, along with the general shape of the cave.  If you make the nodes big and the connection width small, you could have a bunch of large rooms with small interconnecting passages.  If you keep the nodes small but numerous and allow for some more variation in the connection width, you could have a cave that's made up of randomly winding passages.  You could also tweak the connection generation to favor caves with lots of dead ends or a web of passages.

  • Log in or register to post comments
mcco0055
joined 11 years 2 weeks ago
Tuesday, July 15, 2014 - 16:25
mcco0055's picture

Your method is what most D&D dungeon generators are doing. I like the cellular automata but I can certainly see the appeal of growing caves.

Once the generation is done the hard job I think setup a tileset for use in a system and populating the map with alternate tiles and not feel weird. Sort of like you'd need a rule set, i.e since water tiles can be generated do you allow some water to movement, or wide enough to support a bridge.

Lots to still figure out on what makes the most sense. I think maybe it is easier to have someone design the level after all.

  • Log in or register to post comments
nosycat
joined 13 years 8 months ago
Tuesday, July 15, 2014 - 23:12
nosycat's picture

Bart's idea is sound. I used a variant based on a drunken walk, starting from a set of randomly chosen points. Didn't even bother with interconnecting passages -- simply tweaking the length of random walks was enough. I even had a nice function to make water pool in certain places (wall tiles with fewer than five neighbors would become water). Sadly I can't show you the code in action; changes in web browsers have broken it. But yeah, that works.

  • Log in or register to post comments
mcco0055
joined 11 years 2 weeks ago
Wednesday, July 16, 2014 - 09:32
mcco0055's picture

I'll setup a testcase for node variant @Bart suggests and see how that places out.

  • Log in or register to post comments
ryan.dansie
joined 12 years 3 months ago
Friday, July 18, 2014 - 10:26
ryan.dansie's picture

If your not specifically looking to roll your own, I would reccommend rot.js

http://ondras.github.io/rot.js/hp/

 

I used it in my PDJ game. You can see the results here:

https://dl.dropboxusercontent.com/u/141246873/PDJ/index.html

  • Log in or register to post comments
mcco0055
joined 11 years 2 weeks ago
Friday, July 18, 2014 - 10:42
mcco0055's picture

@Ryan, cute game.

I learn by doing and making a game has been on the "TO DO" list since my C64 game days.

  • Log in or register to post comments
mcco0055
joined 11 years 2 weeks ago
Friday, July 18, 2014 - 14:54
mcco0055's picture

I did the first bit that @Bart suggested.

Steps. New > Grow to see the node growth. It very simply random generates between 2-12 nodes. Then for each node runs a lovely hardcode loop 12 times. A drunkard walk between 2-5 steps in 8 possible directions. If the direction is invalid it uses the last successful coordinate to stumble on from.

http://pcmsolutions.ca/cave-gen2.html

  • Log in or register to post comments
eugeneloza
joined 10 years 8 months ago
Wednesday, September 24, 2014 - 22:16

The cave generation algorithm depends on the game/application it is used for.

E.g. if understanding "It's all in the name of art" then the caves must look beautiful. In case you want a kind of a survival game the caves should be realistic. A strategy game will require its own sort of caves. And a maze-solving game needs other kind of caves.

In my game 'Project Helena' I use 3 following approaches to (cave-like) map generation:

1. Formula-driven map generation.

2. Stamp type maps.

3. Procedural map generation (with two variants: random objects and map areas filling).

The next stage of map generation is addition of some manually created objects (called 'buildings' in the code) including entry point.

After the map is generated all inaccessible areas are replaced for walls.

And there are several criterions of map acceptability for the game (considering 'Project Helena' is a turn-based strategy):

1. Free space ratio (for 'Project Helena' the maps should have 20% to 60% free space).

2. Map homogenity (I usually demand that free space ratio for different map segments should not be different by more than 15% in average)

In case the map is inacceptible by these criterions it is re-generated. There are some algorithms like 'linear-sinus' I use which preform very poorly and have to be re-generated many times until some acceptible result occurs, but when they do well, they create a nice-looking and interesting-to-play map.

As of today there are 29 different map generation algorithms, which you can find in the source code of: https://sourceforge.net/projects/projecthelena/

I've attached several examples. Do not pay attention to a white box and red/blue dots :) It's game-specific (large-scale map, enemies and items).

Attachments: 
Preview
ProjectHelenaMapExamples.png ProjectHelenaMapExamples.png 47.3 Kb [10 download(s)]
  • Log in or register to post comments
smonos
joined 14 years 4 months ago
Friday, October 31, 2014 - 23:43
smonos's picture

i think if you would turn just the cave generation into a library.. tons of people would use it? all those maps look gorgeous.

  • Log in or register to post comments
eugeneloza
joined 10 years 8 months ago
Saturday, November 1, 2014 - 06:26

I'm afraid I don't know how to :) I just compile the programm in Lazarus to get windows/linux executable... Never worked with libraries before... And I don't think lazarus/fpc unit would be of any use, not so many apply it for game development.

Moreover I use only 4 tiles for walls/floors, and most map algorithm create just one pair. Plus several other 'to-do' ideas. I'm going to improve this soon, but I mean that it is not 'finished' yet. I hope that will be completed after integrating the game with Castle Game Engine for better graphics.

  • Log in or register to post comments