-
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