Pages

Search Results

Sunday, January 23, 2011

Spelunky and Random Level Design

Since this blog is about game development, I thought it would be a good idea to analyze good (or bad) games in attempts to try to understand how the games are made. One of the games that I'll be starting out with is the great PC freeware game Spelunky.

The dungeons are randomly generated for each level
of Spelunky, making for a unique mix-up of RPG,
Platforming, and Action fun.

Spelunky is a game made by Derek Yu, who is an experienced game developer, and is a great platformer game where the Player must navigate a cave, going deeper and deeper searching for treasure. However, there's quite more to the game than just the platforming portions - one of the main great unique aspects of the game is the randomness. You see, each level in Spelunky is randomly generated when you begin it, which means that even if you die several times in the first level, each retry will be different. Also, the levels gain in complexity and difficulty as they progress (the later levels feature less familiar content that isn't present in the beginning of the game).

The most interesting aspect of Spelunky to me is the random level generation. Anyone can just make a game spit out a random set of blocks and objects to traverse or interact with - the hard thing that Spelunky does is make those sets of blocks both random, but fun and logical to traverse, especially in platforming fashion, where the player has a limited range of movement to work with. For example, even with bombs that the player can use to clear blocks out of the way, Spelunky doesn't ever create rooms that are out of the movable range of the player to traverse. I would like to analyze just how this random level generation process works - here is my attempt at doing so.

As far as I can tell, there are three methods to random level generation, each with their own good aspects and bad aspects.

1. Random levels

This method has a high level of customizability - you can easily make levels that are fun and logical to progress along, and that can contain specific traps or props for each level. However, the down-side of this method is that unless you have an absurdly large amount of levels created in relation to however many the player actually will beat in the game, the player will most likely see repeated levels. Also, this possibility will increase each time the player plays the game again. For example, if you make 80 levels but the Player only plays through 40 and begins to play the game again, he'll probably see a repeated level, which would detract from the replay value (and so, the game won't be able to be called truly 'randomly generated').

2. Random blocks

The second method of using random blocks in the creation of each level, is probably the best and worst method of randomly creating levels. The up-side of this method is that it is almost impossible for two levels to look alike or be repeated. The down-side is that creating rooms that are playable, much less fun to run around in, is next to impossible as well, as you don't know how large or what the shape of each room will be.

3. Random rooms

The third method of creating random levels is most likely the most efficient. In this model, the game designer prepares a set of rooms beforehand that consist of rooms, passages, and bridges of different size, shape, and complexity. The designer can easily place props in strategic positions in the rooms, and can make sure that the rooms themselves are fun to play in. The level is then 'randomly generated'. This is done, not in the sense that the individual blocks are being placed, but the game places the rooms next to each other to connect.

In Spelunky's case, this can be used to the game's advantage, as the game can simply put necessary objects, like bomb or rope crates, in very accessible locations, and put more rare and valuable objects in areas where you must use bombs or ropes to gain access to them.

This method of random level creation is the most customizable and easiest to randomize to help ensure the maximum amount of fun possible.

For example, say that we wanted to make a platforming game with randomly-generated levels. As you can see in illustration A, simply putting down random blocks and objects to form a level could have... Restricting effects on the player character (heh). Because you are simply putting down blocks, you can't tell where would be a good place to place the player's character, coins, or any other objects.

As you can see in the second half of illustration A, though, using the random rooms method is far better, as we can tell where the Player should be spawned, and where other rooms can connect. How does this work?

Well, it's actually pretty simple - a level design may be made up of many rooms, but most of the pre-made rooms are similar in design, and so you really only need a few of them. Take a look at Illustration B below. In this illustration, we see a simple dungeon map made up out of several rooms. However, as you can see in the bottom-right corner of the illustration, the room elements are shared - there are only six actual 'rooms' for the whole level.

Illustration B - Pre-constructed level
elements can be pieced together at game
runtime to make a random level.
Game elements can also easily be placed
inside of these pre-made rooms.

We keep a list or array of which rooms there are, and which exits there are for each room. For example, the hallway room has two exits, one at either end. When randomly generating the room, the game simply chooses a random room and places it, then adding rooms at each exit until a maximum room count (either determined arbitrarily or by design) has been reached. Once this happens, the game can cap off the remaining room exits. Spelunky actually had it easier because rooms may not have exact 'exits' as a whole wall may be open. This makes it easier to make a coherent level design as well as make a level design that is easily customizable.

Come back for the second half of this tutorial when I see about implementing this random level generation idea into a game made with the Blender Game Engine. ~ SolarLune

4 comments:

I haven't played Spelunky but now I might have to give it a look. Ever since Diablo I've been interested in random level design (although it's only been recently that I've started trying it myself).

I think one of the pitfalls of random design is that after a while the levels start to feel generic. A procedural generation algorithm can only come up with so many maps and puzzles; after playing for long everything just feels the same. And when you beat the game, you are left wondering if you were really a skilled player, or if you just lucked out and got an easy level.

On the other hand, random design can greatly enhance replayability, and can speed up the game design workflow since you can focus on putting more effort into the key areas of the game (like Boss fights) and connect the dots with randomly generated rooms. It's good to have a mix, since random levels can help you get more mileage out of a game engine you've worked so hard to build, and constant levels (for lack of a better word) can add a bit more character, or sophistication, to your game.

Did you ever get around to writing part 2 of this tutorial? I'd love to see how you do this in the BGE.

Oh, and you are correct that random levels can get boring, but if you do it right, then it can be fun. The levels in Spelunky were pretty short, and were random enough to have select levels or level elements be memorable (a small amount of levels have shops, and another small amount are dark, etc.).