< Return to Video

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

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

more » « less
Duration:
07:13

English, British subtitles

Revisions