<?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>Eirik Hoem&#039;s Blog &#187; Game Development</title>
	<atom:link href="http://blog.eirikhoem.net/index.php/category/game-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.eirikhoem.net</link>
	<description>PHP, AS3, Flex, Flash</description>
	<lastBuildDate>Tue, 18 May 2010 17:58:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Book review: Papervision 3D Essentials</title>
		<link>http://blog.eirikhoem.net/index.php/2010/03/11/book-review-papervision-3d-essentials/</link>
		<comments>http://blog.eirikhoem.net/index.php/2010/03/11/book-review-papervision-3d-essentials/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 19:36:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[Book]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Papervision]]></category>
		<category><![CDATA[Review]]></category>

		<guid isPermaLink="false">http://blog.eirikhoem.net/?p=220</guid>
		<description><![CDATA[Book review: Papervision 3D Essentials (follow link to buy)
ISBN 1847195725
ISBN 13 978-1-847195-72-2
Publisher: Packt Publishing
Author: Paul Tondeur and Jeff Winder.
This review here is long overdue, but since work got a bit hectic, and I spent some time moving it got pushed back.
Short version: If you want to get started with Papervision 3D, get this book. It&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Book review:</strong> <a href="http://www.packtpub.com/papervision3d-essentials/mid/15090958hmvy?utm_source=blog.eirikhoem.net&amp;utm_medium=affiliate&amp;utm_content=blog&amp;utm_campaign=mdb_000617" target="_blank" onclick="javascript:pageTracker._trackPageview ('/outbound/www.packtpub.com');">Papervision 3D Essentials</a> (follow link to buy)<br />
<strong>ISBN</strong> 1847195725<br />
<strong>ISBN 13</strong> 978-1-847195-72-2<br />
<strong>Publisher:</strong> <a href="http://www.packtpub.com/" target="_blank" onclick="javascript:pageTracker._trackPageview ('/outbound/www.packtpub.com');">Packt Publishing</a><br />
<strong>Author:</strong> <a href="http://www.paultondeur.com/ " target="_blank" onclick="javascript:pageTracker._trackPageview ('/outbound/www.paultondeur.com');">Paul Tondeur</a> and <a href=" http://jeffwinder.blogspot.com/" target="_blank" onclick="javascript:pageTracker._trackPageview ('/outbound/jeffwinder.blogspot.com');">Jeff Winder</a>.<br />
This review here is long overdue, but since work got a bit hectic, and I spent some time moving it got pushed back.</p>
<div id="attachment_148" class="wp-caption alignleft" style="width: 213px"><a href="http://www.packtpub.com/papervision3d-essentials/mid/15090958hmvy?utm_source=blog.eirikhoem.net&amp;utm_medium=affiliate&amp;utm_content=blog&amp;utm_campaign=mdb_000617" onclick="javascript:pageTracker._trackPageview ('/outbound/www.packtpub.com');"><img class="size-full wp-image-148" title="Papervision3D Essentials Cover" src="http://blog.eirikhoem.net/wp-content/uploads/2009/10/papervision-3d-essentials.jpg" alt="Papervision3D Essentials Cover" width="203" height="250" /></a><p class="wp-caption-text">Papervision3D Essentials Cover</p></div>
<p><strong>Short version: </strong>If you want to get started with Papervision 3D, get this book. It&#8217;s a well written, great introduction for people new to Papervision3D, as well as a good reference for more experienced developers. It covers everything from basics to filters, effects and performance topics.</p>
<p><strong>Longer version:</strong> Before I started reading this book I had never used Pv3D except looking at some neat demos. I had some experience with OpenGL from way-back, so the basic 3d concepts were not new to me.  As I got started I found that most of what I knew from general 3d graphics development was covered pretty well in the first few chapters. From the basic building blocks, to coordinate systems and primitives. The book starts out with a chapter dedicated to setting up authoring tools for compiling the code created during the book. Both Flash CS3/CS4 and Flex/Flash Builder is covered. After that it deals briefly with some core AS3 concepts before moving on to fundamental 3D subjects. Everything is explained really well, and as the book progresses trough the rest of the chapters it details subjects as drawing primitives, adding materials, setting up cameras and loading external models, then going on with particle systems, external models, filters and effects. A chapter is also dedicated to performance optimization. The book offers a number of good examples, also available on-line.</p>
<p>The authors are clearly very comfortable with the subjects they are covering, and discussing pretty much every topic in a language that makes it easy to follow, also for less experienced developers. In my opinion this is a very well written book that I would not hesitate to recommend to beginning developers as well as experienced.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eirikhoem.net/index.php/2010/03/11/book-review-papervision-3d-essentials/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>XNA Platformer Starter Kit &#8211; Falling Apples</title>
		<link>http://blog.eirikhoem.net/index.php/2009/03/01/xna-platformer-starter-kit-falling-apples/</link>
		<comments>http://blog.eirikhoem.net/index.php/2009/03/01/xna-platformer-starter-kit-falling-apples/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 20:03:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://blog.eirikhoem.net/?p=67</guid>
		<description><![CDATA[



As I mentioned in this previous post I&#8217;ve started to play around with C# and XNA Game Studio, and it&#8217;s very entertaining. I started out using The Platformer Starter Kit , which is a basic platformer game that you can customize and base your game on. I followed the tutorials mentioned in the previous link, [...]]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "pub-0056923567680782";
/* default */
google_ad_slot = "6546082201";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>As <a href="http://blog.eirikhoem.net/index.php/2009/02/28/blog-refresh-playing-with-xna-game-studio/">I mentioned in this previous post</a> I&#8217;ve started to play around with C# and XNA Game Studio, and it&#8217;s very entertaining. I started out using <a href="http://msdn.microsoft.com/en-us/library/dd254918.aspx" onclick="javascript:pageTracker._trackPageview ('/outbound/msdn.microsoft.com');">The Platformer Starter Kit</a> , which is a basic platformer game that you can customize and base your game on. I followed the tutorials mentioned in the previous link, and everything just works pretty smooth. Very satisfying to see immediate results reflected in a working game. After finishing them I decided to add a new feature by myself, a falling apple which would kill the player (I&#8217;ve been playing <a href="http://kayin.pyoko.org/iwbtg/" onclick="javascript:pageTracker._trackPageview ('/outbound/kayin.pyoko.org');">I Wanna Be The Guy</a> lately). Hence, this post: XNA Platformer Starter Kit &#8211; Falling Apples. Now, this is a very basic feature. I just based my Apple on a copy of the Gem class, and did some minor modifications to allow them to fall down once the player walks under them, and if the player is hit he&#8217;ll die. A picture to show the final result:</p>
<div id="attachment_80" class="wp-caption alignnone" style="width: 310px"><img class="size-medium wp-image-80" title="Falling Apples" src="http://blog.eirikhoem.net/wp-content/uploads/2009/03/platformer1-300x272.jpg" alt="Falling Apples" width="300" height="272" /><p class="wp-caption-text">Falling Apples</p></div>
<p>Please bear in mind that this post is just a note of the changes I did to make this work, and should not be considered a full tutorial. I might end up doing more proper posts on XNA as I progress in my work with it.</p>
<p>So, here it goes!</p>
<p>First, create a new C# class. Just copy all the contents from the Gem class, and rename Gem to Apple (and gems to apples). Also, add the following line to the Apple constructor so that we can see the difference between apples and gems: <em>Color = Color.Red;</em></p>
<p>Now, remove the following lines, since we do not need them:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp"><span style="color: #0600FF;">private</span> SoundEffect collectedSound;
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">readonly</span> <span style="color: #FF0000;">int</span> PointValue;</pre></div></div>

<p>And add these:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">float</span> GravityAcceleration = <span style="color: #FF0000;">6500</span>.0f;
<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">float</span> MaxFallSpeed = <span style="color: #FF0000;">600</span>.0f;
<span style="color: #0600FF;">private</span> <span style="color: #FF0000;">bool</span> isFalling;
&nbsp;
<span style="color: #0600FF;">public</span> Vector2 Velocity
<span style="color: #000000;">&#123;</span>
    get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> velocity; <span style="color: #000000;">&#125;</span>
    set <span style="color: #000000;">&#123;</span> velocity = value; <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
Vector2 velocity;</pre></div></div>

<p>Now, since we want to be able to trigger the apples to fall when the player passes under them, we&#8217;ll need to create a bounding rectangle, which is taller than the actual apple. This will be the rectangle the player will collide with once he passes under the apple, and hence the apple will start falling.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp"><span style="color: #0600FF;">public</span> Rectangle TriggerRectangle
<span style="color: #000000;">&#123;</span>
    get
    <span style="color: #000000;">&#123;</span>
        <span style="color: #FF0000;">int</span> left = <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>basePosition.<span style="color: #0000FF;">X</span>;
        <span style="color: #FF0000;">int</span> width = <span style="color: #FF0000;">32</span>;
        <span style="color: #FF0000;">int</span> top = <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>basePosition.<span style="color: #0000FF;">Y</span>;
        <span style="color: #FF0000;">int</span> height = <span style="color: #FF0000;">200</span>;
        <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> Rectangle<span style="color: #000000;">&#40;</span>left, top, width, height<span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>We need to implement some kind of basic physics to calculate how fast the apple should be falling. This is done by adding a new method called ApplyPhysics, which checks if the apple is falling, and if it is, it updates the velocity and position based on some simple calculations:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> ApplyPhysics<span style="color: #000000;">&#40;</span>GameTime gameTime<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #FF0000;">float</span> elapsed = <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">float</span><span style="color: #000000;">&#41;</span>gameTime.<span style="color: #0000FF;">ElapsedGameTime</span>.<span style="color: #0000FF;">TotalSeconds</span>;
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>isFalling<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        velocity.<span style="color: #0000FF;">Y</span> = MathHelper.<span style="color: #0000FF;">Clamp</span><span style="color: #000000;">&#40;</span>velocity.<span style="color: #0000FF;">Y</span> + GravityAcceleration * elapsed, -MaxFallSpeed, MaxFallSpeed<span style="color: #000000;">&#41;</span>;
        Position += velocity * elapsed;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>To make sure it actually falls when triggered we need to update public void Update(GameTime gameTime) and add a call to the ApplyPhysics method we just created. The call can be added right after bounce, at the end of the method:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp">    bounce = <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">float</span><span style="color: #000000;">&#41;</span>Math.<span style="color: #0000FF;">Sin</span><span style="color: #000000;">&#40;</span>t<span style="color: #000000;">&#41;</span> * BounceHeight * texture.<span style="color: #0000FF;">Height</span>;
    ApplyPhysics<span style="color: #000000;">&#40;</span>gameTime<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The last thing we need to do in the Apple class is to add a method for actually starting the fall:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> OnRockFalling<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    isFalling = <span style="color: #0600FF;">true</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Next up are some changes to the<strong> Level class</strong>. Find the line which creates the Gem array:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp"><span style="color: #0600FF;">private</span> List&amp;lt;Gem&amp;gt; gems = <span style="color: #008000;">new</span> List&amp;lt;Gem&amp;gt;<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>And add a new array for the Apples:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp"><span style="color: #0600FF;">private</span> List&amp;lt;Apple&amp;gt; apples = <span style="color: #008000;">new</span> List&amp;lt;Apple&amp;gt;<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>Next up is the loading of the Apples. In the LoadTile method, add a new case statement as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp">    <span style="color: #0600FF;">case</span> <span style="color: #808080;">'R'</span>:
        <span style="color: #0600FF;">return</span> LoadAppleTile<span style="color: #000000;">&#40;</span>x, y<span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>This will load R&#8217;s in the level code as apples. We now need to create the LoadAppleTile method:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp"><span style="color: #0600FF;">private</span> Tile LoadApppleTile<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> x, <span style="color: #FF0000;">int</span> y<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    Point position = GetBounds<span style="color: #000000;">&#40;</span>x, y<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Center</span>;
    apples.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Apple<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>, <span style="color: #008000;">new</span> Vector2<span style="color: #000000;">&#40;</span>position.<span style="color: #0000FF;">X</span>, position.<span style="color: #0000FF;">Y</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> Tile<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">null</span>, TileCollision.<span style="color: #0000FF;">Passable</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Almost there! We need to create a few news method for getting the apples to work. The first is called UpdateApples, which checks the collisions with the player:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> UpdateApples<span style="color: #000000;">&#40;</span>GameTime gameTime<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i = <span style="color: #FF0000;">0</span>; i &amp;lt; apples.<span style="color: #0000FF;">Count</span>; ++i<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        Apple apple = apples<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>;
        apple.<span style="color: #0000FF;">Update</span><span style="color: #000000;">&#40;</span>gameTime<span style="color: #000000;">&#41;</span>;
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>apple.<span style="color: #0000FF;">BoundingCircle</span>.<span style="color: #0000FF;">Intersects</span><span style="color: #000000;">&#40;</span>Player.<span style="color: #0000FF;">BoundingRectangle</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            OnPlayerKilled<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">else</span> <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>apple.<span style="color: #0000FF;">TriggerRectangle</span>.<span style="color: #0000FF;">Intersects</span><span style="color: #000000;">&#40;</span>Player.<span style="color: #0000FF;">BoundingRectangle</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            OnAppleFalling<span style="color: #000000;">&#40;</span>apple<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Next up is the OnAppleFalling method, which in turn calls OnAppleFalling in the Apple class.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> OnAppleFalling<span style="color: #000000;">&#40;</span>Apple apple<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    apple.<span style="color: #0000FF;">OnAppleFalling</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Now we just need to insert calls for these methods in the correct places. First up is the UpdateApples method. This is called from the Update method. Just find the following line:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp">    UpdateGems<span style="color: #000000;">&#40;</span>gameTime<span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>and insert the UpdateApples call under it:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp">    UpdateApples<span style="color: #000000;">&#40;</span>gameTime<span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>The last change is to the Draw method. You&#8217;ll see there is two lines used to draw the gems, and that&#8217;s what we need to do for our apples. Insert the two following lines after the code for the gems:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp"><span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>Apple apple <span style="color: #0600FF;">in</span> apples<span style="color: #000000;">&#41;</span>
    apple.<span style="color: #0000FF;">Draw</span><span style="color: #000000;">&#40;</span>gameTime, spriteBatch<span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>Now, to give this a spin, open the 0.txt level file and place some R&#8217;s here and there. When you start up the game you should see some red gems which falls down when you pass under them.</p>
<p>PS: A more clever approach here would be to create a base class for these classes, which would hold all the shared logic and methods, but the goal for this tutorial is to show how to implement the new feature as easily as possible.</p>
<p>Technorati Tags: <a href="http://technorati.com/tag/C%23" rel="tag">C#</a>, <a href="http://technorati.com/tag/XNA" rel="tag">XNA</a>, <a href="http://technorati.com/tag/Game+Development" rel="tag">Game Development</a></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-0056923567680782";
/* default */
google_ad_slot = "6546082201";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eirikhoem.net/index.php/2009/03/01/xna-platformer-starter-kit-falling-apples/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
