<?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>STRd6</title>
	<atom:link href="http://strd6.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://strd6.com</link>
	<description>It is beyond anything you have ever experienced or imagined</description>
	<lastBuildDate>Mon, 06 Sep 2010 08:10:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Useful JavaScript Game Extensions: Array#shuffle</title>
		<link>http://strd6.com/2010/09/useful-javascript-game-extensions-array-shuffle/</link>
		<comments>http://strd6.com/2010/09/useful-javascript-game-extensions-array-shuffle/#comments</comments>
		<pubDate>Mon, 06 Sep 2010 08:08:47 +0000</pubDate>
		<dc:creator>Daniel X Moore</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://strd6.com/?p=581</guid>
		<description><![CDATA[Part 7/256 Shuffling is important, especially in card games. /** * Returns a new array with the elements all shuffled up. * * @returns A new array that is randomly shuffled. * @type Array */ Array.prototype.shuffle = function&#40;&#41; &#123; var shuffledArray = &#91;&#93;; &#160; this.each&#40;function&#40;element&#41; &#123; shuffledArray.splice&#40;rand&#40;shuffledArray.length + 1&#41;, 0, element&#41;; &#125;&#41;; &#160; return shuffledArray;]]></description>
			<content:encoded><![CDATA[<p><a href="http://strd6.com/wp-content/uploads/2010/09/220px-Shuffle_cards_4.jpg"><img src="http://strd6.com/wp-content/uploads/2010/09/220px-Shuffle_cards_4-150x150.jpg" alt="Do the shuffle! Array#shuffle" title="Card Shuffle" width="150" height="150" class="alignnone size-thumbnail wp-image-582" /></a></p>
<p>Part 7/256</p>
<p>Shuffling is important, especially in card games.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
 * Returns a new array with the elements all shuffled up.
 *
 * @returns A new array that is randomly shuffled.
 * @type Array
 */</span>
Array.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">shuffle</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> shuffledArray <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>element<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    shuffledArray.<span style="color: #660066;">splice</span><span style="color: #009900;">&#40;</span>rand<span style="color: #009900;">&#40;</span>shuffledArray.<span style="color: #660066;">length</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> element<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">return</span> shuffledArray<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Notice how building on the previous components of <code>rand</code> and <code>each</code> makes this method much easier to write. You&#8217;ll find that when you surround yourself with great APIs things constantly become easier and easier, whereas when you are surrounded with terrible APIs things become harder and harder.</p>
]]></content:encoded>
			<wfw:commentRss>http://strd6.com/2010/09/useful-javascript-game-extensions-array-shuffle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Google Font API to Render Inconsolata in HTML5 Canvas</title>
		<link>http://strd6.com/2010/09/using-google-font-api-to-render-inconsolata-in-html5-canvas/</link>
		<comments>http://strd6.com/2010/09/using-google-font-api-to-render-inconsolata-in-html5-canvas/#comments</comments>
		<pubDate>Sun, 05 Sep 2010 07:56:33 +0000</pubDate>
		<dc:creator>Daniel X Moore</dc:creator>
				<category><![CDATA[Internet Adventures]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://strd6.com/?p=567</guid>
		<description><![CDATA[In Contrasaurus we wanted some cooler fonts to add some extra ambiance to the game. I knew that adding a custom font from Google Font API was easy for classic HTML elements, but would it be easy for HTML5 Canvas elements? 5 minutes later I knew the answer&#8230; Yes! // In the &#60;head&#62; tag &#60;link]]></description>
			<content:encoded><![CDATA[<p>In Contrasaurus we wanted some cooler fonts to add some extra ambiance to the game. I knew that adding a custom font from Google Font API was easy for classic HTML elements, but would it be easy for HTML5 Canvas elements? 5 minutes later I knew the answer&#8230; Yes!</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// In the &lt;head&gt; tag</span>
<span style="color: #339933;">&lt;</span>link href<span style="color: #339933;">=</span><span style="color: #3366CC;">'http://fonts.googleapis.com/css?family=Inconsolata'</span> rel<span style="color: #339933;">=</span><span style="color: #3366CC;">'stylesheet'</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">'text/css'</span><span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// In your js code</span>
context.<span style="color: #660066;">font</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;bold 1.2em 'Inconsolata'&quot;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://strd6.com/2010/09/using-google-font-api-to-render-inconsolata-in-html5-canvas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Useful JavaScript Game Extensions: Array#each</title>
		<link>http://strd6.com/2010/09/useful-javascript-game-extensions-arrayeach/</link>
		<comments>http://strd6.com/2010/09/useful-javascript-game-extensions-arrayeach/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 21:16:24 +0000</pubDate>
		<dc:creator>Daniel X Moore</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://strd6.com/?p=570</guid>
		<description><![CDATA[Welcome to the nether realm of JavaScript extensions&#8230; things that should exist and sometimes kind of do, but with a different name and an inconsiderate API. Part 6 of 256 Useful JavaScript Extensions Array#each. /** * Call the given iterator once for each element in the array, * passing in the element as the first]]></description>
			<content:encoded><![CDATA[<p><a href="http://strd6.com/wp-content/uploads/2010/09/computer-code.jpg"><img src="http://strd6.com/wp-content/uploads/2010/09/computer-code-150x150.jpg" alt="Computer code vortex" title="computer-code" width="150" height="150" class="alignnone size-thumbnail wp-image-572" /></a></p>
<p>Welcome to the nether realm of JavaScript extensions&#8230; things that should exist and sometimes kind of do, but with a different name and an inconsiderate API.</p>
<p>Part 6 of 256 Useful JavaScript Extensions <code>Array#each</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
 * Call the given iterator once for each element in the array,
 * passing in the element as the first argument, the index of 
 * the element as the second argument, and this array as the
 * third argument.
 *
 * @param {Function} iterator Function to be called once for 
 * each element in the array.
 * @param {Object} [context] Optional context parameter to be 
 * used as `this` when calling the iterator function.
 *
 * @returns `this` to enable method chaining.
 */</span>
Array.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">each</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>iterator<span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">forEach</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">forEach</span><span style="color: #009900;">&#40;</span>iterator<span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> len <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> len<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      iterator.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span>context<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> i<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You&#8217;ll notice that this method makes use of the <em>possibly</em> existing <code>Array#forEach</code> method if it exists. In fact it is <em>almost</em> an alias of it, but since <code>forEach</code> always returns <code>undefined</code> like a jerk, we need to wrap it and return the object for chaining like a good citizen. Also, who wants to always be writing <strong>for</strong>Each, why not just <code>each</code>? Yeah&#8230; I like this.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Example:</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> people <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;David&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Joe&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Gandalf&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Greet each person by name</span>
people.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>person<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Hi &quot;</span> <span style="color: #339933;">+</span> person.<span style="color: #000066;">name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://strd6.com/2010/09/useful-javascript-game-extensions-arrayeach/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Useful JavaScript Extensions: Number#times</title>
		<link>http://strd6.com/2010/08/useful-javascript-extensions-numbertimes/</link>
		<comments>http://strd6.com/2010/08/useful-javascript-extensions-numbertimes/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 19:24:29 +0000</pubDate>
		<dc:creator>Daniel X Moore</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://strd6.com/?p=562</guid>
		<description><![CDATA[Part 5/256 For loops&#8230; I hate them so much. Fortunately, a well established functional iteration convention is the Number#times method. /** * Calls iterator the specified number of times, passing in a number of the * current iteration as a parameter. The number will be 0 on first call, 1 on * second call, etc.]]></description>
			<content:encoded><![CDATA[<p><a href="http://strd6.com/wp-content/uploads/2010/08/numbers.gif"><img src="http://strd6.com/wp-content/uploads/2010/08/numbers-150x150.gif" alt="" title="numbers" width="150" height="150" class="alignnone size-thumbnail wp-image-563" /></a></p>
<p>Part 5/256</p>
<p>For loops&#8230; I hate them so much. Fortunately, a well established functional iteration convention is the <a href="http://api.prototypejs.org/language/number/prototype/times/"><code>Number#times</code> method</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
 * Calls iterator the specified number of times, passing in a number of the 
 * current iteration as a parameter. The number will be 0 on first call, 1 on 
 * second call, etc. 
 * 
 * @param {Function} iterator The iterator takes a single parameter, the number 
 * of the current iteration.
 * @param {Object} [context] The optional context parameter specifies an object
 * to treat as &lt;code&gt;this&lt;/code&gt; in the iterator block.
 * 
 * @returns The number of times the iterator was called.
 */</span>
Number.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">times</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>iterator<span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    iterator.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span>context<span style="color: #339933;">,</span> i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">return</span> i<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This hides the inner workings of the iteration from the calling code so there&#8217;s no need to keep track of an external dummy iterator variable if you don&#8217;t want to.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> n <span style="color: #339933;">=</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Greets you three times, with respect</span>
n.<span style="color: #660066;">times</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;O HAI!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// logs: 0, 1, 2</span>
n.<span style="color: #660066;">times</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://strd6.com/2010/08/useful-javascript-extensions-numbertimes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Useful JavaScript Game Extensions: Array#remove</title>
		<link>http://strd6.com/2010/08/useful-javascript-game-extensions-arrayremove/</link>
		<comments>http://strd6.com/2010/08/useful-javascript-game-extensions-arrayremove/#comments</comments>
		<pubDate>Sat, 28 Aug 2010 21:16:19 +0000</pubDate>
		<dc:creator>Daniel X Moore</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://strd6.com/?p=555</guid>
		<description><![CDATA[Part 4: Array#remove JavaScript Arrays are missing some very common, very useful functions. One of those is the remove method. We want to be able to say &#8220;Hey you, array, remove this object from yourself! Now!!&#8221; But our poor JS array&#8217;s don&#8217;t know how. They can barely remove elements from specific indices, let alone a]]></description>
			<content:encoded><![CDATA[<p><a href="http://strd6.com/wp-content/uploads/2010/08/debris_removal.jpg"><img src="http://strd6.com/wp-content/uploads/2010/08/debris_removal-150x150.jpg" alt="Debris Removal" title="debris_removal" width="150" height="150" class="alignnone size-thumbnail wp-image-558" /></a><br />
Part 4: Array#remove</p>
<p>JavaScript Arrays are missing some very common, very useful functions. One of those is the <code>remove</code> method. We want to be able to say &#8220;Hey you, <code>array</code>, remove this object from yourself! Now!!&#8221; But our poor JS array&#8217;s don&#8217;t know how. They can barely remove elements from specific indices, let alone a specified object. Well no longer! Now they&#8217;ll do what we say.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
 * Remove the first occurance of the given object from the array if it is
 * present.
 *
 * @param {Object} object The object to remove from the array if present.
 * @returns The removed object if present otherwise undefined.
 */</span>
Array.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">remove</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> index <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>index <span style="color: #339933;">&gt;=</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">splice</span><span style="color: #009900;">&#40;</span>index<span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> undefined<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>By building off of the <code>Array</code>&#8216;s built in methods we can keep this code very short. We find the first occurrence of the specified object using <code>indexOf</code>, then we remove and return it using <code>splice</code>. If it wasn&#8217;t found we return undefined instead.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// An illustrative test suite</span>
&nbsp;
test<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Array#remove&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  ok<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">2</span><span style="color: #339933;">,</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;[1,2,3].remove(2) === 2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  ok<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> undefined<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;[1,3].remove(2) === undefined&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  ok<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;[1,3].remove(3) === 3&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> array <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">2</span><span style="color: #339933;">,</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  array.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  ok<span style="color: #009900;">&#40;</span>array.<span style="color: #660066;">length</span> <span style="color: #339933;">===</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;array = [1,2,3]; array.remove(2); array.length === 2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  array.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  ok<span style="color: #009900;">&#40;</span>array.<span style="color: #660066;">length</span> <span style="color: #339933;">===</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;array = [1,3]; array.remove(3); array.length === 1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>John Resig has another take on <code>Array#remove</code>, <a href="http://ejohn.org/blog/javascript-array-remove/">remove by index</a>. You may want to take a look at that as well, though for me it feels more natural to remove by specified object rather than by specified index.</p>
]]></content:encoded>
			<wfw:commentRss>http://strd6.com/2010/08/useful-javascript-game-extensions-arrayremove/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Useful JavaScript Game Extensions: Array#rand</title>
		<link>http://strd6.com/2010/08/useful-javascript-game-extensions-arrayrand/</link>
		<comments>http://strd6.com/2010/08/useful-javascript-game-extensions-arrayrand/#comments</comments>
		<pubDate>Fri, 27 Aug 2010 17:51:16 +0000</pubDate>
		<dc:creator>Daniel X Moore</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://strd6.com/?p=548</guid>
		<description><![CDATA[Part 3 of 256. /** * Randomly select an element from the array. The array remains unmodified. * * @returns A random element from an array, or undefined if the array is empty. */ Array.prototype.rand = function&#40;&#41; &#123; return this&#91;rand&#40;this.length&#41;&#93;; &#125;; Building on the last installment of a global rand method, we can easily extend]]></description>
			<content:encoded><![CDATA[<p><a href="http://strd6.com/wp-content/uploads/2010/08/32334.jpg"><img src="http://strd6.com/wp-content/uploads/2010/08/32334-150x150.jpg" alt="Ayn Rand" title="Ayn Rand" width="150" height="150" class="alignnone size-thumbnail wp-image-549" /></a></p>
<p>Part 3 of 256.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
 * Randomly select an element from the array. The array remains unmodified.
 *
 * @returns A random element from an array, or undefined if the array is empty.
 */</span>
Array.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">rand</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#91;</span>rand<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Building on the <a href="http://strd6.com/2010/08/useful-javascript-game-extensions-rand/">last installment of a global <code>rand</code> method</a>, we can easily extend <code>Array</code> to provide simple random element selection.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Example:</span>
<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;rock&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;paper&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;scissors&quot;</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>Selecting options from a loot table, or random AI actions is now wonderfully easy. With all these extensions the theme is the same, start with the best interface for the programmer and extend what you must to make it happen.</p>
]]></content:encoded>
			<wfw:commentRss>http://strd6.com/2010/08/useful-javascript-game-extensions-arrayrand/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Useful JavaScript Game Extensions: rand</title>
		<link>http://strd6.com/2010/08/useful-javascript-game-extensions-rand/</link>
		<comments>http://strd6.com/2010/08/useful-javascript-game-extensions-rand/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 16:56:34 +0000</pubDate>
		<dc:creator>Daniel X Moore</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://strd6.com/?p=541</guid>
		<description><![CDATA[Part 2 of my 256 part series: Useful JavaScript Game Extensions! /** * Generate uniformly distributed random numbers. * * @param {Number} [n] * @returns A Random integers from [0, n) if n is given, otherwise a random float * between 0 and 1. * @type Number */ function rand&#40;n&#41; &#123; if&#40;n !== undefined&#41; &#123;]]></description>
			<content:encoded><![CDATA[<p><a href="http://strd6.com/wp-content/uploads/2010/08/atlasshrugged2.jpg"><img src="http://strd6.com/wp-content/uploads/2010/08/atlasshrugged2-e1282841607542-150x150.jpg" alt="Rand Atlas Shrugged" title="Rand Atlas Shrugged" width="150" height="150" class="alignnone size-thumbnail wp-image-545" /></a><br />
Part 2 of my 256 part series: Useful JavaScript Game Extensions!</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
 * Generate uniformly distributed random numbers.
 *
 * @param {Number} [n]
 * @returns A Random integers from [0, n) if n is given, otherwise a random float
 * between 0 and 1.
 * @type Number
 */</span>
<span style="color: #003366; font-weight: bold;">function</span> rand<span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>n <span style="color: #339933;">!==</span> undefined<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> n<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Some games make use of random numbers&#8230; a lot. So when choosing the best interface it is important to keep that in mind. Often times uniform distributions are the way to go, such as when selecting from an array, or rolling a six sided die. If one often has need of a variety of random distributions then having different methods live in a <code>Random</code> namespace would probably be best. For simple, everyday use a little <code>rand(6)</code> is very convenient.</p>
]]></content:encoded>
			<wfw:commentRss>http://strd6.com/2010/08/useful-javascript-game-extensions-rand/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Useful JavaScript Game Extensions: Clamp</title>
		<link>http://strd6.com/2010/08/useful-javascript-game-extensions-clamp/</link>
		<comments>http://strd6.com/2010/08/useful-javascript-game-extensions-clamp/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 19:53:52 +0000</pubDate>
		<dc:creator>Daniel X Moore</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://strd6.com/?p=530</guid>
		<description><![CDATA[Part 1 of my new 256 part series on simple JavaScript extensions to make game programming easy and fun! /** * Returns a number whose value is limited to the given range. * * Example: limit the output of this computation to between 0 and 255 * (x * 255).clamp(0, 255) * * @param {Number}]]></description>
			<content:encoded><![CDATA[<p><a href="http://strd6.com/wp-content/uploads/2010/08/200px-Clamps.jpg"><img src="http://strd6.com/wp-content/uploads/2010/08/200px-Clamps.jpg" alt="Give him the clamps!" title="Clamps" width="200" height="227" class="alignnone size-full wp-image-538" /></a></p>
<p>Part 1 of my new 256 part series on simple JavaScript extensions to make game programming easy and fun!</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
 * Returns a number whose value is limited to the given range.
 *
 * Example: limit the output of this computation to between 0 and 255
 * (x * 255).clamp(0, 255)
 *
 * @param {Number} min The lower boundary of the output range
 * @param {Number} max The upper boundary of the output range
 * @returns A number in the range [min, max]
 * @type Number
 */</span>
Number.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">clamp</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>min<span style="color: #339933;">,</span> max<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> Math.<span style="color: #660066;">min</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">max</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> min<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> max<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Note that this extends the behavior of the Number class. Some may consider it poor form to &#8220;mess with&#8221; the JS built-ins, but I consider it poor form to expose a worse than necessary interface to the programmer. Compare:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Namespace?</span>
STRd6.<span style="color: #660066;">Util</span>.<span style="color: #660066;">clamp</span><span style="color: #009900;">&#40;</span>x <span style="color: #339933;">*</span> <span style="color: #CC0000;">255</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// global function clamp?</span>
clamp<span style="color: #009900;">&#40;</span>x <span style="color: #339933;">*</span> <span style="color: #CC0000;">255</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Clean, simple and object oriented!</span>
<span style="color: #009900;">&#40;</span>x <span style="color: #339933;">*</span> <span style="color: #CC0000;">255</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">clamp</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Stay tuned for the next 255 parts of the series!</p>
]]></content:encoded>
			<wfw:commentRss>http://strd6.com/2010/08/useful-javascript-game-extensions-clamp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Matrix.js 1.0.1 Released</title>
		<link>http://strd6.com/2010/08/matrix-js-1-0-1-released/</link>
		<comments>http://strd6.com/2010/08/matrix-js-1-0-1-released/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 02:16:45 +0000</pubDate>
		<dc:creator>Daniel X Moore</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://strd6.com/?p=521</guid>
		<description><![CDATA[Thoroughly documented, tested, and minifies very small (1.4k), this is the best release yet! Observe the sweetness: // Rotate 90 degrees var matrix = Matrix.rotation&#40;Math.PI / 4&#41;; &#160; // Scale and move var finalTransform = matrix.scale&#40;1/2&#41;.translate&#40;125, 175&#41;; &#160; canvas.withTransform&#40;finalTransform, function&#40;&#41; &#123; // Draw a circle or whatever in the transformed coordinates // canvas.fillCircle(0, 0, 50);]]></description>
			<content:encoded><![CDATA[<p>Thoroughly <a href="http://strd6.com/matrix.js/docs/symbols/Matrix.html">documented</a>, <a href="http://strd6.com/matrix.js/matrix_test.html">tested</a>, and <a href="http://strd6.com/matrix.js/matrix-1.0.1.min.js">minifies very small</a> (1.4k), this is the best release yet!</p>
<p>Observe the sweetness:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  <span style="color: #006600; font-style: italic;">// Rotate 90 degrees</span>
  <span style="color: #003366; font-weight: bold;">var</span> matrix <span style="color: #339933;">=</span> Matrix.<span style="color: #660066;">rotation</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">PI</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Scale and move</span>
  <span style="color: #003366; font-weight: bold;">var</span> finalTransform <span style="color: #339933;">=</span> matrix.<span style="color: #660066;">scale</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">/</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">translate</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">125</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">175</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  canvas.<span style="color: #660066;">withTransform</span><span style="color: #009900;">&#40;</span>finalTransform<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// Draw a circle or whatever in the transformed coordinates</span>
    <span style="color: #006600; font-style: italic;">// canvas.fillCircle(0, 0, 50);</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://strd6.com/2010/08/matrix-js-1-0-1-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A dinosaur covered in weapons will save the world, and that&#8217;s all I need to know</title>
		<link>http://strd6.com/2010/08/a-dinosaur-covered-in-weapons-will-save-the-world-and-thats-all-i-need-to-know/</link>
		<comments>http://strd6.com/2010/08/a-dinosaur-covered-in-weapons-will-save-the-world-and-thats-all-i-need-to-know/#comments</comments>
		<pubDate>Sat, 14 Aug 2010 08:02:02 +0000</pubDate>
		<dc:creator>Daniel X Moore</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Contrasaurus]]></category>

		<guid isPermaLink="false">http://strd6.com/?p=514</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<div id="attachment_515" class="wp-caption alignnone" style="width: 350px"><a href="http://strd6.com/wp-content/uploads/2010/08/C_Saur_eyelaser_placementexample.jpg"><img src="http://strd6.com/wp-content/uploads/2010/08/C_Saur_eyelaser_placementexample.jpg" alt="Contrasaurus gets decked out" title="Contrasaurus gets decked out" width="340" height="256" class="size-full wp-image-515" /></a><p class="wp-caption-text">Lock and load!</p></div>
]]></content:encoded>
			<wfw:commentRss>http://strd6.com/2010/08/a-dinosaur-covered-in-weapons-will-save-the-world-and-thats-all-i-need-to-know/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
