Friday, October 23, 2009

Run, jump, plummet...

The level design in Spelunky - yes, even though a computer is doing it, it's still level design - at first looks totally random. You have long strethes of tunnel, deep craters. criss-crossing passageways and more, but even with a really clever program it would be almost impossible to create an actually playable level if you're using totally random level generation.

Note that all I'm going to talk about here is reverse-engineering the game, and may or may not be the way it's actually done. Some bits are more obvious than others, but I make no assumption that I know what's in the code.

The first thing that goes into the level is the path to the exit. You start with about four floors worth of map, with the entrance in one of the top corners and the exit in one of the bottom corners. Then, paths are cut between the different layers, they only need to be a single space wide, but we'll get to the variations in a minute.

Once a basic path is created, terrain is put in. After playing the game for some time I can see that there are a number of different terrain blocks that get used, most of them one floor high and twenty or thirty tiles wide. There are tiles that contain entrances, tiles that contain exits, tiles that contain paths to the next floor, tiles that contain idols, and other tiles that contain nothing but rocks, so far. (What's an Idol, you ask? I'll cover that next post, but it's a game mechanic). There are some special peices of terrain that cross more than one floor worth of space, and others that cross less than one, but for the most part, it's simple cut and paste from the database.

But that would make for a boring game, wouldn't it? Yes it would, but because Spelunky is great, the terrain doesn't stop it's generation there. First, on each terrain peice, there are a number of blocks that may or may not contain a tile of terrain. Sometimes, this allows you extra tunnels, other times it makes jumps harder, and still other times it gives the monsters distinct advantages over your character, for example in a tight tunnel with nothing but a whip (usually) spelunkyman really has a tough time overthrowing a yeti, who has to be jumped on to disable.

These little variations add an almost infinite amount of varaition to the game, even before you consider the enemies, treasure, and other challenges that are generated after the terrain, and especially before you consider the number of different interlocking art tiles that make even identical hallways look just a touch different. You really will play a different game every time you play, the occasional four-level deep pit or endless floor of spiked death mixing up what might be a standard crawl through.

No comments:

Post a Comment