{"id":21242,"date":"2013-10-02T10:25:46","date_gmt":"2013-10-02T15:25:46","guid":{"rendered":"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=21242"},"modified":"2015-07-01T04:47:19","modified_gmt":"2015-07-01T09:47:19","slug":"project-good-robot-20-gamespace","status":"publish","type":"post","link":"https:\/\/www.shamusyoung.com\/twentysidedtale\/?p=21242","title":{"rendered":"Project Good Robot 20: Gamespace"},"content":{"rendered":"<p>Good news and bad news: Yesterday we had an impromptu hangout where Josh played the latest build of Good Robot and streamed the game for all to see. It was supposed to be a simple test: I wanted to see Josh play the game to hunt for bugs and gather gameplay feedback. But then I Tweeted a link to the stream and the internet showed up.<\/p>\n<p>Friends joined in and we had a little party where Josh played through all of the available content for Good Robot.  It was funny and fun, although the best part of the show was when Josh got to the end and began using the console to spawn clouds of enemies in an effort to break the game. <\/p>\n<p>The bad news is that <a href=\"http:\/\/www.twitch.tv\/spoilerwarningshow\/profile\/pastBroadcasts\">Twitch.tv didn&#8217;t save the footage<\/a>. We don&#8217;t know why. So the event is gone forever. Sorry.<\/p>\n<p>The crowd feedback was invaluable, and Josh&#8217;s skill at finding bugs was&#8230; irritating. (But also valuable.) <\/p>\n<p>I&#8217;m kind of surprised at how many people are interested in modding or changing the game. It&#8217;s already pretty mod-able. I mean, this is the level data for level 9:<\/p>\n<p><!--more--><\/p>\n<pre lang=\"ini\" line=\"1\">\r\n[Map9]\r\nTitle=Chapter Five\r\nSubtitle=The Robot Factory\r\nStoryPoints=29 30 31\r\nWallColor=000\r\nLightColor=169\r\nBacklightColor=024\r\nMusicTrack=jc_bad_robot.ogg\r\nCoins=960\r\nTileset=4\r\nStars=0\r\nScreens=16\r\nSwarmSize=15\r\nPatterns=grid shafts grid\r\nRobotSwarm=cutter1 cutter2 bomber1 shooter1 launcher1\r\nRobotMooks=cutter2 shooter2 sniper1 launcher2\r\nRobotNormal=cutter3 launcher2 sniper2\r\nRobotBadass=sniper3 bomber2 launcher3\r\n<\/pre>\n<p>The robots are similarly defined by setting variables in text files. The artwork for all robots and items comes from a single PNG file. I did this for convenience during development, but since people are so eager to mess with it I might spend a little extra time to expose a few more systems and variables to modders. <\/p>\n<p>Anyway.  Let&#8217;s talk about gamespace.<\/p>\n<p>It&#8217;s really odd that we&#8217;re all the way up to entry 20 and I still haven&#8217;t talked about where the levels come from or how they&#8217;re generated.  (Actually 19, since there was no 15.) But all of my past projects were focused almost entirely on generating gamespace, and I guess I was itching to talk about some other stuff.  Well, we&#8217;ve done that.  So let&#8217;s talk level generation.<\/p>\n<p>This is the most primitive level generation I&#8217;ve done in any of these projects. Working in 2D is like that. <\/p>\n<p>So the gameworld is divided into a grid of regions. For some idiotic reason I named these things &#8220;screens&#8221;. You can see this in the level info above on line 12 where it says &#8220;Screens=16&#8221;. I think &#8220;pages&#8221; would have been a better name, but I&#8217;m not sure it&#8217;s worth re-naming them now. (The name is dumb, but is it confusing enough to be a bother? Meh.) At a high level, the game world looks like this:<\/p>\n<p><table width='600'  cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/gr20_level1.jpg' class='insetimage' width='600' alt='Playtester: &#8220;How do I open the mini-map?&#8221;  Shamus: &#8220;Just re-compile the project in debug mode, open the console, turn off collision, and then increase the camera distance to a huge number.&#8221; Playtester: &#8220;I don&#8217;t have the source!&#8221; Shamus: &#8220;The challenge is half the fun!&#8221;' title='Playtester: &#8220;How do I open the mini-map?&#8221;  Shamus: &#8220;Just re-compile the project in debug mode, open the console, turn off collision, and then increase the camera distance to a huge number.&#8221; Playtester: &#8220;I don&#8217;t have the source!&#8221; Shamus: &#8220;The challenge is half the fun!&#8221;'\/><\/td><\/tr><\/table><\/p>\n<p>This is one of the early-game levels. Here is the same area, but some hack has drawn lines to roughly show the screen boundaries:<\/p>\n<p><table width='600'  cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/gr20_level2.jpg' class='insetimage' width='600' alt='This is more enjoyable if you look at it while listening to &#8220;The Grid&#8221; by Daft Punk. But that&#8217;s sort of true of everything.' title='This is more enjoyable if you look at it while listening to &#8220;The Grid&#8221; by Daft Punk. But that&#8217;s sort of true of everything.'\/><\/td><\/tr><\/table><\/p>\n<p>The first star marks the level entry, and the second star marks an open arena suitable for a boss fight. Everything between those two probably represents about 5 minutes of game space. Here is a similar view of a place somewhere around mid-game:<\/p>\n<p><table width='600'  cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/gr20_level3.jpg' class='insetimage' width='600' alt='It&#8217;s more confusing than it looks, once you&#8217;re zoomed all the way in to gameplay-distance.' title='It&#8217;s more confusing than it looks, once you&#8217;re zoomed all the way in to gameplay-distance.'\/><\/td><\/tr><\/table><\/p>\n<p>There are a number of different patterns we use for generating individual screens. (Now that I&#8217;m writing about it, the name &#8220;screens&#8221; is starting to annoy me more. Nothing will reveal bad design better than trying to explain the design to someone else.) Some patterns just cut straight-edged shafts.  Others use <a href=\"?p=15777\" title=\"Project Octant Part 4: The Beautiful Noise\">value noise<\/a> to generate tunnels. <\/p>\n<p>I&#8217;ve found that a little complexity goes a long way. Just a couple of side-tunnels or an occasional cul-de-sac is all it takes to make the world feel like a baffling maze. I keep the tunnels linear in the early game and then gradually introduce the more complex ones as the game progresses. <\/p>\n<p>The trick with using noise is that there aren&#8217;t any guarantees. If I make a pattern that uses value noise to fill in the the screen with solid mass at the bottom and gradually becoming more porous towards the top, then that might make something like this:<\/p>\n<p><table width='512'  cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/gr20_map1.jpg' class='insetimage' width='512' alt='gr20_map1.jpg' title='gr20_map1.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>But what if we get some unlucky rolls and it generates the following?<\/p>\n<p><table width='512'  cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/gr20_map2.jpg' class='insetimage' width='512' alt='gr20_map2.jpg' title='gr20_map2.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>That&#8217;s bad.  You can&#8217;t get from the left side of the screen to the right side, which means the player would be walled off.  Even if 99% of the generated screens are fine, the player is going to pass through hundreds of screens throughout the course of the game. The odds of them hitting a bad screen are actually pretty good. Worse, we don&#8217;t automatically know if the screen is passable or not. <\/p>\n<p>Now, you might suggest using the Minecraft solution and letting the player solve the problem by blasting through walls.  The problem with that solution is this:<\/p>\n<p><table width=''  cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/gr20_grass.jpg' class='insetimage' width='' alt='I&#8217;m imagining these two spiders are teaming up so they can roll their eyes at me.' title='I&#8217;m imagining these two spiders are teaming up so they can roll their eyes at me.'\/><\/td><\/tr><\/table><\/p>\n<p>Levels are covered in shaggy grass, drooping vines, piled snow, hanging icicles, stalactites and stalagmites. If I blow away a chunk of ground, it would be goofy to have it reveal more grass or for a fresh batch of hanging vines to appear to replace the old. I am not eager to mess with that.  Right now it assembles tiles from a few base shapes, flipping them as needed and juggling several different alternate versions of each one so the user doesn&#8217;t see the repetition or mirroring. I have base tiles and alternate tiles that are used to assemble the final tiles. Allowing the user to tunnel would require <em>alternate<\/em> alternate tiles and base tiles. The map system would need to keep track of what bits were made of which materials, and the different tiles would need to seamlessly blend. <\/p>\n<p>It would be double the artwork and more than double the coding complexity. I wouldn&#8217;t mind, but I strongly suspect that tunneling through solid rock isn&#8217;t the most fun activity in the world. I say this as a die-hard Minecraft fan. Unless I&#8217;m going to embed gold ore, diamonds, and hidden caverns in the walls, tunneling is just busywork. And the player could end up doing a lot of it. <\/p>\n<p>Going back to our unfortunate screen:<\/p>\n<p><table width='512'  cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/gr20_map3.jpg' class='insetimage' width='512' alt='gr20_map3.jpg' title='gr20_map3.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>What if the player misunderstands and begins tunneling in the wrong spot? They could end up hacking through a lot of solid mass, wondering where the rest of this videogame is.  I suppose I could embed blocks of XP in the wall, but that might signal to players that this is a game about digging and they&#8217;ll spend hours hacking away at solid mass. This would kill the flow of the game and turn it into a horrible boring <a href=\"http:\/\/www.terraria.org\/index2.html\">Terraria<\/a> riff.<\/p>\n<p>I&#8217;m wary of any course of action that&#8217;s going to double my workload while at the same time running completely counter to the core of the game. I love mining games, and maybe there&#8217;s another sandbox game that could be made with this, but for now I think it&#8217;s best to just solve this walling-off problem for the user. <\/p>\n<p>My solution is about the most brute-force method you can come up with.  I do a flood fill on one edge:<\/p>\n<p><table width='512'  cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/gr20_map4.jpg' class='insetimage' width='512' alt='gr20_map4.jpg' title='gr20_map4.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>If the flood doesn&#8217;t reach other opposite edge it enters panic mode and solves the problem with a sledgehammer:<\/p>\n<p><table width='512'  cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/gr20_map5.jpg' class='insetimage' width='512' alt='gr20_map5.jpg' title='gr20_map5.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>It just obliterates a horizontal block of points to make a shaft. Harmless, really. To the user it probably won&#8217;t even look at all that out-of-place.  It would just be a single section that was a little less confusing than the previous bit. <\/p>\n<p>Once the walls are done, it passes over the screen and looks for places that are touched by the floodfill that are also dead-ends. (Surrounded on three sides.) It puts robot spawners there.<\/p>\n<p>When placing enemies, it basically acts like a tabletop GM. Referring back to our level file:<\/p>\n<pre lang=\"ini\" line=\"13\">\r\nSwarmSize=15\r\nPatterns=grid shafts grid\r\nRobotSwarm=cutter1 cutter2 bomber1 shooter1 launcher1\r\nRobotMooks=cutter2 shooter2 sniper1 launcher2\r\nRobotNormal=cutter3 launcher2 sniper2\r\nRobotBadass=sniper3 bomber2 launcher3\r\n<\/pre>\n<p>These lines tell us what bots should be used in what situation.  It then chooses from a list of predetermined encounter types.  Some examples:<\/p>\n<p>1) A swarm of the lowest class of robot. (Line 13 tells us the size of the largest possible swarm on this level. It spawns between n and <sup>n<\/sup>\/<sub>2<\/sub> in a swarm.)<br \/>\n2) A medium-sized group of mooks and a couple of normal bots.<br \/>\n3) A couple of normal bots and one badass.<br \/>\n4) A swarm and a badass.<br \/>\n5) You get the idea.<\/p>\n<p>Then it drops the robots down on the spawn points we worked out above. <\/p>\n<p>It&#8217;s a pretty simple system, but it yields varied and interesting results. <\/p>\n<p>I&#8217;m seriously considering renaming screens now. That means renaming the dang file, too, since the class is in screen.cpp. Grrr. This is actually something I did back on day 2 of the project, long before I was sure I was going anywhere with it. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Good news and bad news: Yesterday we had an impromptu hangout where Josh played the latest build of Good Robot and streamed the game for all to see. It was supposed to be a simple test: I wanted to see Josh play the game to hunt for bugs and gather gameplay feedback. But then I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[498],"tags":[],"class_list":["post-21242","post","type-post","status-publish","format-standard","hentry","category-good-robot"],"_links":{"self":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/21242","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=21242"}],"version-history":[{"count":0,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/21242\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=21242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=21242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=21242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}