<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>jverkamp.com</title>
	<atom:link href="http://blog.jverkamp.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jverkamp.com</link>
	<description></description>
	<lastBuildDate>Fri, 24 May 2013 13:00:54 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Racket Roguelike &#8212; Going on hiatus</title>
		<link>http://blog.jverkamp.com/2013/05/24/racket-roguelike-going-on-hiatus/</link>
		<comments>http://blog.jverkamp.com/2013/05/24/racket-roguelike-going-on-hiatus/#comments</comments>
		<pubDate>Fri, 24 May 2013 13:00:54 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Racket Roguelike]]></category>
		<category><![CDATA[Racket]]></category>
		<category><![CDATA[Roguelike]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.jverkamp.com/?p=4469</guid>
		<description><![CDATA[It&#8217;s hard to believe that it&#8217;s already been almost two months since I first started this series. In that time, it&#8217;s grown and changed rather a lot. The very first week, all we had was a single @ moving about on the screen: A week later and we already have caves, with nice pools and underground trees (that&#8217;s never really made that much sense, has it?): In week 3, the caves get quite a bit more dangerous with the introduction of rats, rats, everywhere: Unfortunately (or perhaps not), a rat without an AI isn&#8217;t much of a threat at all. So after that, we started work on making the enemies a bit starter and added a few more dangerous sorts: In week 5, we shifted gears to get into gear, adding weapons, armors, and potions (oh my!): Then in week 6, we brave the depths, finally getting away from those &#8230; <a href="http://blog.jverkamp.com/2013/05/24/racket-roguelike-going-on-hiatus/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>It&#8217;s hard to believe that it&#8217;s already been almost two months since I first started this series. In that time, it&#8217;s grown and changed rather a lot.<span id="more-4469"></span></p>
<p>The very <a title="Racket Roguelike 1: A GUI, screens, I/O, and you!" href="http://blog.jverkamp.com/2013/04/04/racket-roguelike-1-a-gui-screens-io-and-you/">first week</a>, all we had was a single <code>@</code> moving about on the screen:</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/04/runaway.png" rel="lightbox[4469]"><img class="alignnone size-full wp-image-4232" alt="" src="http://blog.jverkamp.com/wp-content/uploads/2013/04/runaway.png" width="300" height="192" /></a></p>
<p><a title="Racket Roguelike 2: Infinite caves!" href="http://blog.jverkamp.com/2013/04/11/racket-roguelike-2-infinite-caves/">A week later</a> and we already have caves, with nice pools and underground trees (that&#8217;s never really made that much sense, has it?):</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/04/water-and-trees.png" rel="lightbox[4469]"><img class="alignnone wp-image-4284" alt="" src="http://blog.jverkamp.com/wp-content/uploads/2013/04/water-and-trees.png" width="300" height="187" /></a></p>
<p>In <a title="Racket Roguelike 3: Rats, rats, everywhere!" href="http://blog.jverkamp.com/2013/04/18/racket-roguelike-3-rats-rats-everywhere/">week 3</a>, the caves get quite a bit more dangerous with the introduction of rats, rats, everywhere:</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/04/3-attack.png" rel="lightbox[4469]"><img class="alignnone size-full wp-image-4317" alt="" src="http://blog.jverkamp.com/wp-content/uploads/2013/04/3-attack.png" width="300" height="187" /></a></p>
<p>Unfortunately (or perhaps not), a rat without an AI isn&#8217;t much of a threat at all. So <a title="Racket Roguelike 4: Slightly smarter critters!" href="http://blog.jverkamp.com/2013/04/25/racket-roguelike-4-slightly-smarter-critters/">after that</a>, we started work on making the enemies a bit starter and added a few more dangerous sorts:</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/04/7-incoming.png" rel="lightbox[4469]"><img class="wp-image-4355" alt="" src="http://blog.jverkamp.com/wp-content/uploads/2013/04/7-incoming.png" width="300" height="187" /></a></p>
<p>In <a title="Racket Roguelike 5: Armors and weapons and potions, oh my!" href="http://blog.jverkamp.com/2013/05/02/racket-roguelike-5-armors-and-weapons-and-potions-oh-my/">week 5</a>, we shifted gears to get into gear, adding weapons, armors, and potions (oh my!):</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/ooh-shiny.png" rel="lightbox[4469]"><img class="alignnone wp-image-4377" alt="" src="http://blog.jverkamp.com/wp-content/uploads/2013/05/ooh-shiny.png" width="300" height="188" /></a></p>
<p>Then in <a title="Racket Roguelike 6: Dig deeper!" href="http://blog.jverkamp.com/2013/05/10/racket-roguelike-6-dig-deeper/">week 6</a>, we brave the depths, finally getting away from those infinite caves and starting out on the surface. Granted, we went right back down, but still. Onward and downward!</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/2-going-down.png" rel="lightbox[4469]"><img class="alignnone wp-image-4409" alt="" src="http://blog.jverkamp.com/wp-content/uploads/2013/05/2-going-down.png" width="300" height="187" /></a></p>
<p>Finally, <a title="Racket Roguelike 7: Into darkness!" href="http://blog.jverkamp.com/2013/05/17/racket-roguelike-7-into-darkness/">last week</a> we managed to rid our player of that pesky x-ray vision:</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/no-more-xray-vision.png" rel="lightbox[4469]"><img class="wp-image-4449" alt="" src="http://blog.jverkamp.com/wp-content/uploads/2013/05/no-more-xray-vision.png" width="300" height="180" /></a></p>
<p>It&#8217;s been a long strange road already, but where does that leave us now?</p>
<p>Well, there are a few things that I&#8217;d definitely like to implement before moving on:</p>
<ul>
<li>Ranged weapons</li>
<li><span style="line-height: 15px;">Animations decoupled from player movement (to allow for arrows, fire, explosions, etc)</span></li>
<li>Terrain modification (in particular: burrowing for monsters and/or players)</li>
<li>More content! (levels, entities, and items; each is just waiting for more definitions)</li>
</ul>
<p>I&#8217;ve already started on the first two of those. Granted, as a wise man once (may or may not have) said:</p>
<blockquote><p>I have not failed 1,000 times. I have successfully discovered 1,000 ways to NOT make a light bulb.</p></blockquote>
<p>I will figure it out, it&#8217;s just taking longer than I&#8217;d like. Unfortunately<sup><a href="http://blog.jverkamp.com/2013/05/24/racket-roguelike-going-on-hiatus/#footnote_0_4469" id="identifier_0_4469" class="footnote-link footnote-identifier-link" title="Or really not.  ">1</a></sup>, all that&#8217;s going to have to wait. It turns out I&#8217;m getting married in a week<sup><a href="http://blog.jverkamp.com/2013/05/24/racket-roguelike-going-on-hiatus/#footnote_1_4469" id="identifier_1_4469" class="footnote-link footnote-identifier-link" title="It&rsquo;s amazing how something like that can sneak up on you&hellip;">2</a></sup>. Believe it or not, that takes up rather a lot of time. After that, I&#8217;ll be taking a bit of a vacation from the mad, mad world of academia for a couple of weeks. My intention is to avoid the Internet as much as possible. We&#8217;ll see how that goes.</p>
<p>The takeaway from all of this? This series isn&#8217;t over. If anything, it&#8217;s only going to get a lot deeper in the next few posts&#8211;sometime in the third week of June. I hope to see you then!</p>
<ol class="footnotes"><li id="footnote_0_4469" class="footnote">Or really not. <img src='http://blog.jverkamp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li><li id="footnote_1_4469" class="footnote">It&#8217;s amazing how something like that can sneak up on you&#8230;</li></ol>]]></content:encoded>
			<wfw:commentRss>http://blog.jverkamp.com/2013/05/24/racket-roguelike-going-on-hiatus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ludum Dare 26 &#8212; VTanks &#8212; Results</title>
		<link>http://blog.jverkamp.com/2013/05/20/ludum-dare-26-vtanks-results/</link>
		<comments>http://blog.jverkamp.com/2013/05/20/ludum-dare-26-vtanks-results/#comments</comments>
		<pubDate>Tue, 21 May 2013 03:55:28 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[Ludum Dare]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[FlashDevelop]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[Haxe]]></category>
		<category><![CDATA[Tanks]]></category>
		<category><![CDATA[Vector]]></category>

		<guid isPermaLink="false">http://blog.jverkamp.com/?p=4459</guid>
		<description><![CDATA[The voting period for Ludum Dare 26 has ended, which means that now we have some results! Before I post my own, take a moment to check out the overall leaders. Given that there were 2346 games submitted (1610 in the compo and 736 in the jam), there are bound to be some real gems in there. Top 100 overall: Compo, Jam Top 25 by categories And then here are my game&#8217;s (VTanks) ratings: Place (of 736) Percentile Category Average score (of 5) #352 52% Theme (Jam) 3.07 #374 49% Humor (Jam) 1.71 #423 43% Fun (Jam) 2.44 #458 38% Audio (Jam) 1.39 #502 32% Mood (Jam) 1.96 #532 28% Graphics (Jam) 2.02 #546 26% Innovation (Jam) 1.68 #509 31% Overall (Jam) 2.42 Overall, I know that I can do better. But given that I only had about 6 hours to spend, I don&#8217;t think I did half bad. I&#8217;m a bit amused that &#8230; <a href="http://blog.jverkamp.com/2013/05/20/ludum-dare-26-vtanks-results/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>The voting period for Ludum Dare 26 has ended, which means that now we have <a title="Ludum Dare 26 Results" href="http://www.ludumdare.com/compo/2013/05/20/ludum-dare-26-results/">some results</a>! Before I post my own, take a moment to check out the overall leaders. Given that there were <em>2346</em> games submitted (1610 in the compo and 736 in the jam), there are bound to be some real gems in there.<span id="more-4459"></span></p>
<ul>
<li>Top 100 overall: <a href="http://www.ludumdare.com/compo/ludum-dare-26/?action=top&amp;cat=Overall">Compo</a>, <a href="http://www.ludumdare.com/compo/ludum-dare-26/?action=top&amp;cat=Overall(Jam)">Jam</a></li>
<li><a href="http://www.ludumdare.com/compo/ludum-dare-26/?more=1">Top 25 by categories</a></li>
</ul>
<p>And then here are my game&#8217;s (<a title="VTanks for Ludum Dare 26" href="http://blog.jverkamp.com/2013/04/29/vtanks-for-ludum-dare-26/">VTanks</a>) ratings:</p>
<table cellpadding="5">
<thead>
<tr>
<td align="center"><strong>Place (of 736)</strong></td>
<td align="center"><strong>Percentile</strong></td>
<td><strong>Category</strong></td>
<td align="right"><strong>Average score (of 5)</strong></td>
</tr>
</thead>
<tbody>
<tr>
<td align="center">#352</td>
<td align="center">52%</td>
<td>Theme (Jam)</td>
<td align="right">3.07</td>
</tr>
<tr>
<td align="center">#374</td>
<td align="center">49%</td>
<td>Humor (Jam)</td>
<td align="right">1.71</td>
</tr>
<tr>
<td align="center">#423</td>
<td align="center">43%</td>
<td>Fun (Jam)</td>
<td align="right">2.44</td>
</tr>
<tr>
<td align="center">#458</td>
<td align="center">38%</td>
<td>Audio (Jam)</td>
<td align="right">1.39</td>
</tr>
<tr>
<td align="center">#502</td>
<td align="center">32%</td>
<td>Mood (Jam)</td>
<td align="right">1.96</td>
</tr>
<tr>
<td align="center">#532</td>
<td align="center">28%</td>
<td>Graphics (Jam)</td>
<td align="right">2.02</td>
</tr>
<tr>
<td align="center">#546</td>
<td align="center">26%</td>
<td>Innovation (Jam)</td>
<td align="right">1.68</td>
</tr>
</tbody>
<tfoot>
<tr>
<td align="center"><em>#509</em></td>
<td align="center"><em>31%</em></td>
<td><em>Overall (Jam)</em></td>
<td align="right"><em>2.42</em></td>
</tr>
</tfoot>
</table>
<p>Overall, I know that I can do better. But given that I only had about 6 hours to spend, I don&#8217;t think I did half bad. I&#8217;m a bit amused that I somehow managed to place better than about half the entries on humor&#8230; given that there was no humor to speak of in the game. I guess getting yourself buried is funny?</p>
<p>Even weirder is audio. I came in at 38% audio&#8230; and I didn&#8217;t have any. I&#8217;m pretty sure that the policy is just not to leave a score in a category if it doesn&#8217;t make sense, in which case I wouldn&#8217;t get a rating. So yeah&#8230; That&#8217;s strange.</p>
<p>All that being said, it was a lot of fun to participate in Ludum Dare for once. After that, it was just about as much fun to play some of the games. It&#8217;s <em>amazing</em> what some people put out in 24 hours. I&#8217;ll have to do this again!</p>
<p>(If you&#8217;d like to play my entry, you can do so <a title="VTanks for Ludum Dare 26" href="http://blog.jverkamp.com/2013/04/29/vtanks-for-ludum-dare-26/">here</a>.)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jverkamp.com/2013/05/20/ludum-dare-26-vtanks-results/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Star Trek Into Darkness</title>
		<link>http://blog.jverkamp.com/2013/05/19/star-trek-into-darkness/</link>
		<comments>http://blog.jverkamp.com/2013/05/19/star-trek-into-darkness/#comments</comments>
		<pubDate>Mon, 20 May 2013 03:55:30 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[Movies]]></category>
		<category><![CDATA[Other]]></category>

		<guid isPermaLink="false">http://blog.jverkamp.com/?p=4461</guid>
		<description><![CDATA[A few years ago, I decided that I was doing myself a disservice as a self-identified geek1: of Star Trek, I&#8217;d only seen Voyager and a few of the movies. Of course I had to remedy that fact. Over the course of a summer, I watched it all2. 10 movies. 3 seasons of The Original Series; 7 seasons each of The Next Generation, Deep Space Nine, and Voyager3; and finally the 4 seasons of Enterprise. Yet, I still don&#8217;t consider myself a Trekkie (or a Trekker). I guess my entire point is that I do have at least a bit of a leg to stand on when talking about the new Star Trek movies. That being said, feel free to ignore me. Everyone has their own opinion and I&#8217;ve certainly seen the entire spectrum when it comes to this movie&#8230; Overall, I really liked it. On the negative side, the &#8230; <a href="http://blog.jverkamp.com/2013/05/19/star-trek-into-darkness/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/Star-Trek-Into-Darkness.jpg" rel="lightbox[4461]"><img class="alignright size-full wp-image-4462" alt="" src="http://blog.jverkamp.com/wp-content/uploads/2013/05/Star-Trek-Into-Darkness.jpg" width="214" height="317" /></a></p>
<p>A few years ago, I decided that I was doing myself a disservice as a self-identified geek<sup><a href="http://blog.jverkamp.com/2013/05/19/star-trek-into-darkness/#footnote_0_4461" id="identifier_0_4461" class="footnote-link footnote-identifier-link" title="Is there any other kind?">1</a></sup>: of Star Trek, I&#8217;d only seen Voyager and a few of the movies. Of course I had to remedy that fact. <img src='http://blog.jverkamp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Over the course of a summer, I watched it all<sup><a href="http://blog.jverkamp.com/2013/05/19/star-trek-into-darkness/#footnote_1_4461" id="identifier_1_4461" class="footnote-link footnote-identifier-link" title="Yes, in order">2</a></sup>. 10 movies. 3 seasons of <a title="Star Trek: The Original Series" href="https://en.wikipedia.org/wiki/Star_Trek:_The_Original_Series">The Original Series</a>; 7 seasons each of <a title="Star Trek: The Next Generation episode list" href="https://en.wikipedia.org/wiki/List_of_Star_Trek:_The_Next_Generation_episodes">The Next Generation</a>, <a title="Star Trek: Deep Space Nine episode list" href="https://en.wikipedia.org/wiki/List_of_Star_Trek:_Deep_Space_Nine_episodes">Deep Space Nine</a>, and <a title="Star Trek: Voyager episode list" href="https://en.wikipedia.org/wiki/List_of_Star_Trek:_Voyager_episodes">Voyager</a><sup><a href="http://blog.jverkamp.com/2013/05/19/star-trek-into-darkness/#footnote_2_4461" id="identifier_2_4461" class="footnote-link footnote-identifier-link" title="Still my favorite. Feel free to tell me how I&rsquo;m wrong&nbsp;right in the comments">3</a></sup>; and finally the 4 seasons of <a title="Star Trek Enterprise" href="https://en.wikipedia.org/wiki/Star_Trek:_Enterprise">Enterprise</a>. Yet, I still don&#8217;t consider myself a Trekkie (<a title="Trekkie vs Trekker debate on Wikipedia" href="https://en.wikipedia.org/wiki/Trekie#Trekkie_vs._Trekker">or a Trekker</a>).</p>
<p>I guess my entire point is that I do have at least a bit of a leg to stand on when talking about the new Star Trek movies. That being said, feel free to ignore me. <img src='http://blog.jverkamp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Everyone has their own opinion and I&#8217;ve certainly seen the entire spectrum when it comes to this movie&#8230;<span id="more-4461"></span></p>
<p>Overall, I really liked it.</p>
<p>On the negative side, the pacing was pretty bad at times, with long slow stretches that just didn&#8217;t feel like they needed to be there<sup><a href="http://blog.jverkamp.com/2013/05/19/star-trek-into-darkness/#footnote_3_4461" id="identifier_3_4461" class="footnote-link footnote-identifier-link" title="Although it was a later showing than I generally go, so that might have played a role">4</a></sup>. There were a few scenes that just seemed so strange, particularly <a itemprop="url" href="http://www.imdb.com/name/nm1404408/?ref_=tt_cl_t11">Alice Eve&#8217;s</a> underwear scene<sup><a href="http://blog.jverkamp.com/2013/05/19/star-trek-into-darkness/#footnote_4_4461" id="identifier_4_4461" class="footnote-link footnote-identifier-link" title="Which even&nbsp;Damon Lindelof has said was &ldquo;gratuitous&rdquo;">5</a></sup>. Still, the action scenes were nicely &#8220;actiony&#8221; and the scenery looked amazing, both the shine of the ship and the destruction of the later acts.</p>
<p>As many people the internet over have said, there were more than a few <em>&#8216;huh&#8217;</em> moments that really fought against my suspension of disbelief. Without getting too spoilery: Isn&#8217;t saving the natives in the first place a violation of the <a title="Prime Directive" href="https://en.wikipedia.org/wiki/Prime_directive">Prime Directive</a>? Other than looking cool, why didn&#8217;t they just wait in space? Later on, why did they go to Kronos in the first place? And why did it only take them about 30 seconds to get back? And for that matter, where was the rest of Starfleet when they did get back? Does the doctor make a habit of randomly injecting things? And why <em>his</em> blood specifically, not his crew&#8217;s? &#8230; Yeah. I&#8217;m done. It&#8217;s a good thing I don&#8217;t really think of myself as a Trekkie or a lot of that would drive me even more up the wall. <img src='http://blog.jverkamp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>You know what my biggest nit to pick with the movie was though? J.J. Abrams&#8217; marketing. Everyone who knew Trek knew <em>exactly</em> who <a itemprop="url" href="http://www.imdb.com/name/nm1212722/?ref_=tt_cl_t7">Cumberbatch</a> was playing no matter how hard they tried to deny it&#8230; The only people who wouldn&#8217;t know wouldn&#8217;t care. Sigh.</p>
<p>Like I said though, for a summer action flick, it was a rather enjoyable movie. Barring the aforementioned marketing, there were a few neat twists. There were more than a handful of callbacks to <a href="http://www.imdb.com/title/tt0084726/?ref_=fn_al_tt_2">The Wrath of Khan</a>, which was nice at first, although it a bit old by the end<sup><a href="http://blog.jverkamp.com/2013/05/19/star-trek-into-darkness/#footnote_5_4461" id="identifier_5_4461" class="footnote-link footnote-identifier-link" title="The inverted Kirk/Spock yell was particularly weird&hellip;">6</a></sup>. The action was nice and the characters are actually starting to finally feel like a crew now. <a itemprop="url" href="http://www.imdb.com/name/nm0704270/?ref_=tt_cl_t2">Zachary Quinto</a>, <a itemprop="url" href="http://www.imdb.com/name/nm0881631/?ref_=tt_cl_t4">Karl Urban</a>, and <a itemprop="url" href="http://www.imdb.com/name/nm0670408/?ref_=tt_cl_t5">Simon Pegg</a> all carried over strong performances from the first film. I can&#8217;t really get into <a itemprop="url" href="http://www.imdb.com/name/nm1517976/?ref_=tt_cl_t1">Chris Pine</a> as Kirk, but then again I never really liked the original Kirk either. But really? <a itemprop="url" href="http://www.imdb.com/name/nm1212722/?ref_=tt_cl_t7">Benedict Cumberbatch</a> carried the show. <a href="http://www.imdb.com/title/tt1475582/">Sherlock</a> just jumped up rather a few places up my TV queue<sup><a href="http://blog.jverkamp.com/2013/05/19/star-trek-into-darkness/#footnote_6_4461" id="identifier_6_4461" class="footnote-link footnote-identifier-link" title="Also, did you know he was in&nbsp;The Hobbit&nbsp;as the&nbsp;Necromancer? The more you know!">7</a></sup>.</p>
<p>Despite my earlier grumbling, I really did enjoy the movie. It&#8217;s not quite up to <a title="Iron Man 3" href="http://blog.jverkamp.com/2013/05/05/iron-man-3/">Iron Man&#8217;s </a>standards and I still think <a title="The Croods" href="http://blog.jverkamp.com/2013/04/08/the-croods/">The Croods</a> was more fun, but I have no problem putting it into the #3 spot. If you have the time, I&#8217;d say it&#8217;s worth seeing.</p>
<p><a title="2013 Movie Rankings" href="http://blog.jverkamp.com/lists/2013-movie-rankings/"><strong>My 2013 Movie Rankings</strong></a></p>
<ol>
<li><a title="Iron Man 3" href="http://blog.jverkamp.com/2013/05/05/iron-man-3/">Iron Man 3</a></li>
<li><a title="The Croods" href="http://blog.jverkamp.com/2013/04/08/the-croods/">The Croods</a></li>
<li><a title="Star Trek Into Darkness" href="http://blog.jverkamp.com/2013/05/19/star-trek-into-darkness/">Star Trek Into Darkness</a></li>
<li><a title="Django Unchained" href="http://blog.jverkamp.com/2013/01/22/django-unchained/">Django Unchained</a></li>
<li><a title="Parental Guidance" href="http://blog.jverkamp.com/2013/01/27/parental-guidance/">Parental Guidance</a></li>
<li><a title="Oblivion" href="http://blog.jverkamp.com/2013/04/24/oblivion/">Oblivion</a></li>
<li><a title="Beautiful Creatures" href="http://blog.jverkamp.com/2013/02/17/beautiful-creatures/">Beautiful Creatures</a></li>
<li><a title="Jurassic Park (3D!)" href="http://blog.jverkamp.com/2013/05/01/jurassic-park-3d/">Jurassic Park (3D!)</a></li>
<li><a title="Oz the Great and Powerful" href="http://blog.jverkamp.com/2013/03/10/oz-the-great-and-powerful/">Oz the Great and Powerful</a></li>
<li><a title="Hansel &amp; Gretel: Witch Hunters" href="http://blog.jverkamp.com/2013/02/13/hansel-gretel-witch-hunters/">Hansel &amp; Gretel: Witch Hunters</a></li>
<li><a title="Jack the Giant Slayer" href="http://blog.jverkamp.com/2013/03/12/jack-the-giant-slayer/">Jack the Giant Slayer</a></li>
<li><a title="Warm Bodies" href="http://blog.jverkamp.com/2013/02/26/warm-bodies/">Warm Bodies</a></li>
<li><a title="G.I. Joe: Retaliation" href="http://blog.jverkamp.com/2013/04/03/g-i-joe-retaliation/">G.I. Joe: Retaliation</a></li>
<li><a title="Pain &amp; Gain" href="http://blog.jverkamp.com/2013/05/16/pain-gain/">Pain &amp; Gain</a></li>
</ol>
<ol class="footnotes"><li id="footnote_0_4461" class="footnote">Is there any other kind?</li><li id="footnote_1_4461" class="footnote">Yes, in order</li><li id="footnote_2_4461" class="footnote">Still my favorite. Feel free to tell me how I&#8217;m <del>wrong</del> right in the comments</li><li id="footnote_3_4461" class="footnote">Although it was a later showing than I generally go, so that might have played a role</li><li id="footnote_4_4461" class="footnote">Which even Damon Lindelof <a href="http://io9.com/damon-lindelof-admits-the-star-trek-nudity-was-gratuit-508967420">has said</a> was &#8220;gratuitous&#8221;</li><li id="footnote_5_4461" class="footnote">The inverted Kirk/Spock yell was particularly weird&#8230;</li><li id="footnote_6_4461" class="footnote">Also, did you know he was in <a href="http://www.imdb.com/title/tt0903624/">The Hobbit</a> as the <a href="http://www.imdb.com/character/ch0000156">Necromancer</a>? The more you know!</li></ol>]]></content:encoded>
			<wfw:commentRss>http://blog.jverkamp.com/2013/05/19/star-trek-into-darkness/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Firefox vs Chrome</title>
		<link>http://blog.jverkamp.com/2013/05/18/firefox-vs-chrome/</link>
		<comments>http://blog.jverkamp.com/2013/05/18/firefox-vs-chrome/#comments</comments>
		<pubDate>Sat, 18 May 2013 13:00:49 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[Other]]></category>

		<guid isPermaLink="false">http://blog.jverkamp.com/?p=4424</guid>
		<description><![CDATA[Deciding which browser to use has been a bit of a challenge for me. Many years ago, I was something of an Opera fan, but when Firefox rose to dominance, I moved on and never really looked back. For a while after the release of Chrome, I resisted the change, but eventually Chrome&#8217;s rolling release cycle and just sheer speed convinced me to switch. More recently (about two weeks ago), I&#8217;ve tried switching back to Firefox. Here&#8217;s what I found: Firefox Chrome Pros * Completely Open Source Zotero integration is much better Better multiple profile support More &#8216;under the hood&#8217; options accessible * Faster to start Integration with Google accounts Better syncing with iOS Single process per tab 1 * Just feels faster, particularly in JavaScript heavy pages Cons * Formatting issues, particularly with Google Docs, Gawker media sites 2, and WordPress Extensions seem to come to Chrome first now Video acceleration doesn&#8217;t work &#8230; <a href="http://blog.jverkamp.com/2013/05/18/firefox-vs-chrome/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Deciding which browser to use has been a bit of a challenge for me. Many years ago, I was something of an Opera fan, but when Firefox rose to dominance, I moved on and never really looked back. For a while after the release of Chrome, I resisted the change, but eventually Chrome&#8217;s rolling release cycle and just sheer speed convinced me to switch. More recently (about two weeks ago), I&#8217;ve tried switching back to Firefox. Here&#8217;s what I found:<span id="more-4424"></span></p>
<table style="width: 100%;">
<thead>
<tr>
<td style="width: 10%;"></td>
<td style="width: 45%; text-align: center;"><strong>Firefox</strong></td>
<td style="width: 45%; text-align: center;"><strong>Chrome</strong></td>
</tr>
</thead>
<tbody>
<tr>
<td style="vertical-align: top;"><strong>Pros</strong></td>
<td style="vertical-align: top;">
<ul>
<li><strong>* </strong>Completely <a title="Open Source Software" href="https://en.wikipedia.org/wiki/Open_source">Open Source</a></li>
<li><a title="Zotero" href="https://www.zotero.org/">Zotero</a> integration is much better</li>
<li>Better multiple profile support</li>
<li>More &#8216;under the hood&#8217; options accessible</li>
</ul>
</td>
<td style="vertical-align: top;">
<ul>
<li><strong>* </strong>Faster to start</li>
<li>Integration with Google accounts</li>
<li>Better syncing with iOS</li>
<li>Single process per tab <sup><a href="http://blog.jverkamp.com/2013/05/18/firefox-vs-chrome/#footnote_0_4424" id="identifier_0_4424" class="footnote-link footnote-identifier-link" title="Which can also be a con when trying to figure out total useage">1</a></sup></li>
<li><strong>* </strong>Just feels faster, particularly in JavaScript heavy pages</li>
</ul>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><strong>Cons</strong></td>
<td style="vertical-align: top;">
<ul>
<li><strong>*</strong> Formatting issues, particularly with Google Docs, Gawker media sites <sup><a href="http://blog.jverkamp.com/2013/05/18/firefox-vs-chrome/#footnote_1_4424" id="identifier_1_4424" class="footnote-link footnote-identifier-link" title="Lifehacker and io9 in particular">2</a></sup>, and <a title="Wordpress" href="http://wordpress.com/">WordPress</a></li>
<li>Extensions seem to come to Chrome first now</li>
<li>Video acceleration doesn&#8217;t work for Flash (green screen)</li>
</ul>
</td>
<td style="vertical-align: top;">
<ul>
<li><strong>* </strong>Run by Google <sup><a href="http://blog.jverkamp.com/2013/05/18/firefox-vs-chrome/#footnote_2_4424" id="identifier_2_4424" class="footnote-link footnote-identifier-link" title="Yes, I&rsquo;m still bitter about Google Reader&hellip;">3</a></sup></li>
<li>Less support for more powerful plugins <sup><a href="http://blog.jverkamp.com/2013/05/18/firefox-vs-chrome/#footnote_3_4424" id="identifier_3_4424" class="footnote-link footnote-identifier-link" title="DownThemAll / NoScript&nbsp;/&nbsp;Zotero">4</a></sup></li>
<li><a title="KeePass Password Safe" href="http://keepass.info/">KeePass </a>autotype is sluggish</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p><span style="font-size: smaller;"><strong>*</strong> &#8211; Particularly important issues, purely in my opinion.</span></p>
<p>In the end, I stayed with Firefox for about two weeks. Right now, I&#8217;m back to Chrome. It just seems to work more smoothly. Given that the majority of my day is spent either on the command line or in a web browser, I need one that will work well and not crash. Firefox just doesn&#8217;t quite work for me right now. Perhaps I&#8217;ll try again in a few months.</p>
<ol class="footnotes"><li id="footnote_0_4424" class="footnote">Which can also be a con when trying to figure out total useage</li><li id="footnote_1_4424" class="footnote"><a title="Lifehacker" href="http://lifehacker.com">Lifehacker </a>and <a title="io9" href="http://io9.com">io9</a> in particular</li><li id="footnote_2_4424" class="footnote">Yes, I&#8217;m still bitter about <a title="R.I.P. Google Reader :(" href="https://www.google.com/reader/view/">Google Reader</a>&#8230;</li><li id="footnote_3_4424" class="footnote"><a title="DownThemAll for Firefox" href="https://addons.mozilla.org/en-US/firefox/addon/downthemall/">DownThemAll</a> / <a title="NoScript for Firefox" href="https://addons.mozilla.org/en-us/firefox/addon/noscript/">NoScript</a> / <a title="Zotero" href="https://www.zotero.org/">Zotero</a></li></ol>]]></content:encoded>
			<wfw:commentRss>http://blog.jverkamp.com/2013/05/18/firefox-vs-chrome/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Racket Roguelike 7: Into darkness!</title>
		<link>http://blog.jverkamp.com/2013/05/17/racket-roguelike-7-into-darkness/</link>
		<comments>http://blog.jverkamp.com/2013/05/17/racket-roguelike-7-into-darkness/#comments</comments>
		<pubDate>Fri, 17 May 2013 13:00:45 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Racket Roguelike]]></category>
		<category><![CDATA[Racket]]></category>
		<category><![CDATA[Roguelike]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.jverkamp.com/?p=4423</guid>
		<description><![CDATA[When I was playing Racket Roguelike earlier this week1, I realized something: I can see everything. There are no surprises, no mystery, no darkness Let&#8217;s fix that. (If you&#8217;d like to start at the beginning, click here: Racket Roguelike 1: A GUI, screens, I/O, and you!) This week, we want to add a dynamic lighting system to the game. If we were using a pre-built framework (like Doryen&#8217;s excellent libtcod), lighting would be done for us2. But that&#8217;s not the case. Luckily, the framework we&#8217;ve built already makes lighting relatively easy. First, we need some way of representing which tiles should be lit. Technically, we could calculate this on the fly every frame. This isn&#8217;t actually a terrible way of doing things and might just be more efficient than what we&#8217;re doing (don&#8217;t even bother rendering tiles you can&#8217;t see), but since we want to have a &#8216;fog of war&#8217; &#8230; <a href="http://blog.jverkamp.com/2013/05/17/racket-roguelike-7-into-darkness/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>When I was playing Racket Roguelike earlier this week<sup><a href="http://blog.jverkamp.com/2013/05/17/racket-roguelike-7-into-darkness/#footnote_0_4423" id="identifier_0_4423" class="footnote-link footnote-identifier-link" title="Always a good sign when you find yourself actually playing your own game&hellip;">1</a></sup>, I realized something: I can see everything. There are no surprises, no mystery, no <em>darkness</em></p>
<p>Let&#8217;s fix that.</p>
<p><span id="more-4423"></span></p>
<p>(If you&#8217;d like to start at the beginning, click here: <a title="Racket Roguelike 1: A GUI, screens, I/O, and you!" href="http://blog.jverkamp.com/2013/04/04/racket-roguelike-1-a-gui-screens-io-and-you/">Racket Roguelike 1: A GUI, screens, I/O, and you!</a>)</p>
<p>This week, we want to add a dynamic lighting system to the game. If we were using a pre-built framework (like Doryen&#8217;s excellent <a href="http://doryen.eptalys.net/libtcod/">libtcod</a>), lighting would be done for us<sup><a href="http://blog.jverkamp.com/2013/05/17/racket-roguelike-7-into-darkness/#footnote_1_4423" id="identifier_1_4423" class="footnote-link footnote-identifier-link" title="Perhaps I&rsquo;ll add it to AsciiPanel some day">2</a></sup>. But that&#8217;s not the case. Luckily, the framework we&#8217;ve built already makes lighting relatively easy.</p>
<p>First, we need some way of representing which tiles should be lit. Technically, we could calculate this on the fly every frame. This isn&#8217;t actually a terrible way of doing things and might just be more efficient than what we&#8217;re doing (don&#8217;t even bother rendering tiles you can&#8217;t see), but since we want to have a &#8216;fog of war&#8217; type system&#8211;where you can see the terrain you&#8217;ve passed, just not what&#8217;s there&#8211;that won&#8217;t quite work. </p>
<p>Instead, let&#8217;s add it to the <code>tile</code> definitions:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; levels.rkt</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>define<span style="color: #66cc66;">-</span>thing tile
  <span style="color: #66cc66;">&#91;</span>character #\space<span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#91;</span>color <span style="color: #ff0000;">&quot;black&quot;</span><span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#91;</span>items '<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#91;</span>lighting 'dark<span style="color: #66cc66;">&#93;</span>    <span style="color: #808080; font-style: italic;">; Dark: Invisible; Fog: Only show tile, not NPC or item; Lit: Everything</span>
  <span style="color: #66cc66;">&#91;</span>walkable #f<span style="color: #66cc66;">&#93;</span>       <span style="color: #808080; font-style: italic;">; Can the player walk on this tile?</span>
  <span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>As it says in the comment, we have a <code>lighting</code> parameter with three possible states:</p>
<ul>
<li><code>dark</code> &#8211; don&#8217;t draw the tile</li>
<li><code>fog</code> &#8211; draw the tile, but no items or NPCs in it (used once we see a tile then leave)</li>
<li><code>lit</code> &#8211; draw the tile, items, and NPCs (used when the player is nearby)</li>
</ul>
<p>Easy enough. But how do we actually add that to our drawing function? Head over to <em>game-screen.rkt</em>:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; game-screen.rkt</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> gray<span style="color: #66cc66;">-</span>background <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>object color<span style="color: #66cc66;">%</span> <span style="color: #cc66cc;">32</span> <span style="color: #cc66cc;">32</span> <span style="color: #cc66cc;">32</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>      
&nbsp;
...
&nbsp;
<span style="color: #808080; font-style: italic;">; Draw the tiles around the player</span>
<span style="color: #66cc66;">&#40;</span>for<span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>xi <span style="color: #66cc66;">&#40;</span>in<span style="color: #66cc66;">-</span>range <span style="color: #66cc66;">&#40;</span>send canvas get<span style="color: #66cc66;">-</span>width<span style="color: #66cc66;">-</span>in<span style="color: #66cc66;">-</span>characters<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
       <span style="color: #66cc66;">&#91;</span>yi <span style="color: #66cc66;">&#40;</span>in<span style="color: #66cc66;">-</span>range <span style="color: #66cc66;">&#40;</span>send canvas get<span style="color: #66cc66;">-</span>height<span style="color: #66cc66;">-</span>in<span style="color: #66cc66;">-</span>characters<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> x<span style="color: #66cc66;">/</span>y <span style="color: #66cc66;">&#40;</span>recenter canvas <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">-</span> <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get player 'location<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>pt xi yi<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> tile <span style="color: #66cc66;">&#40;</span>send world tile<span style="color: #66cc66;">-</span>at <span style="color: #66cc66;">&#40;</span>pt<span style="color: #66cc66;">-</span>x x<span style="color: #66cc66;">/</span>y<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>pt<span style="color: #66cc66;">-</span>y x<span style="color: #66cc66;">/</span>y<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> lighting <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get tile 'lighting 'lit<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span>
    <span style="color: #808080; font-style: italic;">; Draw nothing on dark tiles</span>
    <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eq?</span> lighting 'dark<span style="color: #66cc66;">&#41;</span>
     <span style="color: #66cc66;">&#40;</span>void<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #808080; font-style: italic;">; If it's in fog, draw with a gray background</span>
    <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eq?</span> lighting 'fog<span style="color: #66cc66;">&#41;</span>
     <span style="color: #66cc66;">&#40;</span>send canvas <span style="color: #b1b100;">write</span> 
           <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get tile 'character<span style="color: #66cc66;">&#41;</span> 
           xi yi 
           <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get tile 'color<span style="color: #66cc66;">&#41;</span> gray<span style="color: #66cc66;">-</span>background<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #808080; font-style: italic;">; If it's lit but there are no items, draw the tile</span>
    <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">null?</span> <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get tile 'items '<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
     <span style="color: #66cc66;">&#40;</span>send canvas <span style="color: #b1b100;">write</span> 
           <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get tile 'character<span style="color: #66cc66;">&#41;</span> 
           xi yi 
           <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get tile 'color<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #808080; font-style: italic;">; If it's lit and there are items, draw the item</span>
    <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">else</span>
     <span style="color: #66cc66;">&#40;</span>send canvas <span style="color: #b1b100;">write</span> 
           <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get tile 'items<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> 'character<span style="color: #66cc66;">&#41;</span> 
           xi yi 
           <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get tile 'items<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> 'color<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>Basically, we draw nothing on dark tiles. This relies on the <code>clear</code> just above this code. If it&#8217;s foggy, we have a background, defined at the top of the file<sup><a href="http://blog.jverkamp.com/2013/05/17/racket-roguelike-7-into-darkness/#footnote_2_4423" id="identifier_2_4423" class="footnote-link footnote-identifier-link" title="And defined only once to save just a bit on performance; we&rsquo;re going to have to look at that soon&hellip;">3</a></sup>. Otherwise, we fall back on the methods that we already had. </p>
<p>Next, we need to actually calculate this lighting. Essentially, every tile starts dark. Then, if a tile is near to the player, light it up. If it&#8217;s already lit but no longer near the tile, fade to fog. For now, we&#8217;re just going to use a simple radius around the player (parameterized below). Here&#8217;s the new <code>update-lighting</code> function and friends:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; entities.rkt</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; game-screen.rkt</span>
<span style="color: #66cc66;">&#40;</span>define<span style="color: #66cc66;">-</span>thing entity
  ...
  <span style="color: #66cc66;">&#91;</span>view<span style="color: #66cc66;">-</span>range <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; Draw the game itself.</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span><span style="color: #66cc66;">/</span>override <span style="color: #66cc66;">&#40;</span>draw canvas<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> player <span style="color: #66cc66;">&#40;</span>send world get<span style="color: #66cc66;">-</span>player<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>send canvas clear<span style="color: #66cc66;">&#41;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">; Update lighting</span>
  <span style="color: #66cc66;">&#40;</span>send world update<span style="color: #66cc66;">-</span>lighting<span style="color: #66cc66;">&#41;</span>
&nbsp;
  ...<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; world.rkt</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; Update lighting</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span><span style="color: #66cc66;">/</span>public <span style="color: #66cc66;">&#40;</span>update<span style="color: #66cc66;">-</span>lighting<span style="color: #66cc66;">&#41;</span>
  <span style="color: #808080; font-style: italic;">; Turn any lit tiles to fog</span>
  <span style="color: #808080; font-style: italic;">; Turn any tiles within the player's view limit to lit</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> player<span style="color: #66cc66;">-</span>location <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get player 'location<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> player<span style="color: #66cc66;">-</span>view <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get player 'view<span style="color: #66cc66;">-</span>range <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>for<span style="color: #66cc66;">-</span>tile
   <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>x y tile<span style="color: #66cc66;">&#41;</span>
     <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span>
       <span style="color: #808080; font-style: italic;">; Light tiles near the player</span>
       <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&lt;=</span> <span style="color: #66cc66;">&#40;</span>distance player<span style="color: #66cc66;">-</span>location <span style="color: #66cc66;">&#40;</span>pt x y<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> player<span style="color: #66cc66;">-</span>view<span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span><span style="color: #b1b100;">set!</span> tile 'lighting 'lit<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
       <span style="color: #808080; font-style: italic;">; Fog previously lit tiles</span>
       <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eq?</span> 'lit <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get tile 'lighting<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span><span style="color: #b1b100;">set!</span> tile 'lighting 'fog<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
       <span style="color: #808080; font-style: italic;">; Otherwise do nothing</span>
       <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>For that, we need the <code>for-tile</code> function. You can check it out <a href="https://github.com/jpverkamp/racket-roguelike/blob/master/src/levels.rkt">on GitHub</a>, but essentially it takes a function of the form <code>(lambda (x y tile) ...)</code> and applies it to each tile on the current level. It might<sup><a href="http://blog.jverkamp.com/2013/05/17/racket-roguelike-7-into-darkness/#footnote_3_4423" id="identifier_3_4423" class="footnote-link footnote-identifier-link" title="Read: will">4</a></sup> get inefficient on more explored levels, but if people keep heading down, we should be good. So in this case, we&#8217;ll just light the area around the player. How does that look?</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/simple-lighting.png" rel="lightbox[4423]"><img src="http://blog.jverkamp.com/wp-content/uploads/2013/05/simple-lighting.png" alt="" width="300" height="180" class="wp-image-4445" /></a></p>
<p>Starting out, not too bad. We&#8217;re out in the middle of a nice grass field like always. Just this time, we can&#8217;t see much of it. Perhaps it&#8217;s night time?</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/simple-fog.png" rel="lightbox[4423]"><img src="http://blog.jverkamp.com/wp-content/uploads/2013/05/simple-fog.png" alt="" width="300" height="180" class="wp-image-4444" /></a></p>
<p>Wander around a bit until we find a way down. You can see the gray background of the fog. That actually looks pretty nice, particularly as you&#8217;re moving around.</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/into-the-caves.png" rel="lightbox[4423]"><img src="http://blog.jverkamp.com/wp-content/uploads/2013/05/into-the-caves.png" alt="" width="300" height="180" class="wp-image-4443" /></a></p>
<p>Okay, now we&#8217;re into the caves. Let&#8217;s explore for a bit.</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/this-is-a-problem.png" rel="lightbox[4423]"><img src="http://blog.jverkamp.com/wp-content/uploads/2013/05/this-is-a-problem.png" alt="" width="300" height="180" class="wp-image-4446" /></a></p>
<p>Hmm. Well, this is a problem. It turns out&#8230; we can see right through walls. Perhaps we should work on that a bit.</p>
<p>This is when a pre-built framework would <em>really</em> come in handy. But the algorithm isn&#8217;t too bad. Essentially, we want <a href="https://en.wikipedia.org/wiki/Raycasting" title="Raycasting on Wikipedia">raycasting</a>. We&#8217;ll start with a series of lines out from the player and light tiles as we go. If we hit something that can&#8217;t be lit up, stop. Sounds like a nicely recursive function to me!</p>
<p>Before that, let&#8217;s modify the tile definitions again. We&#8217;ll add the <code>solid</code> property. If a tile is <code>solid</code> (like a wall or a tree), you can&#8217;t see through it. Otherwise (like empty space or over water), you can.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; levels.rkt</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>define<span style="color: #66cc66;">-</span>thing tile
  <span style="color: #66cc66;">&#91;</span>character #\space<span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#91;</span>color <span style="color: #ff0000;">&quot;black&quot;</span><span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#91;</span>items '<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#91;</span>lighting 'dark<span style="color: #66cc66;">&#93;</span>    <span style="color: #808080; font-style: italic;">; Dark: Invisible; Fog: Only show tile, not NPC or item; Lit: Everything</span>
  <span style="color: #66cc66;">&#91;</span>walkable #f<span style="color: #66cc66;">&#93;</span>       <span style="color: #808080; font-style: italic;">; Can the player walk on this tile?</span>
  <span style="color: #66cc66;">&#91;</span>solid #f<span style="color: #66cc66;">&#93;</span>          <span style="color: #808080; font-style: italic;">; Does this tile block light?</span>
  <span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>So how do we write a raycasting function?</p>
<p>The basic idea<sup><a href="http://blog.jverkamp.com/2013/05/17/racket-roguelike-7-into-darkness/#footnote_4_4423" id="identifier_4_4423" class="footnote-link footnote-identifier-link" title="Which may or may not be the standard way of doing it">5</a></sup> is to start with four rays, one in each of the cardinal directions. Give each ray its own direction. Then as we pass each tile, branch out in each direction for a total of three branches per iteration. It&#8217;s certainly not optimal (we&#8217;ll light some tiles more than once), but it does look nice.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; world.rkt</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; Update lighting</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span><span style="color: #66cc66;">/</span>public <span style="color: #66cc66;">&#40;</span>update<span style="color: #66cc66;">-</span>lighting<span style="color: #66cc66;">&#41;</span>
  <span style="color: #808080; font-style: italic;">; Turn any lit tiles to fog</span>
  <span style="color: #66cc66;">&#40;</span>for<span style="color: #66cc66;">-</span>tile
   <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>x y tile<span style="color: #66cc66;">&#41;</span>
     <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span>
       <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eq?</span> 'lit <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get tile 'lighting 'dark<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span><span style="color: #b1b100;">set!</span> tile 'lighting 'fog<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">; Spread lighting from the player</span>
  <span style="color: #808080; font-style: italic;">; x/y current tile to light</span>
  <span style="color: #808080; font-style: italic;">; xd/yd direction to spread light:</span>
  <span style="color: #808080; font-style: italic;">;  if xd != 0, spread to (x+xd y-1) (x+xd y) (x+xd y+1)</span>
  <span style="color: #808080; font-style: italic;">;  if yd != 0, spread to (x-1 y+yd) (x y+yd) (x-1 y+yd)</span>
  <span style="color: #808080; font-style: italic;">; spread is initially set to player's light radius</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>spread<span style="color: #66cc66;">-</span>light x y xd yd spread<span style="color: #66cc66;">&#41;</span>
    <span style="color: #808080; font-style: italic;">; Light the current tile</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> tile <span style="color: #66cc66;">&#40;</span>get<span style="color: #66cc66;">-</span>tile x y<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span><span style="color: #b1b100;">set!</span> tile 'lighting 'lit<span style="color: #66cc66;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">; Recur</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span>
      <span style="color: #808080; font-style: italic;">; Don't spread pass solid tiles (spread to them though)</span>
      <span style="color: #808080; font-style: italic;">; Don't recur past the spread (vision range) value</span>
      <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">or</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&lt;=</span> spread <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get tile 'solid #f<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
       <span style="color: #66cc66;">&#40;</span>void<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
      <span style="color: #808080; font-style: italic;">; Spread in the x direction</span>
      <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">not</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">=</span> xd <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
       <span style="color: #66cc66;">&#40;</span>spread<span style="color: #66cc66;">-</span>light <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">+</span> x xd<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">-</span> y <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> xd yd <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">-</span> spread <span style="color: #cc66cc;">1.41</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
       <span style="color: #66cc66;">&#40;</span>spread<span style="color: #66cc66;">-</span>light <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">+</span> x xd<span style="color: #66cc66;">&#41;</span> y       xd yd <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">-</span> spread <span style="color: #cc66cc;">1.00</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
       <span style="color: #66cc66;">&#40;</span>spread<span style="color: #66cc66;">-</span>light <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">+</span> x xd<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">+</span> y <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> xd yd <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">-</span> spread <span style="color: #cc66cc;">1.41</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
      <span style="color: #808080; font-style: italic;">; Spread in the y direction</span>
      <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">else</span>
       <span style="color: #66cc66;">&#40;</span>spread<span style="color: #66cc66;">-</span>light <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">-</span> x <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">+</span> y yd<span style="color: #66cc66;">&#41;</span> xd yd <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">-</span> spread <span style="color: #cc66cc;">1.41</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
       <span style="color: #66cc66;">&#40;</span>spread<span style="color: #66cc66;">-</span>light x       <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">+</span> y yd<span style="color: #66cc66;">&#41;</span> xd yd <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">-</span> spread <span style="color: #cc66cc;">1.00</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
       <span style="color: #66cc66;">&#40;</span>spread<span style="color: #66cc66;">-</span>light <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">+</span> x <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">+</span> y yd<span style="color: #66cc66;">&#41;</span> xd yd <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">-</span> spread <span style="color: #cc66cc;">1.41</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">; Spread in the four directions</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>player<span style="color: #66cc66;">-</span>x <span style="color: #66cc66;">&#40;</span>pt<span style="color: #66cc66;">-</span>x <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get player 'location<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
        <span style="color: #66cc66;">&#91;</span>player<span style="color: #66cc66;">-</span>y <span style="color: #66cc66;">&#40;</span>pt<span style="color: #66cc66;">-</span>y <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get player 'location<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
        <span style="color: #66cc66;">&#91;</span>player<span style="color: #66cc66;">-</span>v <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get player 'view<span style="color: #66cc66;">-</span>range <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>spread<span style="color: #66cc66;">-</span>light player<span style="color: #66cc66;">-</span>x player<span style="color: #66cc66;">-</span>y <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span>  <span style="color: #cc66cc;">0</span> player<span style="color: #66cc66;">-</span>v<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>spread<span style="color: #66cc66;">-</span>light player<span style="color: #66cc66;">-</span>x player<span style="color: #66cc66;">-</span>y  <span style="color: #cc66cc;">1</span>  <span style="color: #cc66cc;">0</span> player<span style="color: #66cc66;">-</span>v<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>spread<span style="color: #66cc66;">-</span>light player<span style="color: #66cc66;">-</span>x player<span style="color: #66cc66;">-</span>y  <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span> player<span style="color: #66cc66;">-</span>v<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>spread<span style="color: #66cc66;">-</span>light player<span style="color: #66cc66;">-</span>x player<span style="color: #66cc66;">-</span>y  <span style="color: #cc66cc;">0</span>  <span style="color: #cc66cc;">1</span> player<span style="color: #66cc66;">-</span>v<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>Hopefully that all makes sense. One sneaky trick is reducing the <code>spread</code> by 1 on the orthogonal moves and 1.41 (roughly <img src="//s0.wp.com/latex.php?latex=sqrt%282%29&#038;bg=ffffff&#038;fg=000&#038;s=0" alt="sqrt(2)" title="sqrt(2)" class="latex" />) on the diagonals. This will give us a nice circle. </p>
<p>Let&#8217;s see what an effect that has on the game:</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/nice-circle.png" rel="lightbox[4423]"><img src="http://blog.jverkamp.com/wp-content/uploads/2013/05/nice-circle.png" alt="" width="300" height="180" class="wp-image-4448" /></a></p>
<p>Starting out, we have a nice circle. So far, it looks pretty much the same as it did last time.</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/trees-cast-shadows.png" rel="lightbox[4423]"><img src="http://blog.jverkamp.com/wp-content/uploads/2013/05/trees-cast-shadows.png" alt="" width="300" height="180" class="wp-image-4453" /></a></p>
<p>Shadows! I can&#8217;t tell you how excited this makes me. <img src='http://blog.jverkamp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/over-troubled-waters.png" rel="lightbox[4423]"><img src="http://blog.jverkamp.com/wp-content/uploads/2013/05/over-troubled-waters.png" alt="" width="300" height="180" class="wp-image-4450" /></a></p>
<p>And it works perfectly with water as well. We can see over the water, but we can&#8217;t walk through it.</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/missing-something.png" rel="lightbox[4423]"><img src="http://blog.jverkamp.com/wp-content/uploads/2013/05/missing-something.png" alt="" width="300" height="180" class="wp-image-4447" /></a></p>
<p>Unfortunately though, I haven&#8217;t had any luck yet finding a staircase&#8230;</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/no-more-xray-vision.png" rel="lightbox[4423]"><img src="http://blog.jverkamp.com/wp-content/uploads/2013/05/no-more-xray-vision.png" alt="" width="300" height="180" class="wp-image-4449" /></a></p>
<p>Finally, we&#8217;re down a level. It&#8217;s nice to see<sup><a href="http://blog.jverkamp.com/2013/05/17/racket-roguelike-7-into-darkness/#footnote_5_4423" id="identifier_5_4423" class="footnote-link footnote-identifier-link" title="Believe it or not, pun not intended">6</a></sup>: no more x-ray vision! It does look a bit weird to have all the nice thin walls around, but it looks a lot better once you get used to it.</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/there-are-rats.png" rel="lightbox[4423]"><img src="http://blog.jverkamp.com/wp-content/uploads/2013/05/there-are-rats.png" alt="" width="300" height="180" class="wp-image-4452" /></a></p>
<p>Theoretically, the player shouldn&#8217;t be able to hear updates from entities that aren&#8217;t visible. That would actually be pretty easy to implement (just check for the lighting in the logging function), but for the moment, I like the atmosphere it gives. </p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/still-no-rats.png" rel="lightbox[4423]"><img src="http://blog.jverkamp.com/wp-content/uploads/2013/05/still-no-rats.png" alt="" width="300" height="180" class="wp-image-4451" /></a></p>
<p>All that time wandering about and I still haven&#8217;t actually found any of those rats to fight. I wanted to show that it won&#8217;t draw them unless they&#8217;re in a lit area. Sigh. So it goes.</p>
<p>Well, that&#8217;s all we have for today. It&#8217;s kind of amazing how much difference so few lines can make<sup><a href="http://blog.jverkamp.com/2013/05/17/racket-roguelike-7-into-darkness/#footnote_6_4423" id="identifier_6_4423" class="footnote-link footnote-identifier-link" title="According to the git diff, 26 lines removed and 111 added">7</a></sup>. </p>
<p>As always, if you&#8217;d like to see all of the code for this project, you can do so on GitHub:<br />
- <a title="Racket Roguelike on GitHub" href="https://github.com/jpverkamp/racket-roguelike/tree/day-7">Racket Roguelike &#8211; Day 7</a><br />
- <a title="Racket Roguelike on GitHub" href="https://github.com/jpverkamp/racket-roguelike">Racket Roguelike &#8211; Up to date</a></p>
<p>If you&#8217;d like to try it yourself, you&#8217;ll need to have both <a href="http://git-scm.com/">Git</a> and <a href="http://racket-lang.org/">Racket</a> and run the following series of commands:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git clone</span> git:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>jpverkamp<span style="color: #000000; font-weight: bold;">/</span>racket-roguelike.git
<span style="color: #7a0874; font-weight: bold;">cd</span> racket-roguelike
<span style="color: #c20cb9; font-weight: bold;">git checkout</span> day-<span style="color: #000000;">7</span>
<span style="color: #c20cb9; font-weight: bold;">git submodule</span> init
<span style="color: #c20cb9; font-weight: bold;">git submodule</span> update
racket main.rkt</pre></td></tr></table></div>

<ol class="footnotes"><li id="footnote_0_4423" class="footnote">Always a good sign when you find yourself actually playing your own game&#8230;</li><li id="footnote_1_4423" class="footnote">Perhaps I&#8217;ll add it to <a title="Writing a roguelike — in Racket! (Day 0)" href="http://blog.jverkamp.com/2013/03/28/writing-a-roguelike-in-racket-day-0/">AsciiPanel</a> some day</li><li id="footnote_2_4423" class="footnote">And defined only once to save just a bit on performance; we&#8217;re going to have to look at that soon&#8230;</li><li id="footnote_3_4423" class="footnote">Read: will</li><li id="footnote_4_4423" class="footnote">Which may or may not be the standard way of doing it</li><li id="footnote_5_4423" class="footnote">Believe it or not, pun not intended</li><li id="footnote_6_4423" class="footnote">According to the git diff, 26 lines removed and 111 added</li></ol>]]></content:encoded>
			<wfw:commentRss>http://blog.jverkamp.com/2013/05/17/racket-roguelike-7-into-darkness/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pain &amp; Gain</title>
		<link>http://blog.jverkamp.com/2013/05/15/pain-gain/</link>
		<comments>http://blog.jverkamp.com/2013/05/15/pain-gain/#comments</comments>
		<pubDate>Thu, 16 May 2013 03:55:33 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[Movies]]></category>
		<category><![CDATA[Other]]></category>

		<guid isPermaLink="false">http://blog.jverkamp.com/?p=4418</guid>
		<description><![CDATA[Pain &#38; Gain is a pretty good example of the American Dream gone wrong&#8230; Which I guess is exactly what it&#8217;s supposed to be. So I&#8217;ll give it credit for that. That&#8217;s really all it has though. There&#8217;s a decent smattering of violence and nudity, if you&#8217;re into that sort of thing, but personally I just found it painful to watch. Halfway through, I was actually considering walking out which, for me, is really saying something. Basically, it&#8217;s a kidnapping gone wrong and it proceeds pretty much exactly as you&#8217;d expect. Everything starts out innocent enough (or as innocent as a kidnapping can be) and just spirals out of control. And yet the protagonists never really just quite how incompetent they are. Mark Wahlberg1 is actually pretty believable as Lugo&#8211;absolutely convinced that he&#8217;s deserving of a better life and is just reaching out to take hold of it. Dwayne Johnson does &#8230; <a href="http://blog.jverkamp.com/2013/05/15/pain-gain/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/Pain-Gain.jpg" rel="lightbox[4418]"><img class="alignright size-full wp-image-4419" alt="" src="http://blog.jverkamp.com/wp-content/uploads/2013/05/Pain-Gain.jpg" width="214" height="317" /></a></p>
<p>Pain &amp; Gain is a pretty good example of the American Dream gone wrong&#8230;</p>
<p><span id="more-4418"></span></p>
<p>Which I guess is exactly what it&#8217;s supposed to be. So I&#8217;ll give it credit for that.</p>
<p>That&#8217;s really all it has though. There&#8217;s a decent smattering of violence and nudity, if you&#8217;re into that sort of thing, but personally I just found it painful to watch. Halfway through, I was actually considering walking out which, for me, is really saying something.</p>
<p>Basically, it&#8217;s a kidnapping gone wrong and it proceeds pretty much exactly as you&#8217;d expect. Everything starts out innocent enough (or as innocent as a kidnapping can be) and just spirals out of control. And yet the protagonists never really just quite how incompetent they are. <a itemprop="url" href="http://www.imdb.com/name/nm0000242/?ref_=tt_cl_t1">Mark Wahlberg</a><sup><a href="http://blog.jverkamp.com/2013/05/15/pain-gain/#footnote_0_4418" id="identifier_0_4418" class="footnote-link footnote-identifier-link" title="He looks remarkably familiar considering I don&rsquo;t think I&rsquo;ve seen anything else he&rsquo;s been in&hellip;">1</a></sup> is actually pretty believable as <a href="http://www.imdb.com/character/ch0293640/?ref_=tt_cl_t1">Lugo</a>&#8211;absolutely convinced that he&#8217;s deserving of a better life and is just reaching out to take hold of it. <a itemprop="url" href="http://www.imdb.com/name/nm0425005/?ref_=tt_cl_t2">Dwayne Johnson</a> does rather well as an ex-con who found Jesus in the loosest sense of the word.</p>
<p>Really, I think the worst part is that this is all based (loosely!) on a true story. I read up on the details and they&#8217;ve changed a fair bit (which reminds me of <a title="Argo" href="http://blog.jverkamp.com/2012/10/29/argo/">Argo</a>). It&#8217;s always amazing just how terrible human beings can be to one another.</p>
<p>Overall, I have no qualms putting this movie dead last for the year. In 20/20 hindsight, I wish I had gone to see <a title="Iron Man 3" href="http://blog.jverkamp.com/2013/05/05/iron-man-3/">Iron Man 3</a> again&#8230;</p>
<p><strong>My 2013 Movie Rankings</strong></p>
<ol>
<li><a title="Iron Man 3" href="http://blog.jverkamp.com/2013/05/05/iron-man-3/">Iron Man 3</a></li>
<li><a title="The Croods" href="http://blog.jverkamp.com/2013/04/08/the-croods/">The Croods</a></li>
<li><a title="Django Unchained" href="http://blog.jverkamp.com/2013/01/22/django-unchained/">Django Unchained</a></li>
<li><a title="Parental Guidance" href="http://blog.jverkamp.com/2013/01/27/parental-guidance/">Parental Guidance</a></li>
<li><a title="Oblivion" href="http://blog.jverkamp.com/2013/04/24/oblivion/">Oblivion</a></li>
<li><a title="Beautiful Creatures" href="http://blog.jverkamp.com/2013/02/17/beautiful-creatures/">Beautiful Creatures</a></li>
<li><a title="Jurassic Park (3D!)" href="http://blog.jverkamp.com/2013/05/01/jurassic-park-3d/">Jurassic Park (3D!)</a></li>
<li><a title="Oz the Great and Powerful" href="http://blog.jverkamp.com/2013/03/10/oz-the-great-and-powerful/">Oz the Great and Powerful</a></li>
<li><a title="Hansel &amp; Gretel: Witch Hunters" href="http://blog.jverkamp.com/2013/02/13/hansel-gretel-witch-hunters/">Hansel &amp; Gretel: Witch Hunters</a></li>
<li><a title="Jack the Giant Slayer" href="http://blog.jverkamp.com/2013/03/12/jack-the-giant-slayer/">Jack the Giant Slayer</a></li>
<li><a title="Warm Bodies" href="http://blog.jverkamp.com/2013/02/26/warm-bodies/">Warm Bodies</a></li>
<li><a title="G.I. Joe: Retaliation" href="http://blog.jverkamp.com/2013/04/03/g-i-joe-retaliation/">G.I. Joe: Retaliation</a></li>
<li><a title="Pain &amp; Gain" href="http://blog.jverkamp.com/2013/05/16/pain-gain/">Pain &amp; Gain</a></li>
</ol>
<ol class="footnotes"><li id="footnote_0_4418" class="footnote">He looks remarkably familiar considering I don&#8217;t think I&#8217;ve seen anything else he&#8217;s been in&#8230;</li></ol>]]></content:encoded>
			<wfw:commentRss>http://blog.jverkamp.com/2013/05/15/pain-gain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Racket Roguelike 6: Dig deeper!</title>
		<link>http://blog.jverkamp.com/2013/05/10/racket-roguelike-6-dig-deeper/</link>
		<comments>http://blog.jverkamp.com/2013/05/10/racket-roguelike-6-dig-deeper/#comments</comments>
		<pubDate>Fri, 10 May 2013 13:00:24 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Racket Roguelike]]></category>
		<category><![CDATA[Racket]]></category>
		<category><![CDATA[Roguelike]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.jverkamp.com/?p=4400</guid>
		<description><![CDATA[Moria&#8230; You fear to go into those mines. The dwarves delved too greedily and too deep. You know what they awoke in the darkness of Khazad-dum&#8230; shadow and flame. &#8211; Saruman, Lord of the Rings Today, we dig too deep. (If you&#8217;d like to start at the beginning, click here: Racket Roguelike 1: A GUI, screens, I/O, and you!) Essentially, what we&#8217;re going to do today is to tear out that placeholder we had for level generation and add a proper abstracted level generation script. With that, we might as well add the ability to generate a bunch of levels and just dig deeper and deeper. Okay, so what&#8217;s first? Well, the current code for level generation is in that huge, ugly get-tile function in world.rkt. Instead, let&#8217;s make a new file: levels.rkt. This will have all of the level generation code. So what&#8217;s first? Let&#8217;s pull out the code &#8230; <a href="http://blog.jverkamp.com/2013/05/10/racket-roguelike-6-dig-deeper/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<blockquote><p>Moria&#8230; You fear to go into those mines. The dwarves delved too greedily and too deep. You know what they awoke in the darkness of Khazad-dum&#8230; shadow and flame.<br />
&#8211; Saruman, Lord of the Rings</p></blockquote>
<p>Today, we dig too deep.</p>
<p><span id="more-4400"></span></p>
<p>(If you&#8217;d like to start at the beginning, click here: <a title="Racket Roguelike 1: A GUI, screens, I/O, and you!" href="http://blog.jverkamp.com/2013/04/04/racket-roguelike-1-a-gui-screens-io-and-you/">Racket Roguelike 1: A GUI, screens, I/O, and you!</a>)</p>
<p>Essentially, what we&#8217;re going to do today is to tear out that placeholder we had for level generation and add a proper abstracted level generation script. With that, we might as well add the ability to generate a bunch of levels and just dig deeper and deeper.</p>
<p>Okay, so what&#8217;s first? Well, the current code for level generation is in that huge, ugly <code>get-tile</code> function in <code>world.rkt</code>. Instead, let&#8217;s make a new file: <code>levels.rkt</code>. This will have all of the level generation code. So what&#8217;s first? Let&#8217;s pull out the code generation:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; levels.rkt</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; Generate a simple cave with water and trees</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>shallow<span style="color: #66cc66;">-</span>cave x y<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> wall?  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&amp;</span>gt<span style="color: #808080; font-style: italic;">; (simplex (* 0.1 x) (* 0.1 y) 0)         0))</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> water? <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&amp;</span>gt<span style="color: #808080; font-style: italic;">; (simplex (* 0.1 x) 0         (* 0.1 y)) 0.5))</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> tree?  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&amp;</span>gt<span style="color: #808080; font-style: italic;">; (simplex 0         (* 0.1 x) (* 0.1 y)) 0.5))</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span>
    <span style="color: #66cc66;">&#91;</span>wall?  <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing wall<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#91;</span>water? <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing water<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#91;</span>tree?  <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing tree<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">else</span>   <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing empty<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>This will represent the first few levels under the ground, with the same basic cave systems we&#8217;ve been using forever. There&#8217;s on problem with that&#8211;it turns out that using the noise functions is both a time saver and will be our undoing. Since the function always returns the same values, given the same arguments, every level of our cave system will be identical. Not something we want (at least not for the caves).</p>
<p>The fix?</p>
<p>Add another parameter!</p>
<p>Technically, there are two ways that we could do this:</p>
<ul>
<li>Add a z-coordinate that corresponds to depth. This feels like some nice parallelism, but it means that every single time we play the game, the caves will be the same. Sub-optimal for a roguelike.</li>
<li>Add a random seed that is set once per level. This will generate levels random (albeit consistently within a single playthrough), so this is the option we want.</li>
</ul>
<p>This actually turns out to be really easy to implement:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; levels.rkt</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; Generate a simple cave with water and trees</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>shallow<span style="color: #66cc66;">-</span>cave seed x y<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> wall?  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&amp;</span>gt<span style="color: #808080; font-style: italic;">; (simplex (* 0.1 x) (* 0.1 y) seed)      0))</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> water? <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&amp;</span>gt<span style="color: #808080; font-style: italic;">; (simplex (* 0.1 x) seed      (* 0.1 y)) 0.5))</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> tree?  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&amp;</span>gt<span style="color: #808080; font-style: italic;">; (simplex seed      (* 0.1 x) (* 0.1 y)) 0.5))</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span>
    <span style="color: #66cc66;">&#91;</span>wall?  <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing wall<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#91;</span>water? <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing water<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#91;</span>tree?  <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing tree<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">else</span>   <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing empty<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>Now we&#8217;ll get all sorts of interesting levels. For example:</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/cave-1.png" rel="lightbox[4400]"><img class="alignnone wp-image-4405" alt="" src="http://blog.jverkamp.com/wp-content/uploads/2013/05/cave-1.png" width="300" height="187" /></a></p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/cave-2.png" rel="lightbox[4400]"><img class="alignnone wp-image-4406" alt="" src="http://blog.jverkamp.com/wp-content/uploads/2013/05/cave-2.png" width="300" height="187" /></a></p>
<p>(Yes, there are only rats and basic gear. I&#8217;ll get to that in a second.)</p>
<p>So we can make caves, just like we always have, but what about other sorts of terrain? Well, all we have to do is copy/paste/tweak. Let&#8217;s say instead of caves and walls, we want grassland (but still with trees and small ponds). We&#8217;d get something like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; levels.rkt</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>define<span style="color: #66cc66;">-</span>thing grass tile
  <span style="color: #66cc66;">&#91;</span>character #\.<span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#91;</span>color <span style="color: #ff0000;">&quot;green&quot;</span><span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#91;</span>walkable #t<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; The surface level with grass, water, and trees</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>surface seed x y<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> water? <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&amp;</span>gt<span style="color: #808080; font-style: italic;">; (simplex (* 0.1 x) seed      (* 0.1 y)) 0.5))</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> tree?  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&amp;</span>gt<span style="color: #808080; font-style: italic;">; (simplex seed      (* 0.1 x) (* 0.1 y)) 0.5))</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span>
    <span style="color: #66cc66;">&#91;</span>water? <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing water<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#91;</span>tree?  <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing tree<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">else</span>   <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing grass<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/grassland.png" rel="lightbox[4400]"><img class="alignnone wp-image-4407" alt="" src="http://blog.jverkamp.com/wp-content/uploads/2013/05/grassland.png" width="300" height="187" /></a></p>
<p>We can easily tune this to make any sorts of levels. Even better, we don&#8217;t necessary need to use the noise functions. We could theoretically make levels based on something like <a href="https://en.wikipedia.org/wiki/Cellular_automaton">cellular automaton</a> or even scripted levels (perhaps loaded from external files?). All we have to do is be able to generate a specific tile when asked and our framework will generate the rest. Speaking of which, how do we tie this into the previous <code>get-tile</code> function?</p>
<p>Well, we need a bit of abstraction first. First, how do we want to represent z-levels? Theoretically, we could use the same hash that we&#8217;ve been using, only using <code>(list x y z)</code> instead of <code>(list x y)</code>. But keeping all of that in one hash seems like a recipe for trouble, so instead, we&#8217;ll store a hash of hashes. Each outer hash will be indexed by depth, the inner by the point. Then we can have a local variable referring to just the current level.</p>
<p>While we&#8217;re at it, let&#8217;s all refactor some other code. We need to store the <code>seed</code> that I mentioned earlier for each level. In addition, we want to store the generation functions for tiles (and later NPCs and items). Finally, so we don&#8217;t have an ever-growing list of NPCs all acting each tick, let&#8217;s move the NPC lists into the level. In the end, something like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; levels.rkt</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; Level defintions</span>
<span style="color: #808080; font-style: italic;">; tile-gen : x y -&amp;gt; tile</span>
<span style="color: #808080; font-style: italic;">; npc-gen  : x y -&amp;gt; npc or #f</span>
<span style="color: #808080; font-style: italic;">; item-gen : x y -&amp;gt; item or #f</span>
<span style="color: #66cc66;">&#40;</span>define<span style="color: #66cc66;">-</span>struct level<span style="color: #66cc66;">-</span>definition <span style="color: #66cc66;">&#40;</span>tile<span style="color: #66cc66;">-</span>gen npc<span style="color: #66cc66;">-</span>gen item<span style="color: #66cc66;">-</span>gen<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; All levels </span>
<span style="color: #808080; font-style: italic;">; (pt x y) : tile</span>
<span style="color: #808080; font-style: italic;">; 'npcs    : list of npcs</span>
<span style="color: #808080; font-style: italic;">; 'gen     ; level definition (see above)</span>
<span style="color: #808080; font-style: italic;">; 'seed    ; a random seed [0,1) generated once per level</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> levels <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>hasheq<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> current<span style="color: #66cc66;">-</span>depth <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>parameter <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; Generate a new level (if it doesn't already exist)</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>get<span style="color: #66cc66;">-</span>level depth<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>unless <span style="color: #66cc66;">&#40;</span>hash<span style="color: #66cc66;">-</span>has<span style="color: #66cc66;">-</span>key? levels depth<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> level <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>hash<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>hash<span style="color: #66cc66;">-</span><span style="color: #b1b100;">set!</span> level 'seed <span style="color: #66cc66;">&#40;</span>random<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>hash<span style="color: #66cc66;">-</span><span style="color: #b1b100;">set!</span> level 'npcs '<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>hash<span style="color: #66cc66;">-</span><span style="color: #b1b100;">set!</span> level 'gen
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span>
        <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">=</span> depth <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> 
         <span style="color: #66cc66;">&#40;</span>level<span style="color: #66cc66;">-</span>definition surface nothing nothing<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
        <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">else</span>
         <span style="color: #66cc66;">&#40;</span>level<span style="color: #66cc66;">-</span>definition shallow<span style="color: #66cc66;">-</span>cave rats<span style="color: #66cc66;">-</span>only base<span style="color: #66cc66;">-</span>items<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>hash<span style="color: #66cc66;">-</span><span style="color: #b1b100;">set!</span> levels depth level<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>hash<span style="color: #66cc66;">-</span>ref levels depth<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>With this, <code>get-level</code> mirrors <code>get-tile</code>. If a level doesn&#8217;t currently exist, it will generate a new one. In this case, we have our two generation functions. If the level is 0 (the ground level), use the grassland generator. If it&#8217;s less than that, for now always generate caves. There are a few other generators (<code>nothing</code>, <code>rats-only</code>, and <code>base-items</code>) but I&#8217;ll get to those in a moment. (You can get a pretty good hint for what those will be by looking at the <code>level-definition</code> struct.)</p>
<p>With this, we have what we need to rebuild the <code>get-tile</code> function:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; levels.rkt</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; Fetch a tile</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>get<span style="color: #66cc66;">-</span>tile x y<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> current<span style="color: #66cc66;">-</span>level <span style="color: #66cc66;">&#40;</span>get<span style="color: #66cc66;">-</span>level <span style="color: #66cc66;">&#40;</span>current<span style="color: #66cc66;">-</span>depth<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> seed <span style="color: #66cc66;">&#40;</span>hash<span style="color: #66cc66;">-</span>ref current<span style="color: #66cc66;">-</span>level 'seed<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">; If the tile doesn't already exist, generate it</span>
  <span style="color: #66cc66;">&#40;</span>unless <span style="color: #66cc66;">&#40;</span>hash<span style="color: #66cc66;">-</span>has<span style="color: #66cc66;">-</span>key? current<span style="color: #66cc66;">-</span>level <span style="color: #66cc66;">&#40;</span>pt x y<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #808080; font-style: italic;">; Get the new tile</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> new<span style="color: #66cc66;">-</span>tile <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>level<span style="color: #66cc66;">-</span>definition<span style="color: #66cc66;">-</span>tile<span style="color: #66cc66;">-</span>gen <span style="color: #66cc66;">&#40;</span>hash<span style="color: #66cc66;">-</span>ref current<span style="color: #66cc66;">-</span>level 'gen<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> seed x y<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>hash<span style="color: #66cc66;">-</span><span style="color: #b1b100;">set!</span> current<span style="color: #66cc66;">-</span>level <span style="color: #66cc66;">&#40;</span>pt x y<span style="color: #66cc66;">&#41;</span> new<span style="color: #66cc66;">-</span>tile<span style="color: #66cc66;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">; NPCs and items are only on walkable tiles</span>
    <span style="color: #66cc66;">&#40;</span>when <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get new<span style="color: #66cc66;">-</span>tile 'walkable<span style="color: #66cc66;">&#41;</span>
      <span style="color: #808080; font-style: italic;">; (Potentially) generate a new npc</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> new<span style="color: #66cc66;">-</span>npc <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>level<span style="color: #66cc66;">-</span>definition<span style="color: #66cc66;">-</span>npc<span style="color: #66cc66;">-</span>gen <span style="color: #66cc66;">&#40;</span>hash<span style="color: #66cc66;">-</span>ref current<span style="color: #66cc66;">-</span>level 'gen<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> seed x y<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>when <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">and</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">not</span> <span style="color: #66cc66;">&#40;</span>void? new<span style="color: #66cc66;">-</span>npc<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> new<span style="color: #66cc66;">-</span>npc<span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>new<span style="color: #66cc66;">-</span>npc <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing new<span style="color: #66cc66;">-</span>npc <span style="color: #66cc66;">&#91;</span>location <span style="color: #66cc66;">&#40;</span>pt x y<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
          <span style="color: #66cc66;">&#40;</span>hash<span style="color: #66cc66;">-</span><span style="color: #b1b100;">set!</span> current<span style="color: #66cc66;">-</span>level 'npcs <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> new<span style="color: #66cc66;">-</span>npc <span style="color: #66cc66;">&#40;</span>hash<span style="color: #66cc66;">-</span>ref current<span style="color: #66cc66;">-</span>level 'npcs<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
      <span style="color: #808080; font-style: italic;">; (Potentially) generate a new item for that tile</span>
      <span style="color: #808080; font-style: italic;">; Do not generate an item if there already is one (generated by the tile generation routine)</span>
      <span style="color: #66cc66;">&#40;</span>when <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">null?</span> <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get new<span style="color: #66cc66;">-</span>tile 'items '<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> new<span style="color: #66cc66;">-</span>item <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>level<span style="color: #66cc66;">-</span>definition<span style="color: #66cc66;">-</span>item<span style="color: #66cc66;">-</span>gen <span style="color: #66cc66;">&#40;</span>hash<span style="color: #66cc66;">-</span>ref current<span style="color: #66cc66;">-</span>level 'gen<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> seed x y<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>when <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">and</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">not</span> <span style="color: #66cc66;">&#40;</span>void? new<span style="color: #66cc66;">-</span>item<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> new<span style="color: #66cc66;">-</span>item<span style="color: #66cc66;">&#41;</span>
          <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>new<span style="color: #66cc66;">-</span>item <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing new<span style="color: #66cc66;">-</span>item<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span><span style="color: #b1b100;">set!</span> new<span style="color: #66cc66;">-</span>tile 'items <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> new<span style="color: #66cc66;">-</span>item <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get new<span style="color: #66cc66;">-</span>tile 'items<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">; Return the tile (newly generated or not)</span>
  <span style="color: #66cc66;">&#40;</span>hash<span style="color: #66cc66;">-</span>ref current<span style="color: #66cc66;">-</span>level <span style="color: #66cc66;">&#40;</span>pt x y<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>It has the same structure it always did, but now it&#8217;s nicely abstracted. The first chunk just generates a tile using the generation functions we defined earlier (<code>surface</code> and <code>shallow-caves</code>). The code to do that <code>((level-definition-tile-gen (hash-ref current-level 'gen)) seed x y)</code> is a bit ugly, but it works well enough.</p>
<p>After that (if and only if we have a <code>walkable</code> tile), try to generate an NPC. The NPC generation functions are going to look exactly like the tile functions, except the return entities rather than tiles and can return either <code>void</code> or <code>#f</code> if there&#8217;s no NPC in that location. So if we just want an empty world, we can always return <code>#f</code>:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; levels.rkt</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; No NPCs (also works for items)</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>nothing seed x y<span style="color: #66cc66;">&#41;</span> #f<span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>If we want a world full of rats (roughly 1% of the time):</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; levels.rkt</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; Look up a thing from a vector by 'name</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>lookup vec name<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span><span style="color: #66cc66;">/</span>ec <span style="color: #b1b100;">return</span>
    <span style="color: #66cc66;">&#40;</span>for <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>thing vec<span style="color: #66cc66;">&#93;</span>
          #:when <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">equal?</span> name <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get thing 'name #f<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">return</span> thing<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">return</span> #f<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; Rats. All of the rats.</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>rats<span style="color: #66cc66;">-</span>only seed x y<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>when <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">zero?</span> <span style="color: #66cc66;">&#40;</span>random <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>lookup <span style="color: #66cc66;">*</span>entities<span style="color: #66cc66;">*</span> <span style="color: #ff0000;">&quot;rat&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>The lookup function is so I can reuse those vectors of things I&#8217;ve been defining in <code>entities.rkt</code> and <code>items.rkt</code>. Basically, it finds the first <code>thing</code> with the given <code>'name</code> field.</p>
<p>Items work much the same way. If we want just the basic tier of items, we can do this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; levels.rkt</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; Only basic items</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>base<span style="color: #66cc66;">-</span>items seed x y<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>when <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">zero?</span> <span style="color: #66cc66;">&#40;</span>random <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">case</span> <span style="color: #66cc66;">&#40;</span>random <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>lookup <span style="color: #66cc66;">*</span>armors<span style="color: #66cc66;">*</span> <span style="color: #ff0000;">&quot;leather&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
      <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>lookup <span style="color: #66cc66;">*</span>weapons<span style="color: #66cc66;">*</span> <span style="color: #ff0000;">&quot;club&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
      <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>lookup <span style="color: #66cc66;">*</span>potions<span style="color: #66cc66;">*</span> <span style="color: #ff0000;">&quot;health potion&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
      <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>lookup <span style="color: #66cc66;">*</span>coins<span style="color: #66cc66;">*</span> <span style="color: #ff0000;">&quot;copper coin&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>(I added a new kind of item: <code>stackable</code>. Rather than replacing other items of a given type, they stack with them, combining quantities. Coins are currently the only stackable and at the moment, they&#8217;re completely worthless. But it&#8217;s a neat proof of concept. Check out the code <a title="Racket Roguelike on GitHub" href="https://github.com/jpverkamp/racket-roguelike">on GitHub</a> for more details.)</p>
<p>Okay. That&#8217;s basically everything to actually generate the levels. But we still have two fairly big problems:</p>
<ul>
<li>How does this hook up to the code we already have?</li>
<li>How do we get to different levels?</li>
</ul>
<p>For the first problem, we need to tweak <code>world.rkt</code>. Essentially, we renamed the <code>get-tile</code> function as <code>tile-at</code> and just wrapped <code>get-tile</code> from <code>levels.rkt</code>. Likewise with <code>update</code> and <code>update-npcs</code>. It&#8217;s pretty straight forward, check out the code <a title="Racket Roguelike on GitHub" href="https://github.com/jpverkamp/racket-roguelike">on GitHub</a> for more details.</p>
<p>The more interesting challenge is getting to different levels. The traditional way to do that in roguelikes is stairs. So we need a new tile type. But right now, we don&#8217;t have a way to attach events to tiles. So we&#8217;ll do both at once. Now, any tile can have an (optional) <code>on-enter</code> event, much like the <code>on-pickup</code> and <code>on-drop</code> events on items. Something like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; levels.rkt</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>define<span style="color: #66cc66;">-</span>thing stairs<span style="color: #66cc66;">-</span>up tile
  <span style="color: #66cc66;">&#91;</span>character #\<span style="color: #66cc66;">&amp;</span>lt<span style="color: #808080; font-style: italic;">;]</span>
  <span style="color: #66cc66;">&#91;</span>color <span style="color: #ff0000;">&quot;gold&quot;</span><span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#91;</span>walkable #t<span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>on<span style="color: #66cc66;">-</span>enter entity world<span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>when <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eq?</span> <span style="color: #66cc66;">&#40;</span>send world get<span style="color: #66cc66;">-</span>player<span style="color: #66cc66;">&#41;</span> entity<span style="color: #66cc66;">&#41;</span>
     <span style="color: #66cc66;">&#40;</span>ascend<span style="color: #66cc66;">&#41;</span>
     <span style="color: #66cc66;">&#40;</span>hash<span style="color: #66cc66;">-</span><span style="color: #b1b100;">set!</span> <span style="color: #66cc66;">&#40;</span>get<span style="color: #66cc66;">-</span>level <span style="color: #66cc66;">&#40;</span>current<span style="color: #66cc66;">-</span>depth<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> 
                <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get <span style="color: #66cc66;">&#40;</span>send world get<span style="color: #66cc66;">-</span>player<span style="color: #66cc66;">&#41;</span> 'location<span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing stairs<span style="color: #66cc66;">-</span>up<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p><code>stairs-up</code> will be much the same. Essentially, when the player enters a tile (the <code>when</code> keeps those pesky rats from using the stairs for the time being), they will call <code>ascend</code> which just sets the <code>current-depth</code> variable we defined earlier to one higher, which is all we would need, since the next rendering step will call <code>get-tile</code> which in turn calls <code>get-level</code>. Since there is no level yet (unless we leave the level and come back), a new one will be generated. That&#8217;s the beauty of the lazy tile generation setup we&#8217;re using.</p>
<p>The final chunk is particularly amusing. Basically, when you code up the stairs, it will generate the matching stairs on the next level. This isn&#8217;t perfect, since if you go back to a level you&#8217;ve already been on, the stairs will appear from nowhere. For now, we&#8217;ll consider this a &#8216;feature&#8217;. Hidden stairs. <img src='http://blog.jverkamp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Another problem is that there&#8217;s nothing stopping the stairs from popping up in the middle of a wall. Since stairs on only triggered by entering them, that will be game over. Clearly sub-optmimal, but that&#8217;s something we can save for later.</p>
<p>Speaking of which, how do we implement <code>on-enter</code>? Well, that&#8217;s where the <code>try-move</code> function in <code>world.rkt</code> comes in. Find the one place where the player can move (where the target is <code>walkable</code> and not otherwise occupied) and add this code:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; world.rkt</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; Look for an on-enter item</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> on<span style="color: #66cc66;">-</span>enter <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get tile 'on<span style="color: #66cc66;">-</span>enter #f<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>when on<span style="color: #66cc66;">-</span>enter
  <span style="color: #66cc66;">&#40;</span>on<span style="color: #66cc66;">-</span>enter entity this<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>And that&#8217;s all we need. Bam, z-levels. And it should be really easy to add more level definitions with all sorts of varied properties. One of these weeks (soon probably), I should actually work on balancing and adding a bunch of new content. That will be the last step for making a full game. But really, we&#8217;re basically there. All we really need still to have a game is more content and a way to win (It&#8217;s perfectly possible to lose right now, but winning? Not so much).</p>
<p>Before we go, how about a few more screenshots with stairs and all?</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/1-all-peaceful.png" rel="lightbox[4400]"><img class="alignnone wp-image-4408" alt="" src="http://blog.jverkamp.com/wp-content/uploads/2013/05/1-all-peaceful.png" width="300" height="187" /></a></p>
<p>Starting out, we&#8217;re in a nice peaceful field. All we really have to do is find some stairs (or wander off into infinity (and beyond!)).</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/2-going-down.png" rel="lightbox[4400]"><img class="alignnone wp-image-4409" alt="" src="http://blog.jverkamp.com/wp-content/uploads/2013/05/2-going-down.png" width="300" height="187" /></a></p>
<p>Found some stairs. Down we go!</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/3-into-the-caves.png" rel="lightbox[4400]"><img class="alignnone wp-image-4410" alt="" src="http://blog.jverkamp.com/wp-content/uploads/2013/05/3-into-the-caves.png" width="300" height="187" /></a></p>
<p>A nice little cavern. There are rats south and east and one of those nice new coins up north.</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/4-got-a-coin-killed-a-rat.png" rel="lightbox[4400]"><img class="alignnone wp-image-4411" alt="" src="http://blog.jverkamp.com/wp-content/uploads/2013/05/4-got-a-coin-killed-a-rat.png" width="300" height="187" /></a></p>
<p>Here we&#8217;ve grabbed the coin up north and killed the rat over by the potion. The coins have values based on the &#8220;gold standard&#8221; (1 gold = 10 silver = 100 copper, yay D&amp;D!), so it&#8217;s really not much. But since they don&#8217;t do anything anyways, it&#8217;s as good as gold!</p>
<p>Let&#8217;s try heading back up. Remember that other set of stairs? What happens if we take those?</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/5-up-down-wall.png" rel="lightbox[4400]"><img class="alignnone wp-image-4412" alt="" src="http://blog.jverkamp.com/wp-content/uploads/2013/05/5-up-down-wall.png" width="300" height="187" /></a></p>
<p>Oops. Yeah, I really should fix that. Now I&#8217;m in the middle of a wall and thus stuck. I really should add a way to manually trigger <code>on-enter</code> actions. We&#8217;ll see how that goes.</p>
<p>Well, that&#8217;s it for today. It&#8217;s really starting to look like a game now. <img src='http://blog.jverkamp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>As always, if you&#8217;d like to see all of the code for this project, you can do so on GitHub:<br />
- <a title="Racket Roguelike on GitHub" href="https://github.com/jpverkamp/racket-roguelike/tree/day-6">Racket Roguelike &#8211; Day 6</a><br />
- <a title="Racket Roguelike on GitHub" href="https://github.com/jpverkamp/racket-roguelike">Racket Roguelike &#8211; Up to date</a></p>
<p>If you&#8217;d like to try it yourself, you&#8217;ll need to have both <a href="http://git-scm.com/">Git</a> and <a href="http://racket-lang.org/">Racket</a> and run the following series of commands:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git clone</span> git:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>jpverkamp<span style="color: #000000; font-weight: bold;">/</span>racket-roguelike.git
<span style="color: #7a0874; font-weight: bold;">cd</span> racket-roguelike
<span style="color: #c20cb9; font-weight: bold;">git checkout</span> day-<span style="color: #000000;">6</span>
<span style="color: #c20cb9; font-weight: bold;">git submodule</span> init
<span style="color: #c20cb9; font-weight: bold;">git submodule</span> update
racket main.rkt</pre></td></tr></table></div>

<p>(Note: Sorry I&#8217;m a day late this week. Life&#8217;s been crazy between conference deadlines and getting married. One of these days I&#8217;ll actually actually write one of these posts ahead of time&#8230; Or not.)</p>
<p>For part 7, click here: <a href="http://blog.jverkamp.com/2013/05/17/racket-roguelike-7-into-darkness/" title="Racket Roguelike 7: Into darkness!">Racket Roguelike 7: Into darkness!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jverkamp.com/2013/05/10/racket-roguelike-6-dig-deeper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Iron Man 3</title>
		<link>http://blog.jverkamp.com/2013/05/05/iron-man-3/</link>
		<comments>http://blog.jverkamp.com/2013/05/05/iron-man-3/#comments</comments>
		<pubDate>Mon, 06 May 2013 03:55:02 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[Movies]]></category>
		<category><![CDATA[Other]]></category>

		<guid isPermaLink="false">http://blog.jverkamp.com/?p=4387</guid>
		<description><![CDATA[Go see Iron Man 3. I&#8217;ll wait. (There may be spoilers below, but hopefully nothing that wasn&#8217;t already in the trailers.) Based on the trailers, I wasn&#8217;t quite sure about Iron Man 3. I hoped it would at least be better than the second (which I originally enjoyed but on later viewings, particularly post Avengers, seems rather lacking) and at least as good as the first (still probably my favorite of the stand alone Marvel movies). I&#8217;m still digesting this new entry and will probably have to watch it at least a few more times to be fair, but I think it may actually do just that. It may even be better&#8230; As always, Robert Downey Jr. did an excellent job. he brought a touch of humor to the scenes that sorely needed it and played a worn Iron Man remarkably well. I&#8217;ve heard rumors that he may not do &#8230; <a href="http://blog.jverkamp.com/2013/05/05/iron-man-3/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/Iron-Man-3.jpg" rel="lightbox[4387]"><img src="http://blog.jverkamp.com/wp-content/uploads/2013/05/Iron-Man-3.jpg" alt="" width="214" height="317" class="alignright size-full wp-image-4391" /></a></p>
<p>Go see Iron Man 3. I&#8217;ll wait.</p>
<p><span id="more-4387"></span> </p>
<p>(There may be spoilers below, but hopefully nothing that wasn&#8217;t already in the trailers.)</p>
<p>Based on the trailers, I wasn&#8217;t quite sure about Iron Man 3. I hoped it would at least be better than the second (which I originally enjoyed but on later viewings, particularly post Avengers, seems rather lacking) and at least as good as the first (still probably my favorite of the stand alone Marvel movies). I&#8217;m still digesting this new entry and will probably have to watch it at least a few more times to be fair, but I think it may actually do just that. It may even be better&#8230;</p>
<p>As always, <a href="http://www.imdb.com/name/nm0000375/?ref_=tt_cl_t1" title="Robert Downey Jr. on IMDb">Robert Downey Jr.</a> did an excellent job. he brought a touch of humor to the scenes that sorely needed it and played a worn Iron Man remarkably well. I&#8217;ve heard rumors that he may not do an Iron Man 4 (although there&#8217;s still the second Avengers) and, honestly, if that was the case, I wouldn&#8217;t be that upset. I&#8217;m not sure where they could go with Iron Man after this and I thought they did a pretty good, really surprisingly good job of wrapping everything up. </p>
<p>As for the rest of the cast, I think this was <a href="http://www.imdb.com/name/nm0000569/?ref_=tt_cl_t2" title="Gwyneth Paltrow on IMDb">Gwyneth Paltrow&#8217;s</a> best Iron Man movie as well. I won&#8217;t give too much away, but her parts in the middle (around the attack on Stark&#8217;s house we see in the trailers) and at the end are amazing. And she really helps ground the movie in her reactions to Stark&#8217;s behavior. It&#8217;s about time.</p>
<p><a href="http://www.imdb.com/name/nm0001426/?ref_=tt_cl_t7" title="Ben Kingsley on IMDb">Ben Kingsley</a> as <a href="http://www.imdb.com/character/ch0036533/?ref_=tt_cl_t7" title="The Mandarin">The Mandarin</a> really steals the show though, for the parts that he&#8217;s in. I haven&#8217;t actually read his parts from the comic books, but I&#8217;m pretty sure that the movie version is a fairly significant departure&#8211;and it works great. He really has a strong progression throughout the movie and Ben Kingsley did an amazing job on that. </p>
<p>It was a little weird that the movie is set around Christmas time, particularly given an early summer release. I realize that it&#8217;s very much a summer blockbuster and they they never would have gone for a winter release, but it&#8217;s still a little disorienting. Perhaps I&#8217;ll re-watch it again in about 7 months and see if it changes at all. <img src='http://blog.jverkamp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>One thing that did seem a little strange was how they basically went directly against the idea of the second film though. In the second, the entire point seemed to be that a man in a suit would always be superior to an AI-controlled robot. Yet that&#8217;s pretty much what saves the day when Stark activates his &#8216;reinforcements&#8217;. Theoretically I guess they could have been controlled by Stark himself somehow, but I think the strong implication is that Jarvis is in the driver&#8217;s seat (which is really pretty impressive when you think about it&#8230;).</p>
<p>On an only semi-related note, I knew that since I was seeing it opening weekend, the theater would be crowded. I was a little amazed though at just how many young kids there were though. I&#8217;d say easily half of the audience was under the age of 13&#8230; And there was even at least one infant that I saw. Really, that&#8217;s a decision that every parent has the right to make and I can&#8217;t make it for them&#8211;but think about it this way, the movie isn&#8217;t going anywhere. It will still be there when they&#8217;re older.</p>
<p>Overall, Iron Man 3 takes my top spot. It&#8217;s great fun, particularly if you&#8217;ve seen all of the other Marvel features. It may or may not end up the best movie of the year, but given what&#8217;s in theaters right now, it&#8217;s certainly worth your time and money. </p>
<p><strong><a href="http://blog.jverkamp.com/lists/2013-movie-rankings/" title="My 2013 Movie Rankings">My 2013 Movie Rankings</a></strong></p>
<ol>
<li><a title="Iron Man 3" href="http://blog.jverkamp.com/2013/05/05/iron-man-3/">Iron Man 3</a></li>
<li><a title="The Croods" href="http://blog.jverkamp.com/2013/04/08/the-croods/">The Croods</a></li>
<li><a title="Django Unchained" href="http://blog.jverkamp.com/2013/01/22/django-unchained/">Django Unchained</a></li>
<li><a title="Parental Guidance" href="http://blog.jverkamp.com/2013/01/27/parental-guidance/">Parental Guidance</a></li>
<li><a title="Oblivion" href="http://blog.jverkamp.com/2013/04/24/oblivion/">Oblivion</a></li>
<li><a title="Beautiful Creatures" href="http://blog.jverkamp.com/2013/02/17/beautiful-creatures/">Beautiful Creatures</a></li>
<li><a title="Jurassic Park (3D!)" href="http://blog.jverkamp.com/2013/05/01/jurassic-park-3d/">Jurassic Park (3D!)</a></li>
<li><a title="Oz the Great and Powerful" href="http://blog.jverkamp.com/2013/03/10/oz-the-great-and-powerful/">Oz the Great and Powerful</a></li>
<li><a title="Hansel &amp; Gretel: Witch Hunters" href="http://blog.jverkamp.com/2013/02/13/hansel-gretel-witch-hunters/">Hansel &amp; Gretel: Witch Hunters</a></li>
<li><a title="Jack the Giant Slayer" href="http://blog.jverkamp.com/2013/03/12/jack-the-giant-slayer/">Jack the Giant Slayer</a></li>
<li><a title="Warm Bodies" href="http://blog.jverkamp.com/2013/02/26/warm-bodies/">Warm Bodies</a></li>
<li><a title="G.I. Joe: Retaliation" href="http://blog.jverkamp.com/2013/04/03/g-i-joe-retaliation/">G.I. Joe: Retaliation</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.jverkamp.com/2013/05/05/iron-man-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Racket Roguelike 5: Armors and weapons and potions, oh my!</title>
		<link>http://blog.jverkamp.com/2013/05/02/racket-roguelike-5-armors-and-weapons-and-potions-oh-my/</link>
		<comments>http://blog.jverkamp.com/2013/05/02/racket-roguelike-5-armors-and-weapons-and-potions-oh-my/#comments</comments>
		<pubDate>Thu, 02 May 2013 13:00:50 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Racket Roguelike]]></category>
		<category><![CDATA[Racket]]></category>
		<category><![CDATA[Roguelike]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.jverkamp.com/?p=4372</guid>
		<description><![CDATA[Another week, another step towards building a roguelike in Racket. This week, we&#8217;re going to build another basic system (like the critters) that can easily be expanded with all sorts of crazy content: items and inventory. If you&#8217;d like to start at the beginning, click here: Racket Roguelike 1: A GUI, screens, I/O, and you! This time around, let&#8217;s start with the kinds of items that we want to support. As you may have guessed from the post title, we&#8217;ll start with three: armor, weapons, and potions for boosted attack, defense, and temporary effects in turn. First, we need a base thing on which we can base all of the rest of the items: ; items.rkt &#160; ; All items have: ; - a display char/item if they're on the ground ; - if they're consumed or not (picked up) ; - methods for: ; -- being picked up ; &#8230; <a href="http://blog.jverkamp.com/2013/05/02/racket-roguelike-5-armors-and-weapons-and-potions-oh-my/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Another week, another step towards building a roguelike in Racket. This week, we&#8217;re going to build another basic system (like the critters) that can easily be expanded with all sorts of crazy content: items and inventory.</p>
<p><span id="more-4372"></span></p>
<p>If you&#8217;d like to start at the beginning, click here: <a href="http://blog.jverkamp.com/2013/04/04/racket-roguelike-1-a-gui-screens-io-and-you/" title="Racket Roguelike 1: A GUI, screens, I/O, and you!">Racket Roguelike 1: A GUI, screens, I/O, and you!</a></p>
<p>This time around, let&#8217;s start with the kinds of items that we want to support. As you may have guessed from the post title, we&#8217;ll start with three: armor, weapons, and potions for boosted attack, defense, and temporary effects in turn. </p>
<p>First, we need a base <code>thing</code> on which we can base all of the rest of the items:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; items.rkt</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; All items have:</span>
<span style="color: #808080; font-style: italic;">; - a display char/item if they're on the ground</span>
<span style="color: #808080; font-style: italic;">; - if they're consumed or not (picked up)</span>
<span style="color: #808080; font-style: italic;">; - methods for:</span>
<span style="color: #808080; font-style: italic;">; -- being picked up</span>
<span style="color: #808080; font-style: italic;">; -- being dropped</span>
<span style="color: #66cc66;">&#40;</span>define<span style="color: #66cc66;">-</span>thing item
  <span style="color: #66cc66;">&#91;</span>character #\x<span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#91;</span>color <span style="color: #ff0000;">&quot;white&quot;</span><span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#91;</span>consumable #f<span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#91;</span>category 'unknown<span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>on<span style="color: #66cc66;">-</span>pick<span style="color: #66cc66;">-</span>up item entity world<span style="color: #66cc66;">&#41;</span>   <span style="color: #66cc66;">&#40;</span>void<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>on<span style="color: #66cc66;">-</span>drop item entity world<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>void<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>First, we have the basic display features all of our items have. Then we have a flag that basically identifies if you can wear an item (<code>(not consumable)</code>) or if you consume it immediately (<code>consumable</code>). </p>
<p>Next, we have a category. Basically, our model will be that you can hold one item of each category at a given time. This way, you can have one kind of armor and one weapon and that&#8217;s it. That will save us from having to make any sort of complicated inventory, although this same system could be adapted to a more flexible category to maximum count mapping.</p>
<p>Finally, we have two methods. I really do love functional programming when things like this come up. Basically (as should be obvious from the names), the first method will be called when them item is picked up (also when a consumable item is used), the second when it&#8217;s dropped (never called for consumables). </p>
<p>So how does this work for an armor definition?</p>
<p>Well, we&#8217;ll start with this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; items.rkt</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; Armor protects the wearer</span>
<span style="color: #66cc66;">&#40;</span>define<span style="color: #66cc66;">-</span>thing armor item
  <span style="color: #66cc66;">&#91;</span>character #\<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#91;</span>defense <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#91;</span>category 'armor<span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>on<span style="color: #66cc66;">-</span>pick<span style="color: #66cc66;">-</span>up item entity world<span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span><span style="color: #b1b100;">set!</span> entity 'defense <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">+</span> <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get entity 'defense<span style="color: #66cc66;">&#41;</span>
                                  <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get item 'defense<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>                               
  <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>on<span style="color: #66cc66;">-</span>drop item entity world<span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span><span style="color: #b1b100;">set!</span> entity 'defense <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">-</span> <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get entity 'defense<span style="color: #66cc66;">&#41;</span>
                                  <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get item 'defense<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">*</span>armors<span style="color: #66cc66;">*</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">vector</span>
   <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing armor <span style="color: #66cc66;">&#91;</span>name <span style="color: #ff0000;">&quot;leather&quot;</span><span style="color: #66cc66;">&#93;</span>   <span style="color: #66cc66;">&#91;</span>color <span style="color: #ff0000;">&quot;brown&quot;</span><span style="color: #66cc66;">&#93;</span>  <span style="color: #66cc66;">&#91;</span>defense <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing armor <span style="color: #66cc66;">&#91;</span>name <span style="color: #ff0000;">&quot;chain&quot;</span><span style="color: #66cc66;">&#93;</span>     <span style="color: #66cc66;">&#91;</span>color <span style="color: #ff0000;">&quot;gray&quot;</span><span style="color: #66cc66;">&#93;</span>   <span style="color: #66cc66;">&#91;</span>defense <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing armor <span style="color: #66cc66;">&#91;</span>name <span style="color: #ff0000;">&quot;plate&quot;</span><span style="color: #66cc66;">&#93;</span>     <span style="color: #66cc66;">&#91;</span>color <span style="color: #ff0000;">&quot;white&quot;</span><span style="color: #66cc66;">&#93;</span>  <span style="color: #66cc66;">&#91;</span>defense <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing armor <span style="color: #66cc66;">&#91;</span>name <span style="color: #ff0000;">&quot;enchanted&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>color <span style="color: #ff0000;">&quot;purple&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>defense <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>Basically, we set the character, category, and behavior in a base thing. Then all the further definitions have to do is override the name, color, and specific value. The behavior will be copied over just fine.</p>
<p>Similarly, we can define weapons (the base definition is the same except using <code>'attack</code> instead of <code>'defense</code>):</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; items.rkt</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">*</span>weapons<span style="color: #66cc66;">*</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">vector</span>
   <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing weapon <span style="color: #66cc66;">&#91;</span>name <span style="color: #ff0000;">&quot;club&quot;</span><span style="color: #66cc66;">&#93;</span>        <span style="color: #66cc66;">&#91;</span>color <span style="color: #ff0000;">&quot;brown&quot;</span><span style="color: #66cc66;">&#93;</span>  <span style="color: #66cc66;">&#91;</span>attack <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing weapon <span style="color: #66cc66;">&#91;</span>name <span style="color: #ff0000;">&quot;dagger&quot;</span><span style="color: #66cc66;">&#93;</span>      <span style="color: #66cc66;">&#91;</span>color <span style="color: #ff0000;">&quot;gray&quot;</span><span style="color: #66cc66;">&#93;</span>   <span style="color: #66cc66;">&#91;</span>attack <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing weapon <span style="color: #66cc66;">&#91;</span>name <span style="color: #ff0000;">&quot;battle axe&quot;</span><span style="color: #66cc66;">&#93;</span>  <span style="color: #66cc66;">&#91;</span>color <span style="color: #ff0000;">&quot;white&quot;</span><span style="color: #66cc66;">&#93;</span>  <span style="color: #66cc66;">&#91;</span>attack <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing weapon <span style="color: #66cc66;">&#91;</span>name <span style="color: #ff0000;">&quot;longsword&quot;</span><span style="color: #66cc66;">&#93;</span>   <span style="color: #66cc66;">&#91;</span>color <span style="color: #ff0000;">&quot;white&quot;</span><span style="color: #66cc66;">&#93;</span>  <span style="color: #66cc66;">&#91;</span>attack <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing weapon <span style="color: #66cc66;">&#91;</span>name <span style="color: #ff0000;">&quot;magic sword&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>color <span style="color: #ff0000;">&quot;purple&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>attack <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>Finally, we have the actual consumables. Specifically, potions. Right now, there&#8217;s really only one potion that makes sense, but the framework is more than flexible enough to do just about anything. Perhaps next week I&#8217;ll start in on mutable terrain. <img src='http://blog.jverkamp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; items.rkt</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; Potions are single use and consumed on contact</span>
<span style="color: #66cc66;">&#40;</span>define<span style="color: #66cc66;">-</span>thing potion item
  <span style="color: #66cc66;">&#91;</span>character #\<span style="color: #66cc66;">!</span><span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#91;</span>category 'potion<span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#91;</span>consumable #t<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">*</span>potions<span style="color: #66cc66;">*</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">vector</span>
   <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing potion
     <span style="color: #66cc66;">&#91;</span>name <span style="color: #ff0000;">&quot;health potion&quot;</span><span style="color: #66cc66;">&#93;</span>
     <span style="color: #66cc66;">&#91;</span>color <span style="color: #ff0000;">&quot;red&quot;</span><span style="color: #66cc66;">&#93;</span>
     <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>on<span style="color: #66cc66;">-</span>pick<span style="color: #66cc66;">-</span>up item entity world<span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span><span style="color: #b1b100;">set!</span> entity 'health <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">10</span> <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get entity 'health<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>Now all you have to do is walk over a potion and you&#8217;ll feel much better. </p>
<p>So now we have a bunch of items, how do we tie them into the rest of the framework?</p>
<p>First, we need to be able to store them. Since we eventually want any entity (player or enemy) to hold an item, we&#8217;ll add the inventory all of the way back at the base <code>entity</code> thing:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; entities.rkt</span>
<span style="color: #66cc66;">&#40;</span>define<span style="color: #66cc66;">-</span>thing entity
  ...
  <span style="color: #66cc66;">&#91;</span>inventory '<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>That will cascade through to all players and enemies.</p>
<p>Next, we need to do the same to tiles on the ground so that we can have items just lying about:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; world.rkt</span>
<span style="color: #66cc66;">&#40;</span>define<span style="color: #66cc66;">-</span>thing tile
  ...
  <span style="color: #66cc66;">&#91;</span>items '<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>Now, we have to actually generate some items lying around. Luckily, we can use almost exactly the same code that we used to generate the wandering monsters. Any time a tile is generated, there&#8217;s a small chance of generating a random item as well.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; world.rkt</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; Sometimes even more rarely, generate some sort of treasure</span>
<span style="color: #66cc66;">&#40;</span>when <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">and</span> <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get new<span style="color: #66cc66;">-</span>tile 'walkable<span style="color: #66cc66;">&#41;</span>
           <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&lt;</span> <span style="color: #66cc66;">&#40;</span>random <span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> new<span style="color: #66cc66;">-</span>item
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>base <span style="color: #66cc66;">&#40;</span>vector<span style="color: #66cc66;">-</span>choose<span style="color: #66cc66;">-</span>biased <span style="color: #66cc66;">&#40;</span>vector<span style="color: #66cc66;">-</span>choose<span style="color: #66cc66;">-</span>random <span style="color: #66cc66;">*</span>all<span style="color: #66cc66;">-</span>items<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>thing base<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
  <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span><span style="color: #b1b100;">set!</span> new<span style="color: #66cc66;">-</span>tile 'items <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> new<span style="color: #66cc66;">-</span>item <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get new<span style="color: #66cc66;">-</span>tile 'items<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>As we did with the new creatures and tiles, we wrap the items with a call to <code>make-thing</code>, making this item distinct from the base definition. Right now, there&#8217;s no way to mutate items, but in the future we might want to have durability or some such&#8211;this will prevent all swords in the world from breaking when you swing any one of them. </p>
<p>So now we have items in the world, but we still can&#8217;t see them. So we need to go over to the <code>game-screen</code> and modify the draw routine. Where previously the lowest layer was to draw the tile, now it will draw the tile if there&#8217;s no item or the first item if there&#8217;s at least one.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; game-screen.rkt</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> tile <span style="color: #66cc66;">&#40;</span>send world get<span style="color: #66cc66;">-</span>tile <span style="color: #66cc66;">&#40;</span>pt<span style="color: #66cc66;">-</span>x x<span style="color: #66cc66;">/</span>y<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>pt<span style="color: #66cc66;">-</span>y x<span style="color: #66cc66;">/</span>y<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span>
  <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">null?</span> <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get tile 'items '<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>send canvas <span style="color: #b1b100;">write</span>
         <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get tile 'character<span style="color: #66cc66;">&#41;</span>
         xi
         yi
         <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get tile 'color<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
  <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">else</span>
   <span style="color: #66cc66;">&#40;</span>send canvas <span style="color: #b1b100;">write</span>
         <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get tile 'items<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> 'character<span style="color: #66cc66;">&#41;</span>
         xi
         yi
         <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get tile 'items<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> 'color<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>It&#8217;s a bit ugly (so much duplicated code), but for the moment it will work. </p>
<p>Well, now that we&#8217;re generating them, what does it actually look like?</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/random-items.png" rel="lightbox[4372]"><img src="http://blog.jverkamp.com/wp-content/uploads/2013/05/random-items.png" alt="" width="300" height="188" class="alignnone wp-image-4374" /></a> </p>
<p>If you look to the left of the player, there&#8217;s a nice gray <code>]</code> just sitting there. If I remember the definitions correctly, that&#8217;s chain armor. If only we could actually pick it up&#8230;</p>
<p>(I made the screen a bit larger so we have room for the player inventory to print, which we&#8217;ll get to shortly. It should still be reasonable on most people&#8217;s screens.)</p>
<p>Well, for that, we can tie into the movement code. The only time that we could pick up an item is when we walk into it, so it has to be a walkable, unoccupied tile. We want to pick up any items we walk over, drop any items that have the category of one we just picked up, and directly consume and consumables. It&#8217;s a bit of code, so let&#8217;s just take a look first:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; world.rkt</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; If it's walkable and not occupied, update the location</span>
<span style="color: #808080; font-style: italic;">; Also, pick up any items there, exchanging if types match</span>
<span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">null?</span> others<span style="color: #66cc66;">&#41;</span>
 <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span><span style="color: #b1b100;">set!</span> entity 'location target<span style="color: #66cc66;">&#41;</span>
&nbsp;
 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>pick<span style="color: #66cc66;">-</span>up item<span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span><span style="color: #b1b100;">set!</span> entity 'inventory <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> item <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get entity 'inventory<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span><span style="color: #b1b100;">set!</span> tile 'items <span style="color: #66cc66;">&#40;</span>remove item <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get tile 'items<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>call item 'on<span style="color: #66cc66;">-</span>pick<span style="color: #66cc66;">-</span>up item entity this<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>drop item<span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span><span style="color: #b1b100;">set!</span> entity 'inventory <span style="color: #66cc66;">&#40;</span>remove item <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get entity 'inventory<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span><span style="color: #b1b100;">set!</span> tile 'items <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> item <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get tile 'items<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>call item 'on<span style="color: #66cc66;">-</span>drop item entity this<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>consume item<span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span><span style="color: #b1b100;">set!</span> tile 'items <span style="color: #66cc66;">&#40;</span>remove item <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get tile 'items<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>call item 'on<span style="color: #66cc66;">-</span>pick<span style="color: #66cc66;">-</span>up item entity this<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
 <span style="color: #808080; font-style: italic;">; For each item on the ground</span>
 <span style="color: #66cc66;">&#40;</span>for <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>item <span style="color: #66cc66;">&#40;</span>in<span style="color: #66cc66;">-</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get tile 'items<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #808080; font-style: italic;">; Remove same typed items from the inventory</span>
   <span style="color: #66cc66;">&#40;</span>for <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>in<span style="color: #66cc66;">-</span>inv <span style="color: #66cc66;">&#40;</span>in<span style="color: #66cc66;">-</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get entity 'inventory<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         #:when <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eq?</span> <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get item 'category<span style="color: #66cc66;">&#41;</span>
                     <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get in<span style="color: #66cc66;">-</span>inv 'category<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
     <span style="color: #66cc66;">&#40;</span>drop in<span style="color: #66cc66;">-</span>inv<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
   <span style="color: #808080; font-style: italic;">; Pick up or consume the item</span>
   <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>thing<span style="color: #66cc66;">-</span>get item 'consumable<span style="color: #66cc66;">&#41;</span>
       <span style="color: #66cc66;">&#40;</span>consume item<span style="color: #66cc66;">&#41;</span>
       <span style="color: #66cc66;">&#40;</span>pick<span style="color: #66cc66;">-</span>up item<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span></pre></td></tr></table></div>

<p>That should be relatively straight forward. And it actually works out great:</p>
<p>Here&#8217;s another nice bit of chainmail just lying there for us.</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/ooh-shiny.png" rel="lightbox[4372]"><img src="http://blog.jverkamp.com/wp-content/uploads/2013/05/ooh-shiny.png" alt="" width="300" height="188" class="alignnone wp-image-4377" /></a></p>
<p>Walk right over it to put it on. You can see the armor we&#8217;re currently wearing in the top left, along with the boost in defense we got (note: Things are totally unbalanced right now. That&#8217;s a post all to itself.)</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/invincible.png" rel="lightbox[4372]"><img src="http://blog.jverkamp.com/wp-content/uploads/2013/05/invincible.png" alt="" width="300" height="188" class="alignnone wp-image-4376" /></a></p>
<p>Then we wander about a bit more. Hit a few bombs (those things <strong>hurt</strong>!). A bit of a pick-me-up would come in handy about now.</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/think-i-need-that.png" rel="lightbox[4372]"><img src="http://blog.jverkamp.com/wp-content/uploads/2013/05/think-i-need-that.png" alt="" width="300" height="188" class="alignnone wp-image-4379" /></a></p>
<p>Walk over it and drink it up:</p>
<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/ahhh.png" rel="lightbox[4372]"><img src="http://blog.jverkamp.com/wp-content/uploads/2013/05/ahhh.png" alt="" width="300" height="188" class="alignnone wp-image-4375" /></a></p>
<p>Everything seems to be working well. </p>
<p>That&#8217;s all we have today. I&#8217;m thinking about doing some line of sight calculations for next week (the screen is getting rather cluttered&#8230;). We&#8217;ll see if I haven&#8217;t changed my mind by then though. <img src='http://blog.jverkamp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>As always, if you&#8217;d like to see all of the code for this project, you can do so on GitHub:<br />
- <a href="https://github.com/jpverkamp/racket-roguelike/tree/day-5" title="Racket Roguelike on GitHub">Racket Roguelike &#8211; Day 5</a><br />
- <a href="https://github.com/jpverkamp/racket-roguelike" title="Racket Roguelike on GitHub">Racket Roguelike &#8211; Up to date</a></p>
<p>If you&#8217;d like to try it yourself, you&#8217;ll need to have both <a href="http://git-scm.com/">Git</a> and <a href="http://racket-lang.org/">Racket</a> and run the following series of commands:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git clone</span> git:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>jpverkamp<span style="color: #000000; font-weight: bold;">/</span>racket-roguelike.git
<span style="color: #7a0874; font-weight: bold;">cd</span> racket-roguelike
<span style="color: #c20cb9; font-weight: bold;">git checkout</span> day-<span style="color: #000000;">5</span>
<span style="color: #c20cb9; font-weight: bold;">git submodule</span> init
<span style="color: #c20cb9; font-weight: bold;">git submodule</span> update
racket main.rkt</pre></td></tr></table></div>

<p>For part 6, click here: <a href="http://blog.jverkamp.com/2013/05/10/racket-roguelike-6-dig-deeper/" title="Racket Roguelike 6: Dig deeper!">Racket Roguelike 6: Dig deeper!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jverkamp.com/2013/05/02/racket-roguelike-5-armors-and-weapons-and-potions-oh-my/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jurassic Park (3D!)</title>
		<link>http://blog.jverkamp.com/2013/05/01/jurassic-park-3d/</link>
		<comments>http://blog.jverkamp.com/2013/05/01/jurassic-park-3d/#comments</comments>
		<pubDate>Thu, 02 May 2013 03:55:53 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[Movies]]></category>
		<category><![CDATA[Other]]></category>

		<guid isPermaLink="false">http://blog.jverkamp.com/?p=4386</guid>
		<description><![CDATA[I wasn&#8217;t actually sure if I wanted to add this to my 2013 Movie Rankings, since really this isn&#8217;t a new movie for 2013. But in the end, it is a movie and I did see it, so it seems worthwhile to post about. For the most part, Jurassic Park1 has held up amazingly well over the intervening 202 years. Some of science is a bit dodgy&#8211;for example, we&#8217;re now pretty sure that dinosaurs would have had feathers3&#8211;but it&#8217;s still a nicely intense look at how dinosaurs and people just really wouldn&#8217;t / shouldn&#8217;t mix. Two things that really did annoy me about the movie (now just as much as the first time I watched it) were Jeff Goldblum&#8217;s Dr. Malcom and Wayne Knight&#8217;s Dennis Nedry. For the former, his constant obsession with chaos theory despite just sort of spewing words that only vaguely relate to the field he&#8217;s supposed &#8230; <a href="http://blog.jverkamp.com/2013/05/01/jurassic-park-3d/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://blog.jverkamp.com/wp-content/uploads/2013/05/Jurassic-Park-3D.jpg" rel="lightbox[4386]"><img class="alignright size-full wp-image-4390" alt="" src="http://blog.jverkamp.com/wp-content/uploads/2013/05/Jurassic-Park-3D.jpg" width="214" height="339" /></a> I wasn&#8217;t actually sure if I wanted to add this to my 2013 Movie Rankings, since really this isn&#8217;t a new movie for 2013. But in the end, it is a movie and I did see it, so it seems worthwhile to post about. <img src='http://blog.jverkamp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><span id="more-4386"></span></p>
<p>For the most part, <a title="Wikipedia: Jurassic Park (film)" href="https://en.wikipedia.org/wiki/Jurassic_Park_%28film%29">Jurassic Park</a><sup><a href="http://blog.jverkamp.com/2013/05/01/jurassic-park-3d/#footnote_0_4386" id="identifier_0_4386" class="footnote-link footnote-identifier-link" title="I still have problems spelling that correctly&hellip;">1</a></sup> has held up amazingly well over the intervening 20<sup><a href="http://blog.jverkamp.com/2013/05/01/jurassic-park-3d/#footnote_1_4386" id="identifier_1_4386" class="footnote-link footnote-identifier-link" title="Holy crap">2</a></sup> years. Some of science is a bit dodgy&#8211;for example, we&#8217;re now pretty sure that dinosaurs would have had feathers<sup><a href="http://blog.jverkamp.com/2013/05/01/jurassic-park-3d/#footnote_2_4386" id="identifier_2_4386" class="footnote-link footnote-identifier-link" title="A fact that the upcoming Jurassic Park sequel is apparently going to happily ignore">3</a></sup>&#8211;but it&#8217;s still a nicely intense look at how dinosaurs and people just really wouldn&#8217;t / shouldn&#8217;t mix.</p>
<p>Two things that really did annoy me about the movie (now just as much as the first time I watched it) were <a href="http://www.imdb.com/name/nm0000156/?ref_=tt_cl_t3" title="Jeff Goldblum on IMDb">Jeff Goldblum&#8217;s</a> <a href="http://www.imdb.com/character/ch0002031/?ref_=tt_cl_t3" title="Dr. Malcom on IMDb">Dr. Malcom</a> and <a href="http://www.imdb.com/name/nm0001431/?ref_=tt_cl_t11" title="Wayne Knight on IMDb">Wayne Knight&#8217;s</a> <a href="http://www.imdb.com/character/ch0002044/?ref_=tt_cl_t11" title="Dennis Nedry">Dennis Nedry</a>. For the former, his constant obsession with <a href="https://en.wikipedia.org/wiki/Chaos_theory" title="Wikipedia: Chaos theory">chaos theory</a> despite just sort of spewing words that only vaguely relate to the field he&#8217;s supposed to have a doctorate in. Logically, I know that it&#8217;s yet another instance of knowing more about a field that I&#8217;m personally very interested in than the film&#8217;s producer&#8217;s did<sup><a href="http://blog.jverkamp.com/2013/05/01/jurassic-park-3d/#footnote_3_4386" id="identifier_3_4386" class="footnote-link footnote-identifier-link" title="Or, if you want to be generous, than they thought that the audience could handle">4</a></sup>, but it still irks me. Chaos theory is fascinating. He just makes it sound annoying.</p>
<p>Speaking of which&#8230; Oh Dennis Nedry. I know that we&#8217;re <em>supposed</em> to dislike him, but eesh. Granted, it was a different world back in 1993. I was only barely getting into computers myself<sup><a href="http://blog.jverkamp.com/2013/05/01/jurassic-park-3d/#footnote_4_4386" id="identifier_4_4386" class="footnote-link footnote-identifier-link" title="I&rsquo;ll leave that as an exercise for the reader to work out just how young I was back then  ">5</a></sup>. But if he really thought he was being treated so absolutely terribly, why didn&#8217;t he just leave? There was probably some sort of contract in place, given the nature of the park and all, but then why did he take the job in the first place? </p>
<p>As a side note though, I&#8217;ll actually speak against the crowd and say that I really liked the scene where <a href="http://www.imdb.com/character/ch0002041/?ref_=tt_cl_t8" title="Lex Murphy on IMDb">Lex (the sister)</a> &#8216;hacks&#8217; into the Unix machine and turns on the door controls. People give that scene a lot of crap, saying that of course that&#8217;s not how computers really work. But it turns out that it actually was an experimental 3D file system viewer known as <a href="https://en.wikipedia.org/wiki/Fsn" title="fsn on Wikipedia"><code>fsn</code> or &#8216;fusion&#8217;</a>. Granted, it was never actually finished, but I really can imagine someone like Nedry installing it on the system, mostly just as a form of job security. People also say that even if the line &#8220;It&#8217;s a UNIX system! I know this!&#8221; is a bit over the top, it&#8217;s not <em>that</em> far off from how you would actually go about making use of an unfamiliar system in a time-critical environment: make your best guess based on domain knowledge and what the system is telling you and hope for the best. </p>
<p>On a positive note, the technology that made the movie famous&#8211;the dinosaurs&#8211;has held up really well. In parts, the dinosaurs do look a bit fake (mostly the eyes and when they don&#8217;t have quite a large enough field of motion), but I&#8217;m frankly amazed at how good a lot of the action scenes look even now. Say what you will about the differences between modern CGI and the effects of days gone by, but I really didn&#8217;t have a problem believing that they really <em>were</em> about to be eaten by dinosaurs. </p>
<p>Overall, it&#8217;s a solid movie. If you liked the original, go ahead and check it out in 3D. The conversion was well done (even if I don&#8217;t get the full effect due to an imbalance in my vision) and added a lot. It was nice to have 3D scenes that worked without a reliance on being in 3D<sup><a href="http://blog.jverkamp.com/2013/05/01/jurassic-park-3d/#footnote_5_4386" id="identifier_5_4386" class="footnote-link footnote-identifier-link" title="Any scene ever that throws things at the audience, I&rsquo;m looking at you!">6</a></sup>. Still, this year has been pretty good for movies. Based purely on my own enjoyment (which is, after all, what this rankings are based on), Jurassic Park fits right down the middle of the line.</p>
<p><strong><a href="http://blog.jverkamp.com/lists/2013-movie-rankings/" title="My 2013 Movie Rankings">My 2013 Movie Rankings</a></strong></p>
<ol>
<li><a title="The Croods" href="http://blog.jverkamp.com/2013/04/08/the-croods/">The Croods</a></li>
<li><a title="Django Unchained" href="http://blog.jverkamp.com/2013/01/22/django-unchained/">Django Unchained</a></li>
<li><a title="Parental Guidance" href="http://blog.jverkamp.com/2013/01/27/parental-guidance/">Parental Guidance</a></li>
<li><a title="Oblivion" href="http://blog.jverkamp.com/2013/04/24/oblivion/">Oblivion</a></li>
<li><a title="Beautiful Creatures" href="http://blog.jverkamp.com/2013/02/17/beautiful-creatures/">Beautiful Creatures</a></li>
<li><a title="Jurassic Park (3D!)" href="http://blog.jverkamp.com/2013/05/01/jurassic-park-3d/">Jurassic Park (3D!)</a></li>
<li><a title="Oz the Great and Powerful" href="http://blog.jverkamp.com/2013/03/10/oz-the-great-and-powerful/">Oz the Great and Powerful</a></li>
<li><a title="Hansel &amp; Gretel: Witch Hunters" href="http://blog.jverkamp.com/2013/02/13/hansel-gretel-witch-hunters/">Hansel &amp; Gretel: Witch Hunters</a></li>
<li><a title="Jack the Giant Slayer" href="http://blog.jverkamp.com/2013/03/12/jack-the-giant-slayer/">Jack the Giant Slayer</a></li>
<li><a title="Warm Bodies" href="http://blog.jverkamp.com/2013/02/26/warm-bodies/">Warm Bodies</a></li>
<li><a title="G.I. Joe: Retaliation" href="http://blog.jverkamp.com/2013/04/03/g-i-joe-retaliation/">G.I. Joe: Retaliation</a></li>
</ol>
<ol class="footnotes"><li id="footnote_0_4386" class="footnote">I still have problems spelling that correctly&#8230;</li><li id="footnote_1_4386" class="footnote">Holy crap</li><li id="footnote_2_4386" class="footnote">A fact that the upcoming Jurassic Park sequel is apparently going to happily ignore</li><li id="footnote_3_4386" class="footnote">Or, if you want to be generous, than they thought that the audience could handle</li><li id="footnote_4_4386" class="footnote">I&#8217;ll leave that as an exercise for the reader to work out just how young I was back then <img src='http://blog.jverkamp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li><li id="footnote_5_4386" class="footnote">Any scene ever that throws things at the audience, I&#8217;m looking at you!</li></ol>]]></content:encoded>
			<wfw:commentRss>http://blog.jverkamp.com/2013/05/01/jurassic-park-3d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 3.733 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2013-06-04 00:56:19 -->

<!-- Compression = gzip -->