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