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