How (and Why) Spelunky Makes its Own Levels | Game Maker’s Toolkit
Articles Blog

How (and Why) Spelunky Makes its Own Levels | Game Maker’s Toolkit

August 10, 2019


This is Game Maker’s Toolkit, I’m Mark Brown. If there’s one game I’ve played more than
any other, it’s Spelunky – a viciously hard platformer that takes the side-scrolling thrills
of games like Mario and Castlevania, but snatches away your ability to learn the level layouts
and enemy spawns by mixing up the map, every time you die. But what makes Spelunky so special is that
even though the levels are randomly cobbled together, they’re always fair and enjoyable.
Even after 1000 runs, I’ve never stumbled upon a crappy level. They just don’t feel like the product of an
algorithm – which, in some games, spits out levels that are messy and unfocused and full
of dead ends. In Spelunky, these procedurally made stages are as sharp and satisfying
as the levels in some hand-crafted games. And that’s because creator Derek Yu struck
the perfect balance between random and authored content. He explains how he pulled it off in his new
book, titled Spelunky, which I highly recommend to anyone interested in design. But, while you’re
waiting for it to come in the post, I’m going to use some info in the book to explain how a Spelunky
level is half generated, and half designed. And then we’ll look at why it was so important
for the game to have an infinite supply of unique levels. Though, first, we need to go back to where
it all began – because while you might think of Spelunky as looking like this, it actually
started life as a free, pixel art game, now named Spelunky Classic. So, every level in Spelunky is generated by
a script that starts with the same basic shape and size: 16 rooms in a boxy 4 by 4 grid. The first thing the script does is pick a
random room from the top row, and makes this the entrance. It will then randomly place a room to the
left, right, or beneath this room. This process is repeated from room to room – and if the
path hits the edge of the level, it also goes down – until we get to the lowest level; when
it tries to go down once more, an exit is made. Every room on this main path has openings
to the left and right, but rooms where the path drops also have exits on the bottom,
while the rooms you drop into are given exits at the top. What you end up with is a guaranteed path
through the level that you’ll always be able to get through without using ropes or bombs.
The other rooms are not on the critical path, so they may be open, or they may be walled
off depending on their design. Next, each room is randomly given a template.
Derek Yu hand crafted a number of room designs, with different layouts for rooms where you
drop down, rooms you land in, corridors you run through, and rooms not on the critical
path. But these templates are not set in stone,
and parts of them are randomly generated. Sometimes entire chunks of tiles are plastered
on at random. This means that while you might start to see familiar set-ups, they will always
have their own unique quirks. Next, a script checks every tile on the map
and rolls a dice to see if it should place down a monster, some treasure, or another
object. Again, it’s not entirely random – gems and crates are more likely to appear in spaces
surrounded by walls, and enemies generally don’t spawn in cramped spaces. And everything is weighted,
so a level isn’t filled with fire frogs or crates containing jetpacks. Describing his level-making algorithm, Derek
Yu says “This system doesn’t create the most natural-looking caves ever, and players
will quickly begin to recognize certain repeating landmarks and perhaps even sense that the
levels are generated on a grid. But with enough templates and random mutations, there’s
still plenty of variability. More importantly, it creates fun and engaging levels that the
player can’t easily get stuck in, something much more valuable than realism when it comes
to making an immersive experience.” There’s still more to a Spelunky level, of
course. Those rooms not on the critical path can contain golden idols that set off a boulder
trap, or a sacrificial altar where you can trade bodies for helpful items. A room can also be a shop where you can buy,
or steal items. “The difficulty of buying all the items you want and the consequence
to your score” – your final score is based on how much loot you found – “creates a strong
temptation to steal from the shop”, says Yu. If you do pilfer an item, the shopkeeper will
not only try and kill you with his shotgun, but his buddies will appear at the end of
every level for that run, and attack you in a mad, unpredictable fury. Every level also has a damsel in distress,
which gives you one extra health point. While the health pick-ups in other games – be
it a mushroom or a turkey leg or a pizza – are activated immediately, Spelunky makes you
carry the damsel to the exit, leading to tricky moments where you have to lug multiple items
through an unpredictable maze. And finally, there’s the ghost. Stick around
in one level for too long and a spectre will appear and instantly kill you if it touches
you. All of these additions, which are highly authored,
but scattered about the procedurally generated worlds, are about making choices and weighing
up your options. Derek Yu says “I wanted to force [the player] to make difficult decisions
and experience both the satisfaction of choosing correctly and the regret of choosing poorly”. So do you sacrifice your score by spending
money on the shop? Or do you just rob it and deal with the consequences? Do you risk throwing
a damsel down here, or leave your shotgun behind? Do you grab the golden idol, and risk
getting smushed by a boulder? And can you collect these gems before the ghost appears? Those decisions would be far less interesting
to make if you had already played the level before and knew the right path to take or
could predict the exact outcome of snatching a golden idol. But because you never know
how the stage will be laid out, the game forces you to read the situation and make a plan,
before watching it all go hideously wrong. And that’s all the more painful when you know
you’ll be sent back to the very start of the game, now with all new levels to tackle. The stakes in this game are super high. Plus, not allowing you to master the stages
means you’ll need to master the mechanics instead. You’ll need to understand the quirky
physics of your jump and the tiny reach of your whip. You need to learn the unique properties
of each enemy, so you can to predict what will happen when you enter their domain. And
you have to learn about the items, and the secrets, and the tricks that will keep you
alive for longer. So Spelunky proves that an algorithm doesn’t
necessarily lead to soulless levels – balancing authored and random content can lead to levels
that are satisfying to play. And by removing the ability to learn levels – either after
you die or on your second or 1000th playthrough – this game encourages you to learn the underlying
mechanics, and makes you read the situation carefully before making those very difficult decisions. Thank you so much for watching! Spelunky is one of my favourite games of all
time so it’s great to be able to dig into just one aspect of what makes it so special. I will no doubt come back to the other bits
– like the emergent gameplay and the crazy secrets – in future videos if you would like to help this show please
consider subscribing on YouTube to get new episodes delivered directly to your inbox, or even
pitch in a few dollars per episode over on Patreon. just like these top tier subscribers have
done

