<?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>Illogic Tree &#187; How To</title>
	<atom:link href="http://illogictree.com/category/how-to/feed/" rel="self" type="application/rss+xml" />
	<link>http://illogictree.com/blog</link>
	<description>Development In Any Colour You Like, Logical or Otherwise</description>
	<lastBuildDate>Sat, 24 Dec 2011 16:18:26 +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>How to Code a Rhythm Game</title>
		<link>http://illogictree.com/blog/2010/05/how-to-code-a-rhythm-game/</link>
		<comments>http://illogictree.com/blog/2010/05/how-to-code-a-rhythm-game/#comments</comments>
		<pubDate>Mon, 31 May 2010 14:20:00 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[beats]]></category>
		<category><![CDATA[bpm]]></category>
		<category><![CDATA[ddr]]></category>
		<category><![CDATA[gamedev]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[rhythm]]></category>
		<category><![CDATA[sound]]></category>

		<guid isPermaLink="false">http://illogictree.com/?p=1673</guid>
		<description><![CDATA[So you want to program a rhythm game but you don&#8217;t know exactly how to begin? Well, during the development process of my rhythm-based mini-game, Funkbot3000, I learned a few things about creating a rhythm game that might be valuable for anyone looking to code one of their own. In games that use rhythm as [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-1803" title="Sound Equalizer Rhythm Music Beats" src="http://illogictree.com/wp-content/uploads/2010/05/981847-xs.jpg" alt="" width="340" height="227" />So you want to program a <strong>rhythm game</strong> but you don&#8217;t know exactly how to begin? Well, during the development process of my rhythm-based mini-game, <a href="http://illogictree.com/games/funkbot/">Funkbot3000</a>, I learned a few things about creating a rhythm game that might be valuable for anyone looking to code one of their own.</p>
<p>In games that use rhythm as its core mechanic, the most important aspect is detecting if the user executes a certain action in the correct <strong>position</strong> in time. For example, in games such as DDR, the user must step on positional arrows at certain <strong>intervals</strong> in the musical sequence in order for the game to register the input as a successful action.</p>
<p>In this post, I will depart some knowledge that I learned while creating a rhythm game that will hopefully help you in your journey of making a <strong>beat-tastic love adventure</strong>!</p>
<p><span id="more-1673"></span></p>
<p>First and foremost, it definitely helps (but is not required) to have some musical background. If you haven&#8217;t had any experience, you might want to brush up on some of the musical terminology.</p>
<p><strong>BPM (Beats Per Minute)</strong></p>
<p>Regardless if you use a full-length song or a small sound-loop, the most important aspect of any song is calculating its <strong>BPM</strong>. If the song&#8217;s BPM is not provided, the two things that you need to calculate the BPM is the <strong>length </strong>(in seconds) and the <strong>number of beats</strong> in the song/loop. Then, to calculate the BPM, you simply use the formula:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">BPM <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>num beats in song<span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> <span style="color: #0000dd;">60</span> <span style="color: #000040;">/</span> <span style="color: #008000;">&#40;</span>num secs in song<span style="color: #008000;">&#41;</span></pre></div></div>

<p>The <strong>BPM</strong> provides a foundation on which you can start testing for user inputs.</p>
<p><strong>Break It Down</strong></p>
<p>In the general case, we can assume that our song is in <strong>4/4</strong> time (also known as <em>common time</em>). What 4/4 means is that the song uses four <a href="http://en.wikipedia.org/wiki/Quarter-note">quarter-note</a> beats per <a href="http://en.wikipedia.org/wiki/Bar_(music)">bar</a>.</p>
<p>What you want to do next is figure out how accurate you want your input to be.  Using <a href="http://en.wikipedia.org/wiki/Eighth_note">eighth note</a> seems to provide enough accuracy for most sequences. But depending on how complicated you want your player&#8217;s input sequence to be, you might want to go all the way to <a href="http://en.wikipedia.org/wiki/Sixteenth_note">sixteeth</a> or <a href="http://en.wikipedia.org/wiki/Sixty-fourth_note">sixty-fourth</a> if you plan to really punish your players with <a href="http://www.youtube.com/watch?v=aS_IYe5JTZ4">Yngwie Malmsteen</a>-style arpeggios.</p>
<p>Below is a depiction of how a whole note is broken down.</p>
<p><img title="note_hierarchy" src="http://illogictree.com/wp-content/uploads/2010/05/note_hierarchy.gif" alt="" width="560" height="293" /></p>
<p style="text-align: center;"><em>Musical note values</em></p>
<p><strong>Register Correct Beats</strong></p>
<p>Now, you want to create a cool button sequence that you want players to press when the song is playing. What you want to do is store all the notes in the song that you want the user to hit in an <strong>array</strong>.</p>
<p>For example, say thatI have a funky, 1-bar drum-loop. And say when the then song is playing, I want to user to press down on a button every first, second, and third beat in the loop.</p>
<p>If I am using <strong>sixteenth</strong> notes as my input sequence&#8217;s precision, I would create an array like this:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">Array beats <span style="color: #000080;">=</span> <span style="color: #008000;">&#91;</span> <span style="color: #0000dd;">4</span>, <span style="color: #0000dd;">8</span>, <span style="color: #0000dd;">12</span> <span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// 1st, 2nd, 3rd quarter note</span></pre></div></div>

<p>So for <strong>each </strong>quarter note, there are <strong>four </strong>sixteenth notes.  The array above suggests that we want to detect the first, second and third sixteenth-note of each bar, so we multiply each value (quarter note) by <strong>four</strong> to get its corresponding value in sixteenth notes.</p>
<p><strong>Detecting User Input</strong></p>
<p>Now that you have your input sequence laid out, you can start detecting if players correctly pressed your sequence in time.</p>
<p>Every time the user hits a button, you must calculate which note (or which sixteenth note in our funk drum-loop example) the input corresponds to. To calculate that, you must know when, in the <strong>local time</strong> of the song, the button was pressed. What I mean by <strong>local time</strong> is the current time in the song that your game state is currently at. Say your song loop is only <strong>10</strong> seconds long but the game has elapsed a total time of <strong>14</strong> seconds. That means the local time of the song loop is 14-10=<strong>4 seconds</strong>.</p>
<p>To calculate the <strong>note position</strong> given the local time in the song, you can use this formula:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">nth sixteenth<span style="color: #000040;">-</span>note <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">time</span> in secs in song<span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> BPM <span style="color: #000040;">*</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #000040;">/</span><span style="color: #0000dd;">60</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> <span style="color: #008000;">&#40;</span>num_vals _per_beat<span style="color: #008000;">&#41;</span></pre></div></div>

<p>In my example, we are using <strong>sixteenth</strong> notes. Say I have a local-time of <strong>1.5</strong> seconds of a song with <strong>50</strong> BPM. Since there are <strong>4</strong> sixteenth notes per beat, we can calculate the nth sixteenth note:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// BPM = 50, secs = 4, num_vals_per_beat = 4</span>
nth sixteenth<span style="color: #000040;">-</span>note <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color:#800080;">1.5</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> <span style="color: #0000dd;">50</span> <span style="color: #000040;">*</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #000040;">/</span><span style="color: #0000dd;">60</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">4</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">5</span></pre></div></div>

<p>That means we were at the <strong>5th</strong> sixteenth note in the song/loop. Since there is no <strong>5</strong> in our array <strong>[4, 8, 12]</strong>, that means that the user did not press the button at the correct position in time according to what we set as our input sequence.</p>
<p><strong>Go Easy, Bro</strong></p>
<p>We can assume that the user will not press the input button at the <em>exact</em> moment in time that corresponds to your beat sequence (virtually impossible). So, what I did to remedy that is to give an acceptable <strong>buffer</strong> which provides the user a <strong>range of time</strong> such that if the user presses the button within this buffer, the game will register the input as correct. For example, if the user presses the button within 0.5 beats of the target beat, the input would register as a success.</p>
<p>So there you have it, a way to structure your code to provide a framework for rhythm games. Now go make some sweet, musical lovin&#8217;.</p>
]]></content:encoded>
			<wfw:commentRss>http://illogictree.com/blog/2010/05/how-to-code-a-rhythm-game/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>DirectX10 (D3D10) &amp; DevIL Image Library</title>
		<link>http://illogictree.com/blog/2010/02/directx10-devil-image-library/</link>
		<comments>http://illogictree.com/blog/2010/02/directx10-devil-image-library/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 05:19:06 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[How To]]></category>

		<guid isPermaLink="false">http://illogictree.com/?p=1455</guid>
		<description><![CDATA[After extensively searching online for some documentation on how to use the DevIL Image Library with DirectX10 to no avail, I have brought it upon myself to write a brief post on how to get them two to coexist in love. Although DirectX10 (Direct3D10) already has functionality that allows users to load images directly, it [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://illogictree.com/wp-content/uploads/2010/02/devil-image-library-300x143.jpg" alt="" title="devil-image-library" width="300" height="143" class="alignright size-medium wp-image-1459" />After extensively searching online for some documentation on how to use the <a href="http://openil.sourceforge.net/">DevIL</a> Image Library with DirectX10 to no avail, I have brought it upon myself to write a brief post on how to get them two to coexist in love. </p>
<p>Although DirectX10 (Direct3D10) already has <a href="http://msdn.microsoft.com/en-us/library/ee416716(VS.85).aspx">functionality</a> that allows users to load images directly, it might not be enough. For example, DirectX is unable to load some image types such as TARGA (.tga) files.  And if you are writing a OpenGL &#038; DirectX10 dual-renderer, you might want unite both renderers under a common image library API. Plus, DevIL has a lot of great functionality, and you want to take full advantage of it. Below, I provided the code to load an image given the filename.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;IL/il.h&gt;</span>
<span style="color: #339900;">#include &lt;string&gt;</span>
<span style="color: #339900;">#include &lt;assert.h&gt;</span>
&nbsp;
<span style="color: #666666;">// Use this macro to verify if D3D10 function succeeded</span>
<span style="color: #339900;">#define HV(x) if(!SUCCEEDED(x)) MessageBox(NULL, #x, &quot;HRESULT fail&quot;, MB_OK)</span>
&nbsp;
<span style="color: #666666;">// Creates a shader resource view given a filepath &amp; D3D10 device</span>
<span style="color: #666666;">//	@filePath - String of the file path of the image file</span>
<span style="color: #666666;">//	@pDevice - Pointer to the D3D10 device</span>
ID3D10ShaderResourceView<span style="color: #000040;">*</span> MakeSRV<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #000040;">&amp;</span> filePath, ID3D10Device<span style="color: #000040;">*</span> pDevice <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #666666;">// Will be filled and returned</span>
	ID3D10ShaderResourceView<span style="color: #000040;">*</span> pSRV <span style="color: #000080;">=</span> <span style="color: #0000ff;">NULL</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #666666;">// Load image from DevIL</span>
	ILuint idImage<span style="color: #008080;">;</span>
	ilGenImages<span style="color: #008000;">&#40;</span> <span style="color: #0000dd;">1</span>, <span style="color: #000040;">&amp;</span>idImage <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	ilBindImage<span style="color: #008000;">&#40;</span> idImage <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	ilLoadImage<span style="color: #008000;">&#40;</span> filePath.<span style="color: #007788;">c_str</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000dd;">assert</span> <span style="color: #008000;">&#40;</span> IL_NO_ERROR <span style="color: #000080;">==</span> ilGetError<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #666666;">// Fetch dimensions of image</span>
	<span style="color: #0000ff;">int</span> width <span style="color: #000080;">=</span> ilGetInteger<span style="color: #008000;">&#40;</span> IL_IMAGE_WIDTH <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">int</span> height <span style="color: #000080;">=</span> ilGetInteger<span style="color: #008000;">&#40;</span> IL_IMAGE_HEIGHT <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #666666;">// Load the data</span>
	ilConvertImage<span style="color: #008000;">&#40;</span> IL_RGBA,IL_UNSIGNED_BYTE <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span> pData <span style="color: #000080;">=</span> ilGetData<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #666666;">// Build the texture header descriptor</span>
	D3D10_TEXTURE2D_DESC descTex<span style="color: #008080;">;</span>
	descTex.<span style="color: #007788;">Width</span> <span style="color: #000080;">=</span> width<span style="color: #008080;">;</span>
	descTex.<span style="color: #007788;">Height</span> <span style="color: #000080;">=</span> height<span style="color: #008080;">;</span>
	descTex.<span style="color: #007788;">Format</span> <span style="color: #000080;">=</span> DXGI_FORMAT_R8G8B8A8_UNORM<span style="color: #008080;">;</span>
	descTex.<span style="color: #007788;">Usage</span> <span style="color: #000080;">=</span> D3D10_USAGE_DEFAULT<span style="color: #008080;">;</span>
	descTex.<span style="color: #007788;">BindFlags</span> <span style="color: #000080;">=</span> D3D10_BIND_SHADER_RESOURCE <span style="color: #000040;">|</span> D3D10_BIND_RENDER_TARGET<span style="color: #008080;">;</span>
	descTex.<span style="color: #007788;">CPUAccessFlags</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
	descTex.<span style="color: #007788;">MipLevels</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
	descTex.<span style="color: #007788;">ArraySize</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
	descTex.<span style="color: #007788;">SampleDesc</span>.<span style="color: #007788;">Count</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
	descTex.<span style="color: #007788;">SampleDesc</span>.<span style="color: #007788;">Quality</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
	descTex.<span style="color: #007788;">MiscFlags</span> <span style="color: #000080;">=</span> D3D10_RESOURCE_MISC_GENERATE_MIPS<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #666666;">// Resource data descriptor</span>
	D3D10_SUBRESOURCE_DATA data <span style="color: #008080;">;</span>
	<span style="color: #0000dd;">memset</span><span style="color: #008000;">&#40;</span> <span style="color: #000040;">&amp;</span>data, <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>D3D10_SUBRESOURCE_DATA<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	data.<span style="color: #007788;">pSysMem</span> <span style="color: #000080;">=</span> pData<span style="color: #008080;">;</span>
	data.<span style="color: #007788;">SysMemPitch</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">4</span> <span style="color: #000040;">*</span> width<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #666666;">// Create the 2d texture from data</span>
	ID3D10Texture2D <span style="color: #000040;">*</span> pTexture <span style="color: #000080;">=</span> <span style="color: #0000ff;">NULL</span><span style="color: #008080;">;</span>
	HV<span style="color: #008000;">&#40;</span> pDevice<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>CreateTexture2D<span style="color: #008000;">&#40;</span> <span style="color: #000040;">&amp;</span>descTex, <span style="color: #000040;">&amp;</span>data, <span style="color: #000040;">&amp;</span>pTexture <span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #666666;">// Create resource view descriptor</span>
	D3D10_SHADER_RESOURCE_VIEW_DESC srvDesc<span style="color: #008080;">;</span>
	srvDesc.<span style="color: #007788;">Format</span> <span style="color: #000080;">=</span> descTex.<span style="color: #007788;">Format</span><span style="color: #008080;">;</span>
	srvDesc.<span style="color: #007788;">ViewDimension</span> <span style="color: #000080;">=</span> D3D10_SRV_DIMENSION_TEXTURE2D<span style="color: #008080;">;</span>
	srvDesc.<span style="color: #007788;">Texture2D</span>.<span style="color: #007788;">MostDetailedMip</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
	srvDesc.<span style="color: #007788;">Texture2D</span>.<span style="color: #007788;">MipLevels</span> <span style="color: #000080;">=</span> D3D10_RESOURCE_MISC_GENERATE_MIPS <span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #666666;">// Create the shader resource view</span>
	HV<span style="color: #008000;">&#40;</span> pDevice<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>CreateShaderResourceView<span style="color: #008000;">&#40;</span> pTexture, <span style="color: #000040;">&amp;</span>srvDesc, <span style="color: #000040;">&amp;</span>pSRV <span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #666666;">// Delete from IL buffer after image loaded correctly</span>
	ilDeleteImages<span style="color: #008000;">&#40;</span> <span style="color: #0000dd;">1</span>, <span style="color: #000040;">&amp;</span>idImage <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	idImage <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">return</span> pSRV<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>There you have it. Let me know if you got any woes getting it to work. Thanks to my bud Manny for helping with the code.</p>
]]></content:encoded>
			<wfw:commentRss>http://illogictree.com/blog/2010/02/directx10-devil-image-library/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Mass-Spring Damper System (AS3 Source Code)</title>
		<link>http://illogictree.com/blog/2010/01/1345/</link>
		<comments>http://illogictree.com/blog/2010/01/1345/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 17:54:28 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[How To]]></category>

		<guid isPermaLink="false">http://illogictree.com/?p=1345</guid>
		<description><![CDATA[Above is a little test app I&#8217;ve created to show the deliciousness of the mass-spring damper system (also known as a harmonic oscillator). Move your mouse anywhere inside the box and it&#8217;ll swing the ball accordingly to emulate real mass-spring physics. In this post, I will briefly explain how you can add a mass-spring damper system into [...]]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="570" height="350" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="/wp-content/uploads/2010/01/Swingers1.swf" /><embed type="application/x-shockwave-flash" width="570" height="350" src="/wp-content/uploads/2010/01/Swingers1.swf"></embed></object></p>
<p>Above is a little test app I&#8217;ve created to show the deliciousness of the <a href="http://en.wikipedia.org/wiki/Damping">mass-spring damper system</a> (also known as a harmonic oscillator). Move your <strong>mouse </strong>anywhere inside the box and it&#8217;ll swing the ball accordingly to emulate real mass-spring physics.</p>
<p>In this post, I will briefly explain how you can add a mass-spring damper system into your own engine to simulate cool swinging action.</p>
<p style="text-align: left;"><strong>Source code</strong> (Actionscript 3.0): [ <a href="http://illogictree.com/wp-content/uploads/2010/01/MassSpring.as">MassSpringDamper.as</a> ]</p>
<p><span id="more-1345"></span></p>
<p><img class="alignright" title="FileDamped spring" src="http://illogictree.com/wp-content/uploads/2010/01/FileDamped-spring.gif" alt="" width="110" height="359" />A mass-spring damper is a system where there exists a <strong>mass</strong> attached at the end of  a <strong>spring</strong>. The forces that are involved in this system are the forces generated by compression<strong>/</strong>relaxation of the <strong>spring </strong>and, of course, <strong>gravity</strong>.</p>
<p>Using the <strong>F=ma</strong> approach, the <strong>acceleration </strong>gained from the mass-spring is:</p>
<p><strong>a = ( -cv &#8211; k(x &#8211; xo) ) / m</strong></p>
<p>Where <strong>m</strong> is mass of the object, <strong>v</strong> is velocity, (x-xo) is the distance between the end of spring and the mass, <strong>c</strong> is the friction constant and <strong>k</strong> is the spring constant.</p>
<p>In order to prevent your system from accumulating errors and blowing up, we will try to avoid using the classic <a href="http://en.wikipedia.org/wiki/Euler_method">forward euler integration</a> method. Instead, we use the safer approach, the symplectic integration method. If you didn&#8217;t understand this last part, it&#8217;s okay. Just remember that systems like these can easily accumulate errors and just go completely nuts if you don&#8217;t take special care.</p>
<p>Anyhow, the <a href="http://illogictree.com/wp-content/uploads/2010/01/MassSpring.as">source code</a> is attached. Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://illogictree.com/blog/2010/01/1345/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Make a Mini Moss Garden</title>
		<link>http://illogictree.com/blog/2009/04/how-to-make-minimoss-garden/</link>
		<comments>http://illogictree.com/blog/2009/04/how-to-make-minimoss-garden/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 04:02:31 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[Gardening]]></category>
		<category><![CDATA[How To]]></category>

		<guid isPermaLink="false">http://illogictree.com/?p=581</guid>
		<description><![CDATA[One of the hobbies that I&#8217;ve been developing recently is in-home gardening. For those who have never considered it, it really puts you in a peaceful mindstate. Also, having a few plants around your house not only is scientifically proven to bring peace-of-mind, it can also make your home look less like a crackhouse. Today, [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-582" title="plantfront" src="http://illogictree.com/wp-content/uploads/2009/04/plantfront.jpg" alt="plantfront" width="420" height="475" /><img class="alignnone size-full wp-image-602" title="planttopside" src="http://illogictree.com/wp-content/uploads/2009/04/planttopside.jpg" alt="planttopside" width="420" height="393" /><img class="alignnone size-full wp-image-583" title="planttop" src="http://illogictree.com/wp-content/uploads/2009/04/planttop.jpg" alt="planttop" width="420" height="279" /></p>
<p>One of the hobbies that I&#8217;ve been developing recently is <strong>in-home gardening</strong>. For those who have never considered it, it really puts you in a peaceful mindstate. Also, having a few plants around your house not only is scientifically proven to bring peace-of-mind, it can also make your home look less like a crackhouse.</p>
<p>Today, the sun was shining and the weather was sweet. So my girlfriend and I cruised over to West LA to check out this <a href="http://www.hashimotonursery.com/">epic nursey</a>. Oddly enough, we saw <a href="http://www.imdb.com/name/nm0736622/">Seth Rogan</a> there purchasing some <a href="http://www.eternitree.com/assets/red_leaf_japanese_large.jpg">Japanese red-leaf maple</a> trees. But anyhow, I saw this awesome batch of <a href="http://en.wikipedia.org/wiki/Soleirolia_soleirolii">baby&#8217;s tear moss</a> (priced @ about $1.30) and decided to make myself a nice little moss garden. So after several kilojoules were expended, I took some pictures (above) as proof of concept.</p>
<p>This shit was so easy, homeboy. In this post, you will learn how you can give birth to <strong>your own mini moss garden</strong> for cheap.</p>
<p><span id="more-581"></span></p>
<p><strong>Step 1 (Preparation)</strong></p>
<p>You need to find some <strong>moss</strong>. You can buy it at your local nursery, Home Depot, or you can just look around your home/neighborhood for some. They tend to grow in shaded spots on bark or rock. I used some baby&#8217;s tear moss from the nursery.</p>
<p>You need a <strong>container</strong>. The container I used was this glass container that I had lying around, but you can put it any unused vases or even a wine cup. Wash it.</p>
<p>You need some <strong>gravel</strong>. I found some gravel right in front of my apartment. But you can really find it anywhere. Make sure to wash it clean.</p>
<p>You need some <strong>potting soil</strong>. The potting sound is the soil that the moss must grow and expand into. I had alot of potting soil left from my recent growing op, but you can buy it anywhere (Home Depot/Target/Walmart) in the gardening isle. It should be relatively cheap. And depending on your container, you may or may not need alot of this.</p>
<p>(Optional) I decorated my moss garden with some black rocks. You can use rocks, figurines, or whatever floats your boat.</p>
<p><strong>Step 2 (Compilation)</strong></p>
<p><img class="alignnone size-full wp-image-609" title="compile" src="http://illogictree.com/wp-content/uploads/2009/04/compile.png" alt="compile" width="420" height="398" /></p>
<p>First, put the <strong>gravel </strong>into the container. This layer of gravel is used for water drainage which prevents the plant from developing root rot. It also is used to indicate if you are overwatering.</p>
<p>Next, pad on some <strong>potting soil</strong>. Make sure to part the soil (Moses style) so that you can drop the moss in (like it&#8217;s hot!).</p>
<p>Put in the moss, fit it in snuggly.</p>
<p>(Optional) Decorate your moss garden with figurines or rocks.</p>
<p>Spray the plant with water until the soil appears slightly moist.</p>
<p><strong>Step 3 (Care)</strong></p>
<p>Moss does not like direct sunlight. So keep it indoors next to a window to absorb some of that indirect sun-love.</p>
<p>Moss does not need alot of water to grow. So water it sparringly (few times a week). You want the soil just slightly moist but definitely not soaked. Check the gravel layer to see if it is swiming in water. If it is at all, you are watering it too much.</p>
<p>That&#8217;s it. Enjoy. (<a href="http://www.unruly-things.com/2008/09/paula-hayes.html">Level 2</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://illogictree.com/blog/2009/04/how-to-make-minimoss-garden/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>C++ and XML</title>
		<link>http://illogictree.com/blog/2009/04/cplusplus-and-xml/</link>
		<comments>http://illogictree.com/blog/2009/04/cplusplus-and-xml/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 08:58:51 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[How To]]></category>

		<guid isPermaLink="false">http://illogictree.com/?p=497</guid>
		<description><![CDATA[There are plenty of ways of utilizing XML in your game. From stucturing your dialogue trees to organizing the entities in your game, XML may be your best choice for most of your game&#8217;s needs. If you Google the interwebs, you will find several ways to process XML with C++. For one, if you want [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-full wp-image-498 alignnone" title="xmllogo" src="http://illogictree.com/wp-content/uploads/2009/04/xmllogo.png" alt="xmllogo" width="400" height="74" /></p>
<p>There are plenty of ways of utilizing <a href="http://en.wikipedia.org/wiki/Xml">XML</a> in your game. From stucturing your dialogue trees to organizing the entities in your game, XML may be your best choice for most of your game&#8217;s needs. If you Google the interwebs, you will find several ways to process XML with C++. For one, if you want read-and-write capabilities, you can use the popular <a href="http://xerces.apache.org/xerces-c/">Xerces-C++ XML Parser</a> (DOM, SAX, SAX2).</p>
<p>But if your XML isn&#8217;t super humungous (GBs) and you only want to read in an XML file, why not consider <a href="http://www.danoneverythingelse.com/articles/Softwarebxmlnode.html">Dan&#8217;s BXMLNode</a>? He calls it the &#8220;simplest XML file reader in the world&#8221; because it&#8217;s just that simple. With only 500 lines of code and a liberal license (MIT), you can just plug the code right into your engine to instantly read XML files. However, I do recommend you wrap this code in a class in case you ever want to switch out the reader for some other code.</p>
<p>You can download the <a href="http://www.danoneverythingelse.com/bxmlnode.cpp">C++ version (bxmlnode.cpp)</a>, the <a href="http://www.danoneverythingelse.com/bxmlnode.c">C version (bxmlnode.c)</a> and the <a href="http://www.danoneverythingelse.com/bxmlnode.zip">Visual C++ 6.0 project version (bxmlnode.zip)</a>.</p>
<p>[Edit]</p>
<p><strong>XML _Node Class Source Code (C++)</strong></p>
<p>I attached the class that I use in my game. This <strong>class </strong>basically wraps around bxmlnode with some nice features such as searching for tags, altering the XML, saving to file, and other XMLiciousness. Sorry I have no time to document this, but feel free to <a href="mailto:eddie@illogictree.com">email me</a> with any questions. Also, opted to use STL vectors because I&#8217;m a lazy asian.</p>
<p>Download: <a href="http://illogictree.com/wp-content/uploads/2009/04/xml_node.zip">xml_node.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://illogictree.com/blog/2009/04/cplusplus-and-xml/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Implement 2D Parallax Scrolling</title>
		<link>http://illogictree.com/blog/2009/01/how-to-implement-parallax-scrolling/</link>
		<comments>http://illogictree.com/blog/2009/01/how-to-implement-parallax-scrolling/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 18:36:43 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[How To]]></category>

		<guid isPermaLink="false">http://yellowtale.wordpress.com/?p=20</guid>
		<description><![CDATA[So one of the most delicious techniques for making your two-dimensional side-scrolling game appear more three-dimensional is through an age-old technique called parallax scrolling. It&#8217;s a special scrolling technique that makes nearby object seem, closer and distant terrain seem, well, more distant. Below is an example: So how do you begin implement this parallax scrolling [...]]]></description>
			<content:encoded><![CDATA[<p>So one of the most delicious techniques for making your two-dimensional side-scrolling game appear more three-dimensional is through an age-old technique called <a href="http://en.wikipedia.org/wiki/Parallax_scrolling">parallax scrolling</a>. It&#8217;s a special scrolling technique that makes nearby object seem, closer and distant terrain seem, well, more distant. Below is an example:</p>
<p style="text-align:center;"><img class="aligncenter" title="Parallax Example" src="http://upload.wikimedia.org/wikipedia/commons/1/16/Parallax-scroll-example.gif" alt="" width="320" height="200" /></p>
<p>So how do you begin implement this parallax scrolling in to your game? Well there are two ways you can go about it&#8230;</p>
<p><span id="more-20"></span></p>
<p><strong>Technique 1</strong></p>
<p>If your game is a simple side-scroller with the camera moving continuously causing your scene to pan from left-to-right (or vise-versa) without the camera jumping around the scene, we can do as follows:</p>
<p>You can start off by setting the velocity for your closest layer (in the image above, it&#8217;s the layer with foreground palm trees and path). Let signify that layer with index 1 that layer&#8217;s velocity to c. We our code so that if the camera moves, we move the objects on this layer by velocity c.:</p>
<p>v<sub>1</sub> = c;</p>
<p>Then, lets index the background vegetation layer (the one with dark green grass) with 2. Since it is farther away from the viewer, it &#8220;moves&#8221; slower than the first layer. Let&#8217;s say it moves half as slow..</p>
<p>v<sub>2</sub> = c/2;</p>
<p>After, we consider the mountain layer, which is even farther that the previous layer. Since it&#8217;s farther than the background vegetation layer, it should move at a slower velocity.</p>
<p>v<sub>3</sub> = c/3;</p>
<p>For more layers, we can do v<sub>4</sub> = c/4;  v<sub>5</sub> = c/5;  &#8230; v<sub>100</sub> = c/100 ;</p>
<p>As you can tell, the farther away the object is, the smaller the velocity becomes, all the way until the velocity converges to zero. And since the night background is way off in the distance, we can assume that it&#8217;s velocity is so negligible that we can consider it to be zero, which is why the backdrop doesn&#8217;t move.</p>
<p><strong>Technique 2</strong></p>
<p>So what happens if we have a scene that requires the camera to occasionally jump around in the scene, how do we handle how much of the layers to offset to still appear to have have parallax when we scroll? If we were to use technique one, the layers would just seem very off only because we expect the movement of the layers to be continuous like the camera.</p>
<p><img class="aligncenter size-full wp-image-104" title="parallax21" src="http://illogictree.com/wp-content/uploads/2009/01/parallax21.png" alt="parallax21" width="400" height="242" /></p>
<p>As you can see from the image above,  the position of the layers are affected by one central pivot point in the farthest position of the screen. So how do we calculate the position of any layer of the scene? Well, sir, we must incorporate simple trigonometry into solving this problem:</p>
<p><img class="aligncenter size-full wp-image-199" title="trig" src="http://illogictree.com/wp-content/uploads/2009/01/trig.png" alt="trig" width="403" height="316" /></p>
<p>First, we must designate a central point on each of the layers. And we must also know how far away each layer is from the center pivot point (designated as <strong>y</strong> in image above).  We can assume we are moving the camera in relation to the first layer (which is the foreground layer with palm trees and path).</p>
<p>So we first choose a layer that we want all other layers to move in relation to. Since most games have the characters/sprites on the closest layer, we set it as the first layer (in image above, layer with foreground palm trees and path). Say we move the camera 10 units left of  the center axis in relation to that layer. Since we already know how how far this layer is from the center axis (designated <strong>x<sub>1</sub></strong>) and how distant this layer is away from the center pivot at the backdrop (designated <strong>y<sub>1</sub></strong>), we can use simple trigonometry to fetch the angle (designated<strong> Θ </strong>). Calculate <strong> Θ = </strong> <strong>inverse tangent of x<sub>1</sub>/y<sub>1</sub></strong> = tan^-1 (x<sub>1</sub>/y<sub>1</sub>).</p>
<p>Now that we have Θ, we can now correctly determine the offset for the rest of the layers. For example, if we are calculating how much x to offset the 2nd layer (designated by x<sub>2</sub>), we use x<sub>2</sub> = y<sub>2</sub> * tan(Θ), in which <strong>y<sub>2</sub></strong> is how far the second layer is away from the center pivot and <strong>Θ</strong> is the angle that we calculated. The x<sub>2</sub> generated is how far we should offset the center of the layer from the center axis.</p>
<p>Now, don&#8217;t you  regret dozing off in your high school trig class?</p>
]]></content:encoded>
			<wfw:commentRss>http://illogictree.com/blog/2009/01/how-to-implement-parallax-scrolling/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

