Monday, September 15, 2014

Procedural Death Labyrinth Generation, Part 1

...wherein I talk about how Spelunker generates its incredible caverns.

The heart of any good roguelike is the "dungeon" generation algorithm.  Too simple, and players get bored.  Too arbitrary, and players throw up their hands in frustration.  Too weird, and players cannot get a grasp on any sort of consistent reality in the game world.

The key is to make your procedural content persuasive and detailed.


Persuasive Content

For Spelunker, the main goal is exploration, so a primary goal was to not just ape the act of moving around in a cave, but evoke the feeling of exploring a cave system underground.  One of the hardest elements I've grappled with was making the virtual cave system feel like a real-life cave system, while still retaining a sane representation that can be feasibly interacted with using the game's core mechanics, and flattening it all to 2D.

That means faking an organic environment digitally, while still retaining important distinctions like rooms, discrete tiles, etc.

A great way to have your procedural content be persuasive is to use reference material and try to have your content approach that reference material.  I used articles on the web and my own experiences spelunking to try to think of various experiences I wanted to highlight out of real-life caving and how they might be translated to a game.

For instance, one of the really compelling elements of caving is that realization you're on the edge of a crazy-deep drop off, that the seemingly solid stone all around you can house great chasms, chimneys, and pits mere inches from your feet and you don't even know it.

Another compelling moment is when you are crawling through the mud, squeezing through tight little spaces of boring, uninteresting rock, and suddenly find yourself in a place that can only be described as a wonderland of strange formations and colors.

Still another is that creeping claustrophobia, that sense that you've gone too far and won't be able to make it back up to see the sunlight.

All these feelings can be evoked simply by ensuring the algorithm can accommodate those sorts of situations.  The generation system ensures that sometimes, there are sudden yawning drop-offs, tight crawls, hidden troves of visual beauty, and forbidding environments that are easy to enter and hard to climb out of.  The system still decides how these things are represented, where they are placed, how large they are, how extreme they are, etc., but by explicitly allowing for those "moments" to happen in the algorithm, you allow them to happen in the game.

Detailed content

The other requirement for immersion, besides the persuasiveness of an environment, is how detailed the environment is.  Detail is, of course, a double-edged sword.  Too little detail and your game feels barren, with nothing to do.  Too much detail, and your player is lost in micromanagement of the game world.  Somehow, you want to strike a balance between those two extremes that allows interesting gameplay, but not overwhelming gameplay.

And those considerations spill over into the procedural generation of your content, since the gameplay detail and the game world detail have to match.

For Spelunker, I decided early on to stick with the traditional "the player is represented by a single @ on the screen", so already it felt like detail was going out the window.

But there are ways to overcome that.  One of the best things about irregular cave systems is that you can make them feel irregular with what boils down to noise.  Making the floors not be flat, making the ceilings not be smooth, etc., went a long way towards conveying implied detail that was nevertheless a very coarse representation of the game world.  Although there's no obstacle that is shorter in height than two meters, it doesn't feel like you're living in a world of giant blocks because you can relatively quickly scale them.  They feel like slopes, rocky crawls, and uneven ground when you play.

Another element that worked well was the addition of elements with explicitly no gameplay influence.  Here and there, you will see flowstone stalagmites and stalactites in the background; they do not impede your movement, but the breaking-up of that background implies complexity that, while not present in the simulation, certainly manifests in your mind's eye.

(In time, it turned out the stalagmites and stalactites did come to have a gameplay effect, but that's another issue.)

In part two of this blog post, I talk about the mechanics of how I actually went about generating the structure of the caves and populating it with these details.



No comments:

Post a Comment