Only registered users can comment.

  1. New Super Mario Bros is the first game to have Spelunky's style of damsel in distress, with it's toads found in bricks in single player mode.

  2. I got Spelunky years ago years ago, played a couple times, got frustrated and gave up rather quickly. Then Mark published this video and convinced me the game was worth another shot. Nearly two years later, I've put several hundred hours into the game, and it's become a slight obsession of mine. I bought Derek's book, play the daily challenge every day, and rank far higher than any of my friends. All because of this video. Thank you, Mark. Your channel is a blessing.

  3. You should try Caveblazers. It’s not as good as Spelunky I’d say, but the level design is very similar.

  4. I've actually had a jungle level with no way to leave the entrance, because I had no ropes or bombs. But I have no evidence to back this up, so my word means nothing. 🤷

  5. What’s up with so many shop keepers literally being more powerful then most bosses if you anger them, i blame Zelda

  6. The only problem I have ever found with this is that the 'guaranteed' path through sometimes fails. The only example I have of it failing though is that sometimes on the jungle levels the tiki traps can block the pathway.

  7. There was this Spelunky Youtuber I watch (Israel Blargh), he was in the ice-caves (3-4), He got stuck since he the mothership blocked his way to go down, he didn't have any bombs left. IT WAS VERY SAD.

  8. You say that you're always able to progress without the use of items, yet this (http://steamcommunity.com/id/1TacocaT1/screenshot/913547533755311062) contradicts that statement.

  9. >they're always fair
    Ok that's bullshit. Legit there's times when you spawn in an ice level where if you don't instantly move some random elephant can make a chain reaction of mines and kill you, it happened to me.
    And in the pyramid there's a chance that you get instantly killed by the teleporting monster.
    That's not fair, it's a roguelike and it requires skill and luck, but if you're unlucky you will die no matter how skilled you are.

  10. I've had a few issues with the map gen and enemy placement from time to time, nothing is perfect obviously.

    That being said, because each one is softly random I find myself getting bored with the game because it isn't focused on level design but tries to be and in return gets designs where you may need a bomb or rope to get something or in rare cases even complete a level.

    I'm not going to say it is a bad game, but I do feel it hit the balance between authored and random where each stage felt more generic and without a quick scenery change would probably kill the game. The vast differences between each area, with the final being a mixture of everything.

    In my personal experience I don't have high praises for it, but it isn't bad imo either.

  11. I used to play the demo on xbox and would have to constantly restart the game. The thing is that each time I restarted, I got the exact same levels in the exact same order. Is it possible that the randomly generated levels aren't generated right when you start the run, but a large amount were generated in the game and put in the game in that order before release? It might be only for the demo version though. I might have to test this on PC by starting a new save file, play a few runs, delete the save file, and repeat the process to see if the levels are the same.

  12. Well to be fair, sometimes you are stuck without a bomb. For me it was only a single time that in the ice caves, it wasnt possible to proceed without a bomb. Whatsoever its indeed a great game.

  13. It's pretty similar to Elder Scrolls: Daggerfall dungeon generation, Daggerfall had the issue that the hand-crafted "chunks" did not always come together well, but at the end of the day it was always possible to find a quest objective if you had necessary skills or spells and a lot of patience to transverse them.

  14. one time i ran out of bombs and the hive spawned in the jungle which made it so I was stuck and I couldn't make it to the exit cause their was no opening to drop down.

  15. its becuse each level is generated in sections. also, spelunky dose creat unfair levels every now and then

  16. Yea… except that one time when me and my friend got stuck on a jungle level because we did not have bombs and no mattock. We had to blow up the ground to get to the next layer. Very weird.
    It had to be some sort of glitch.

  17. 0 ;38 which, in some games, spit out levels that are messy, unfocused and full of dead ends – my experience with FTL

  18. Spelunky sins committed by player in background
    1. Grabbed gold statue despite shop keep present
    2. Approached Anubis from above and gets bodied hard
    3. Attacks shopkeeper without weapon.
    4. Didn't ghost gems (jk thats next level stuff he good)
    5. Too reckless in Temple. Almost shot by arrow trap and whomp.

  19. "You will have a clear path you will be able to get through without bombs or ropes"

    What about when Israel Blargh got stuck in the ice caves and had no bombs? Lol

  20. dude just disable the automatic title translations on your videos im sick of seeing titles in portuguese i want everything in english
    YES FUCK MY NATIVE LANGUAGE
    on a serious note, i dont like having titles in one language then the video itself in another

  21. one time in classic spelunky i had a layout where right at the start i had to use a rope
    then a impossible to pass little bunch of arrow traps

  22. I have replaced all the music files in Spelunky with new, high quality game sound tracks. You can find the file here if interested. Just replace the music folder and enjoy! https://www.filehosting.org/file/details/760396/Matthew%20King

  23. Dead Cells does a similar thing, so I'm curious if they have a different system for it or if it's relatively the same

  24. After over 3000 tries and 100 wins I can say I have never ever seen two exact levels. I automatically read patterns of levels and decide the best approach depending on various factors.

  25. The randomly generated game I have the most experience with is Dark Cloud. Every floor of every level is randomly generated upon every entry, and I feel it is rather poorly done. There will be long empty corridors far away from what would generally be considered the main path that lead to a dead end room with only 1 enemy or item, enemies often get placed in these cramped corridors where it's really hard to fight them (which as far as I can tell is an inevitable consequence of the randomness and not a deliberate feature), character-specific barrier will get placed right next to each other, requiring you to switch characters in rapid succession (which again is not a deliberate feature but rather an unintended consequence of the randomness), and there's a few too many long tedious treks back to the exit point once you get the key and/or kill the last enemy because the layouts are abysmal and non-looping. And the randomly generated items and weapons make it very difficult to fulfill the game's primary mechanic- which is to level up your weapons and evolve them into their stronger forms. The weapon mechanics are poorly explained in the game, so it's very easy to not know what you're doing and permanently ruin the stats of a low-spawn rate weapon and waste precious items. And if you do know what you're doing, you'll just be frustrated that the game is so stingy about giving you the items you need. I think the game might know this, which is why I often found myself getting more weapons than I had the capacity to hold if I've been neglecting trips to the storage unit, but that seems to suggest the game wants me to grind all those weapons until they can be converted into synth spheres, and grinding isn't fun. Being denied the exact items you know you need to minimize grinding isn't fun either. The game is basically rife with questionable if not outright bad design decisions. How it's a greatest hits PS2 game is puzzling to me, I consider it a prime example of a game to show an aspiring game designer or otherwise design-minded player just because there's so many intuitively bad design choices to pick up on, features that are obviously "they shouldn't have done that" or "this needed expansion and/or tweaking". The game isn't good as is. I haven't played its sequel, but I hope they learned their lessons.

  26. You did not mention Gosthing (Waiting for the gost on purpose and turn all the jewels in the path of the ghost into diamonds).

  27. Level tips: level 1-1 has nothing important try to find damsel (so you have 5 hp)
    Level 1-2,3 or 4: Might have the ujat eye try to find it (you only have one chance)
    Level 2-1,2 or 3: there is black market (ujat eye will blink when your near)
    Level 3-2 or 3: has the Maui head (not important unless you have ankh)
    Level 3-4: alien space ship (plasma cannon)
    Level 4-1: Anubis (spectre)
    Level 4-2: City of gold Lock (need headjet and spectre)
    Level 4-3: normal (unless you go through lock then city of gold)
    Level 4-4: Olmec

  28. Still playing Spelunky HD in 2019. My favorite game genres are rogue-likes and rogue-lites, but the only other game that even comes close to Spelunky for enjoyment is Streets of Rogue, which you have already done a video on I believe.

    $10 goes a long way these days.

  29. Sometimes the game messes up and you can’t get lower without a bomb buy that’s so rare that it’s actually awesome when it happens

  30. I love rogue-like games and played a lot of them, including some very hardcore, but for Spelunky… I tried to played it a few times, because everyone is agree to say it's awesome, but i don't know why, i can't enjoy it. Everytime i try to play it, i do a few levels, then i get bored and frustated, then i quit the game and just never launch it again. I really wanted to like this game, but idk, maybe it's because of this plateformer gameplay, it's not really what i like. I like other plateformer rogue-like, like the awesome Dead Cells for example, at least in Dead Cells we have a wiiiide variety of options in movement and attacks, but idk, in Spelunky it feels clunky, and the weak attack power of the character make me want to just avoid fights, so i rush to end of the level endlessly. Maybe i'm just doing it wrong :/

Leave a Reply

Your email address will not be published. Required fields are marked *