<?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>Tyler Forsythe&#039;s Blog</title>
	<atom:link href="http://tylerforsythe.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://tylerforsythe.com</link>
	<description>This blog is the game development outpouring of Tyler Forsythe</description>
	<lastBuildDate>Fri, 10 Feb 2012 06:18:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Learning XNA 2d Engine IceCream With 1945 Demo Project</title>
		<link>http://tylerforsythe.com/2012/02/learning-xna-2d-engine-icecream-with-1945-demo-project/</link>
		<comments>http://tylerforsythe.com/2012/02/learning-xna-2d-engine-icecream-with-1945-demo-project/#comments</comments>
		<pubDate>Fri, 10 Feb 2012 06:18:16 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[developer]]></category>
		<category><![CDATA[icecream]]></category>
		<category><![CDATA[xna]]></category>

		<guid isPermaLink="false">http://tylerforsythe.com/?p=91</guid>
		<description><![CDATA[Cross-posted to CodeProject. 1945_Code_Package &#8211; 1.5 MB 1945_Demo_Package &#8211; 542 KB IceCream1945 is a demonstration of XNA and the IceCream 2d library in a 2d top-down scrolling shooter similar to 1942 for the NES. Overview XNA is a wonderful game &#8230; <a href="http://tylerforsythe.com/2012/02/learning-xna-2d-engine-icecream-with-1945-demo-project/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.codeproject.com/Articles/327977/Learning-XNA-2d-Engine-IceCream-With-1945-Demo-Pro">Cross-posted to CodeProject</a>.</p>
<p><a href="http://tylerforsythe.com/wp-content/uploads/2012/02/1945_Code_Package.zip">1945_Code_Package</a> &#8211; 1.5 MB<br />
<a href="http://tylerforsythe.com/wp-content/uploads/2012/02/1945_Demo_Package.zip">1945_Demo_Package</a> &#8211; 542 KB</p>
<p><a href="http://tylerforsythe.com/wp-content/uploads/2012/02/1945_screenshot_full_small.jpg"><img class="alignnone size-full wp-image-93" title="1945_screenshot_full_small" src="http://tylerforsythe.com/wp-content/uploads/2012/02/1945_screenshot_full_small.jpg" alt="" width="600" height="350" /></a></p>
<p><em>IceCream1945 is a demonstration of XNA and the IceCream 2d library in a 2d top-down scrolling shooter similar to 1942 for the NES.</em></p>
<h2>Overview</h2>
<p>XNA is a wonderful game development SDK from Microsoft. It handles so many core game-engine features and allows you as the developer to jump right into the fun stuff. But because it&#8217;s open-ended to fit everyone, 2d and 3d games, it can be a bit much to work with once you&#8217;ve narrowed down the scope and type of game you want to make. If you&#8217;re making a 2d game, you start with a very powerful one-size-fits-all library that takes a lot of refinement. It makes sense to use another layer on top of XNA to get you even closer to your game type without yet having to write any code.</p>
<p>IceCream is a framework written in XNA to handle 2d sprite-based games. If that&#8217;s the sort of game you want to make, this article and framework are for you. If you want 3d, your time will be better spent reading something else.</p>
<p>Before diving into the meat of the article, I would encourage you to download the source code and sample demo application and give it a playthrough. It&#8217;s very short but demonstrates many of the things this article discusses: loading scenes, sprite movement, player input (WASD), enemies, bullets and collisions, animation, a scrolling background, etc. The controls are:</p>
<ul>
<li>Movement: W, A, S, and D</li>
<li>Fire bullet: Space</li>
<li>Drop bomb: Left Shift</li>
<li>Quit: Escape</li>
</ul>
<p>Now that you&#8217;ve seen the engine in action, let&#8217;s talk a little more about the framework.</p>
<h2>What is IceCream and its history?</h2>
<p>The IceCream library is the fruits of labor by Episcode (Loïc Dansart) and conkerjo. It hadn&#8217;t seen a repository commit since 2009 until I found it and asked if there was an update available for XNA 4.0 compatibility. I was in luck, as Loïc had already done all the work but just hadn&#8217;t committed it. A few hours later and the latest XNA 4.0 compatible code was committed and ready for action. The official code license as given by Loïc via email is to do whatever you want with it, as long as it&#8217;s not for a public derivative editor/engine.</p>
<h2>What&#8217;s Special About IceCream/Why Should I Use It?</h2>
<p>Why write yet another 2d engine for XNA when this one has tons of built-in functionality and a GUI editor? More specifically, IceCream has built-in support for spritesheets, static and animated sprites, layering, tile grids, particle effects, post-processing effects, and composite entities (think: 2d humanoid with arms and legs that are animated like a skeleton rather than a single whole sprite for each position). It even has a GUI editor for putting all those items into your levels (&#8220;scenes&#8221; as IceCream calls them).</p>
<p>IceCream is built on a component design model. Each SceneItem can have 0 or many Components, which are code pieces you write that do or control anything you want. The most basic type is a velocity component, which gives the sprite its movement. A velocity component might have a Vector2 to describe X and Y velocities, and every Update(), move the sprite by those amounts. But IceCream doesn&#8217;t have any built-in components or make assumptions about how you want to write your game. It just enables you to attach reusable code to every scene item, via components, that is given an Update() call every loop.</p>
<p>There is no override-able Draw() method because IceCream handles all drawing. That&#8217;s the only constraint of this engine. Since it does all the drawing, you don&#8217;t have the opportunity to do your own drawing if that&#8217;s your thing. But that&#8217;s also the point: all the drawing code has been written for you. (The exception to this is that your main game class, that inherits from IceCream.Game, does get a Draw() override, but components do not.)</p>
<p>If you feel it&#8217;s really lacking a drawing ability you want, however, it&#8217;s open-source, and you can easily jump in and modify it to your hearts desire. After working in the codebase for the past few months, I can say that it&#8217;s pretty easy to understand once you learn where things are. The drawing portion is a bit complicated because it&#8217;s extremely capable, but it&#8217;s not magic.</p>
<p>I&#8217;m going to skip over the details of the GUI because I&#8217;m assuming that you have some development experience and knowledge. Thus, the MilkShake UI should come pretty naturally in 10 to 15 minutes of self-exploration when opening the included project file (point MilkShake to IceCream1945/Game.icproj).</p>
<h2>Component Properties</h2>
<p>As I mentioned, IceCream is component based, and the primary location for your code is within these components. Each component can override the following methods:</p>
<ul>
<li>CopyValuesTo(object target) &#8211; Called regularly by the IceCream engine to perform deep-copies. Anytime you add properties to your component, you&#8217;ll need to add them to the copy operation that happens in this method. It&#8217;s up to you to decide what parts of the object&#8217;s state are relevant to a deep copy, and which should be skipped.</li>
<li>OnRegister() &#8211; Called whenever the parent SceneItem is registered with the scene, which happens when the scene is loaded into memory, or the next Update() after a SceneItem is new-ed and added to the scene (footnote: it&#8217;s also possible to tell a scene to register an item immediately rather than next Update()).</li>
<li>OnUnRegister() &#8211; Called whenever a SceneItem is marked for deletion and removed from the scene.</li>
<li>Update(float elapsedTime) &#8211; Called every loop for your component to advance state, whatever that might mean. This is where the real meat happens. A component to check for player input would do the input checking in this method. Likewise, our aforementioned VelocityComponent example would use this method to modify the X and Y position of it&#8217;s parent SceneItem.</li>
</ul>
<p>Sometimes it makes sense for these properties to display in the MilkShake GUI settings area when building the scene. To do this, we decorate those properties with [IceComponentProperty("text")]. This attribute is used to tell the MilkShake UI that this property should be editable in the property list UI, and what text description to use. Properties without this attribute are not exposed in MilkShake. The easy way to think of this is, if it has an IceComponentProperty decorator, it&#8217;s a configuration value in the editor. If not, it&#8217;s probably an internally managed state property.</p>
<p><em>Example of IceComponentProperty</em></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>IceComponentProperty<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Velocity Vector&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> Vector2 Velocity <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span></pre></div></div>

<p><em>Various Examples of IceCream Component Properties in the UI</em></p>
<p><a href="http://tylerforsythe.com/wp-content/uploads/2012/02/Property-Samples.jpg"><img class="alignnone size-full wp-image-98" title="Property Samples" src="http://tylerforsythe.com/wp-content/uploads/2012/02/Property-Samples.jpg" alt="" width="377" height="1042" /></a></p>
<p><em>Example: Full VelocityComponent</em></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">namespace</span> IceCream1945<span style="color: #008000;">.</span><span style="color: #0000FF;">Components</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #008000;">&#91;</span>IceComponentAttribute<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;VelocityComponent&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> VelocityComponent <span style="color: #008000;">:</span> IceComponent
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008000;">&#91;</span>IceComponentProperty<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Velocity Vector&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> Vector2 Velocity <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> VelocityComponent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            Enabled <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span><span style="color: #008080; font-style: italic;">//we manually Enable the component in other locations of code. By default, all components are enabled.</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnRegister<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> CopyValuesTo<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> target<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CopyValuesTo</span><span style="color: #008000;">&#40;</span>target<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>target <span style="color: #008000;">is</span> VelocityComponent<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                VelocityComponent targetCom <span style="color: #008000;">=</span> target <span style="color: #0600FF; font-weight: bold;">as</span> VelocityComponent<span style="color: #008000;">;</span>
                targetCom<span style="color: #008000;">.</span><span style="color: #0000FF;">Velocity</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Velocity</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> Update<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span> elapsedTime<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>Enabled<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Owner</span><span style="color: #008000;">.</span><span style="color: #0000FF;">PositionX</span> <span style="color: #008000;">+=</span> Velocity<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span> <span style="color: #008000;">*</span> elapsedTime<span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Owner</span><span style="color: #008000;">.</span><span style="color: #0000FF;">PositionY</span> <span style="color: #008000;">+=</span> Velocity<span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span> <span style="color: #008000;">*</span> elapsedTime<span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<h2>Getting Into the Code</h2>
<p>Moving past components and getting into intial game startup for IceCream1945 (not part of the core IceCream library), we have our MainGame class, which inherits from IceCream.Game. We can optionally override the common XNA methods like Update() and Draw(). I use this class for basic initialization, holding the current scene, and navigating among scenes (e.g., title screen to level 1, level 1 to game over, etc). In my sample, I wanted this class to be very lightweight and relatively dumb.</p>
<p>Again, this class is custom code, and not part of the standard IceCream codebase.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> MainGame <span style="color: #008000;">:</span> IceCream<span style="color: #008000;">.</span><span style="color: #0000FF;">Game</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> GameScene CurrentScene<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> <span style="color: #6666cc; font-weight: bold;">string</span> SplashIntroSceneName <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Splash&quot;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> <span style="color: #6666cc; font-weight: bold;">string</span> Level1SceneName <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Level1&quot;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> <span style="color: #6666cc; font-weight: bold;">string</span> EndingSceneName <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Ending&quot;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> MainGame<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">ContentDirectoryName</span> <span style="color: #008000;">=</span> ContentDirectoryName <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;IceCream1945Content&quot;</span><span style="color: #008000;">;</span>
		GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">ContentManager</span> <span style="color: #008000;">=</span> Content<span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> LoadContent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">LoadContent</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsFixedTimeStep</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
&nbsp;
		CurrentScene <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MenuScene<span style="color: #008000;">&#40;</span>SplashIntroSceneName<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		CurrentScene<span style="color: #008000;">.</span><span style="color: #0000FF;">LoadContent</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> Update<span style="color: #008000;">&#40;</span>GameTime gameTime<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">ShouldQuit</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>CurrentScene <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
				CurrentScene<span style="color: #008000;">.</span><span style="color: #0000FF;">UnloadContent</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Exit</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>CurrentScene<span style="color: #008000;">.</span><span style="color: #0000FF;">MoveToNextScene</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>CurrentScene<span style="color: #008000;">.</span><span style="color: #0000FF;">SceneName</span> <span style="color: #008000;">==</span> SplashIntroSceneName <span style="color: #008000;">||</span> CurrentScene<span style="color: #008000;">.</span><span style="color: #0000FF;">SceneName</span> <span style="color: #008000;">==</span> EndingSceneName<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
				CurrentScene<span style="color: #008000;">.</span><span style="color: #0000FF;">UnloadContent</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
				CurrentScene <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PlayScene<span style="color: #008000;">&#40;</span>Level1SceneName<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
				CurrentScene<span style="color: #008000;">.</span><span style="color: #0000FF;">LoadContent</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #008000;">&#125;</span>
			<span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>CurrentScene<span style="color: #008000;">.</span><span style="color: #0000FF;">SceneName</span> <span style="color: #008000;">==</span> Level1SceneName<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
				CurrentScene<span style="color: #008000;">.</span><span style="color: #0000FF;">UnloadContent</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
				CurrentScene <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MenuScene<span style="color: #008000;">&#40;</span>EndingSceneName<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
				CurrentScene<span style="color: #008000;">.</span><span style="color: #0000FF;">LoadContent</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #008000;">&#125;</span>
		<span style="color: #008000;">&#125;</span>
		<span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Update</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		CurrentScene<span style="color: #008000;">.</span><span style="color: #0000FF;">Update</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> Draw<span style="color: #008000;">&#40;</span>GameTime gameTime<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Draw</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		CurrentScene<span style="color: #008000;">.</span><span style="color: #0000FF;">Draw</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> UnloadContent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">UnloadContent</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The scene that I&#8217;m referring to here is different than the IceCream.Scene. I&#8217;ve created an abstract GameScene class that is the base class of PlayScene and MenuScene. This allows me to reuse common methods in GameScene but have specialized circumstance handling for a &#8220;menu&#8221;-like scene vs a &#8220;gameplay&#8221; scene (and potentially others). In a GameScene, I&#8217;m expecting for the player to be actively controlling a game object, for the AI to be thinking, and for the camera to be moving. But a MenuScene is all about presenting information and waiting for user input. Hence, I felt it would be more clear to split the two cases into separate objects rather than litter a single object with conditionals.</p>
<p><em>MenuScene Class Update() method</em></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> Update<span style="color: #008000;">&#40;</span>GameTime gameTime<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Update</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #6666cc; font-weight: bold;">float</span> elapsed <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#41;</span>gameTime<span style="color: #008000;">.</span><span style="color: #0000FF;">ElapsedGameTime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TotalSeconds</span><span style="color: #008000;">;</span>
&nbsp;
	IceCream<span style="color: #008000;">.</span><span style="color: #0000FF;">Debug</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OnScreenStats</span><span style="color: #008000;">.</span><span style="color: #0000FF;">AddStat</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;FPS: {0:0.00}&quot;</span>, DrawCount <span style="color: #008000;">/</span> gameTime<span style="color: #008000;">.</span><span style="color: #0000FF;">TotalGameTime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TotalSeconds</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>ReadInput <span style="color: #008000;">||</span> WaitBeforeInput<span style="color: #008000;">.</span><span style="color: #0000FF;">Stopwatch</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">100</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		ReadInput <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>InputCore<span style="color: #008000;">.</span><span style="color: #0000FF;">IsAnyKeyDown</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			MoveToNextScene <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<h2>Preloading, Caching, and GlobalGameData</h2>
<p><em>GlobalGameData Class and Startup Caching</em></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">class</span> GlobalGameData
<span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> ContentManager ContentManager <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> ShouldQuit <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> ContentDirectoryName <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">int</span> ResolutionHeight <span style="color: #008000;">=</span> <span style="color: #FF0000;">720</span>, ResolutionWidth <span style="color: #008000;">=</span> <span style="color: #FF0000;">1280</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">int</span> PlayerHealth<span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">int</span> MaxPlayerHealth <span style="color: #008000;">=</span> <span style="color: #FF0000;">18</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> SoundOn <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> MusicOn <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">float</span> SoundEffectVolume <span style="color: #008000;">=</span> 0<span style="color: #008000;">.</span>3f<span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">float</span> MusicVolume <span style="color: #008000;">=</span> 0<span style="color: #008000;">.</span>3f<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> List InactiveSceneItems <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>SceneItem<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> List ActiveSceneItems <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>SceneItem<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> SceneItem PlayerAnimatedSprite <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> PostProcessAnimation ScreenDamageEffect <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> PointTracking PlayerOnePointTracking <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PointTracking<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">PlayerAnimatedSprite</span> <span style="color: #008000;">=</span> scene<span style="color: #008000;">.</span><span style="color: #0000FF;">GetSceneItem</span><span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>AnimatedSprite<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;PlayerPlane_1&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
HealthBarItem <span style="color: #008000;">=</span> scene<span style="color: #008000;">.</span><span style="color: #0000FF;">GetSceneItem</span><span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>Sprite<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;HealthBar&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">PlayerHealth</span> <span style="color: #008000;">=</span> GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">MaxPlayerHealth</span><span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">//[...]</span>
GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">ScreenDamageEffect</span> <span style="color: #008000;">=</span> scene<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateCopy</span><span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>PostProcessAnimation<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;PlayerDamageScreenEffect&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">ScreenDamageEffect</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Stop</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
scene<span style="color: #008000;">.</span><span style="color: #0000FF;">RegisterSceneItem</span><span style="color: #008000;">&#40;</span>GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">ScreenDamageEffect</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">//[...]</span>
<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>SceneItem si <span style="color: #0600FF; font-weight: bold;">in</span> scene<span style="color: #008000;">.</span><span style="color: #0000FF;">SceneItems</span><span style="color: #008000;">&#41;</span>
	GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">InactiveSceneItems</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>si<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">//sort the inactive list so we only have to look at the very first one to know if there is anything to activate.</span>
GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">InactiveSceneItems</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Sort</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">delegate</span><span style="color: #008000;">&#40;</span>SceneItem a, SceneItem b<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> b<span style="color: #008000;">.</span><span style="color: #0000FF;">PositionY</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CompareTo</span><span style="color: #008000;">&#40;</span>a<span style="color: #008000;">.</span><span style="color: #0000FF;">PositionY</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>GlobalGameData is a singleton class (my custom code, not part of base IceCream) that holds references to game settings and commonly used objects. During things like collision detection, it&#8217;s necessary to run through all scene items for detection. Something like that is extremely slow and can catch up to you after your game is past a simple proof of concept. So I&#8217;ve created Active and InactiveSceneItems lists for just this purpose. When running through items looking for collisions, I only look through what&#8217;s active, which I consider to be sprites that are shown on screen or have moved beyond it (though those should be eliminated automatically by a bounds detection component). This way I&#8217;m not checking scene items at the end of the level when the player just starts, and I can control the enabling of scene items as the player moves throughout the level rather than having all sprites immediately start traversing the level.</p>
<p>There are faster methods, such as dividing the screen into quadrants or other sectioning, but for now, an active list of only on-screen SceneItems is more than fast enough.</p>
<p>Additionally, things like the health box and score are moved every frame to be at the top of the screen while the camera moves &#8220;upward&#8221;. This requires the code to always touch the PositionY property, and it&#8217;s very wasteful to find these objects every frame. So we find them once and keep a reference at our fingertips.</p>
<p>Essentially, GlobalGameData is where &#8220;global&#8221; variables are held. In a more robust game, these references would probably be split into more concise objects, such as a static Settings object and a SceneItemCache object, or corrosponding management-type objects. But in all cases, we only need and want one copy of this data, and we want it accessible from nearly everywhere in our game. We don&#8217;t want to have to pass around some sort of context object to all our methods when a globally-accessible context object will work just the same (because we&#8217;ll never need to have two context&#8217;s co-exist in a single running instance). There is a fine line between &#8220;global variables are bad&#8221; and bloating all your method signatures to pass a reference to an object throughout your code.</p>
<h2>Game Loop: Scene Movement and Background Scrolling</h2>
<p>The scene is moved along with actual movement of the camera. Some scrollers work by moving the scene into the view of a static camera or other indirect ways, but I decided it was most efficient and mentally straight-forward to move just the camera and have it scan across the level. Some of the reasons include:</p>
<ol>
<li>If I had to move the scene into the view of the camera, I would need to modify the position of every single scene item every single frame to move them into the view of the camera. By moving the camera, only the scene items actually moving via AI have to move.</li>
<li>Keeping the camera static but spawning objects just outside the view of the camera via a script adds significant code and GUI complexity.</li>
<li>The GUI editor is already setup for camera movement over a laid-out scene. The point of using IceCream is to leverage the tools someone else has written.</li>
</ol>
<p><em>Code of Camera Movement</em></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">float</span> ScrollPerUnit <span style="color: #008000;">=</span> 60<span style="color: #008000;">.</span>0f<span style="color: #008000;">;</span>
<span style="color: #008000;">&#91;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#93;</span>
<span style="color: #6666cc; font-weight: bold;">float</span> elapsed <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#41;</span>gameTime<span style="color: #008000;">.</span><span style="color: #0000FF;">ElapsedGameTime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TotalSeconds</span><span style="color: #008000;">;</span>
<span style="color: #6666cc; font-weight: bold;">float</span> distance <span style="color: #008000;">=</span> elapsed <span style="color: #008000;">*</span> ScrollPerUnit<span style="color: #008000;">;</span>
&nbsp;
scene<span style="color: #008000;">.</span><span style="color: #0000FF;">ActiveCameras</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">PositionY</span> <span style="color: #008000;">-=</span> distance<span style="color: #008000;">;</span>
BoundsComponent<span style="color: #008000;">.</span><span style="color: #0000FF;">ResetScreenBounds</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>The background movement is only partially real. It&#8217;s just a single sprite the width of the screen and 32 pixels tall, duplicated to the height of the screen plus two. Each time the bottom strip disappears from the view of the camera, it is shuffled to the top. So the background images are perpetually being moved bottom to top as the camera moves along the scene, and we don&#8217;t have to waste memory copying the strip to the entire vertical length of the scene. We only need enough memory to cover the users view.</p>
<p><em>Code of Construction of Background Sprites</em></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/* Load Background Water sprites */</span>
Sprite water <span style="color: #008000;">=</span> scene<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateCopy</span><span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>Sprite<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Water1280&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
WaterHeight <span style="color: #008000;">=</span> water<span style="color: #008000;">.</span><span style="color: #0000FF;">BoundingRectSize</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span><span style="color: #008000;">;</span>
<span style="color: #6666cc; font-weight: bold;">double</span> totalWaters <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Ceiling</span><span style="color: #008000;">&#40;</span>GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">ResolutionHeight</span> <span style="color: #008000;">/</span> WaterHeight<span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> totalWaters<span style="color: #008000;">;</span> <span style="color: #008000;">++</span>i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	Sprite w <span style="color: #008000;">=</span> scene<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateCopy</span><span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>Sprite<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Water1280&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	w<span style="color: #008000;">.</span><span style="color: #0000FF;">Layer</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">;</span>
	w<span style="color: #008000;">.</span><span style="color: #0000FF;">PositionX</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
	w<span style="color: #008000;">.</span><span style="color: #0000FF;">PositionY</span> <span style="color: #008000;">=</span> i <span style="color: #008000;">*</span> WaterHeight<span style="color: #008000;">;</span>
	scene<span style="color: #008000;">.</span><span style="color: #0000FF;">RegisterSceneItem</span><span style="color: #008000;">&#40;</span>w<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	BackgroundWaters<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>w<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p><em>Code of Background Sprite Movement and Swapping</em></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/* Background Water Movement (totally fake)
 * Since our camera is moving up the Y axis, all we have to do is shift the background upwards
 * everytime the camera moves the equivalent of a tile height. */</span>
BackgroundOffset <span style="color: #008000;">+=</span> distance<span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>BackgroundOffset <span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span> WaterHeight<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>Sprite water <span style="color: #0600FF; font-weight: bold;">in</span> BackgroundWaters<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		water<span style="color: #008000;">.</span><span style="color: #0000FF;">PositionY</span> <span style="color: #008000;">-=</span> WaterHeight<span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
	BackgroundOffset <span style="color: #008000;">-=</span> WaterHeight<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>For sprite and camera movement, I decided to move things in the game based upon the time that has passed between update calls. XNA likes to run at 60 fps regardless of whether you enable IsFixedTimeStep, and in a low complexity game as it is right now it doesn&#8217;t make much difference. But if our framerate ever starts to drop due to scene complexity, this design decision will keep the game more playable and consistent.</p>
<p><em>Example of Time-Based Sprite Movement</em></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> Update<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span> elapsedTime<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>Enabled<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Owner</span><span style="color: #008000;">.</span><span style="color: #0000FF;">PositionX</span> <span style="color: #008000;">+=</span> Velocity<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span> <span style="color: #008000;">*</span> elapsedTime<span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Owner</span><span style="color: #008000;">.</span><span style="color: #0000FF;">PositionY</span> <span style="color: #008000;">+=</span> Velocity<span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span> <span style="color: #008000;">*</span> elapsedTime<span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The other way to write this method is to move each sprite a flat X number of pixels each call to update, regardless of how much time has passed. Very old games written in the 80&#8242;s and early 90&#8242;s that used this method are out of control on today&#8217;s PCs. Back then, developers didn&#8217;t think their games would still be played today, so they were written to go all-out with no limiter of any kind in place. I think it&#8217;s important to realize your code has much more life in it than you think.</p>
<p>To prevent that scenario from happening in the inevitable future, the XNA framework is supposed to be intelligent enough to cap the framerate at 60 frames per second even if the hardware can play your game much faster.</p>
<h2>Player Movement and Firing: PlayerControllableComponent</h2>
<p>The PlayerControllableComponent is applied to the sprite that the player controls. It watches for input via IceInput and moves the sprite accordingly. It&#8217;s setup for multiple players, but I have not implemented it. The rest of the code could easily be modified for co-op, but I decided it was out of scope for my first exercise.</p>
<p><em>PlayerControllableComponent Class Update()</em></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> Update<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span> elapsedTime<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">// when the owner uses PlayerIndex.One</span>
	<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>Playerindex <span style="color: #008000;">==</span> PlayerIndex<span style="color: #008000;">.</span><span style="color: #0000FF;">One</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #008080; font-style: italic;">// if W button is pressed</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>InputCore<span style="color: #008000;">.</span><span style="color: #0000FF;">IsKeyDown</span><span style="color: #008000;">&#40;</span>Keys<span style="color: #008000;">.</span><span style="color: #0000FF;">W</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #008080; font-style: italic;">// we go upwards</span>
			Owner<span style="color: #008000;">.</span><span style="color: #0000FF;">PositionY</span> <span style="color: #008000;">-=</span> Velocity<span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
		<span style="color: #008080; font-style: italic;">// if S key is pressed</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>InputCore<span style="color: #008000;">.</span><span style="color: #0000FF;">IsKeyDown</span><span style="color: #008000;">&#40;</span>Keys<span style="color: #008000;">.</span><span style="color: #0000FF;">S</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #008080; font-style: italic;">// we go downwards</span>
			Owner<span style="color: #008000;">.</span><span style="color: #0000FF;">PositionY</span> <span style="color: #008000;">+=</span> Velocity<span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
		<span style="color: #008080; font-style: italic;">// if A button is pressed</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>InputCore<span style="color: #008000;">.</span><span style="color: #0000FF;">IsKeyDown</span><span style="color: #008000;">&#40;</span>Keys<span style="color: #008000;">.</span><span style="color: #0000FF;">A</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #008080; font-style: italic;">// we go to the left</span>
			Owner<span style="color: #008000;">.</span><span style="color: #0000FF;">PositionX</span> <span style="color: #008000;">-=</span> Velocity<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
		<span style="color: #008080; font-style: italic;">// if D button is pressed</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>InputCore<span style="color: #008000;">.</span><span style="color: #0000FF;">IsKeyDown</span><span style="color: #008000;">&#40;</span>Keys<span style="color: #008000;">.</span><span style="color: #0000FF;">D</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #008080; font-style: italic;">// we go to the right</span>
			Owner<span style="color: #008000;">.</span><span style="color: #0000FF;">PositionX</span> <span style="color: #008000;">+=</span> Velocity<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>BulletTimer<span style="color: #008000;">.</span><span style="color: #0000FF;">Stopwatch</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">100</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;&amp;</span>amp<span style="color: #008000;">;</span> InputCore<span style="color: #008000;">.</span><span style="color: #0000FF;">IsKeyDown</span><span style="color: #008000;">&#40;</span>Keys<span style="color: #008000;">.</span><span style="color: #0000FF;">Space</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #008080; font-style: italic;">//fire projectile</span>
			AnimatedSprite newBullet <span style="color: #008000;">=</span> Owner<span style="color: #008000;">.</span><span style="color: #0000FF;">SceneParent</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CreateCopy</span><span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>AnimatedSprite<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;FlamingBullet&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			newBullet<span style="color: #008000;">.</span><span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
			newBullet<span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span> <span style="color: #008000;">=</span> Owner<span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span><span style="color: #008000;">;</span>
			newBullet<span style="color: #008000;">.</span><span style="color: #0000FF;">PositionX</span> <span style="color: #008000;">+=</span> Owner<span style="color: #008000;">.</span><span style="color: #0000FF;">BoundingRectSize</span><span style="color: #008000;">.</span><span style="color: #0000FF;">X</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span>
			VelocityComponent velocityCom <span style="color: #008000;">=</span> newBullet<span style="color: #008000;">.</span><span style="color: #0000FF;">GetComponent</span><span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>VelocityComponent<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			velocityCom<span style="color: #008000;">.</span><span style="color: #0000FF;">Enabled</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
			Owner<span style="color: #008000;">.</span><span style="color: #0000FF;">SceneParent</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RegisterSceneItem</span><span style="color: #008000;">&#40;</span>newBullet<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			Sound<span style="color: #008000;">.</span><span style="color: #0000FF;">Play</span><span style="color: #008000;">&#40;</span>Sound<span style="color: #008000;">.</span><span style="color: #0000FF;">Laser_Shoot_Player</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>BombTimer<span style="color: #008000;">.</span><span style="color: #0000FF;">Stopwatch</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">100</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;&amp;</span>amp<span style="color: #008000;">;</span> InputCore<span style="color: #008000;">.</span><span style="color: #0000FF;">IsKeyDown</span><span style="color: #008000;">&#40;</span>Keys<span style="color: #008000;">.</span><span style="color: #0000FF;">LeftShift</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #008080; font-style: italic;">//drop bomb</span>
			Sprite newBullet <span style="color: #008000;">=</span> Owner<span style="color: #008000;">.</span><span style="color: #0000FF;">SceneParent</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CreateCopy</span><span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>Sprite<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Bomb&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			newBullet<span style="color: #008000;">.</span><span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
			newBullet<span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span> <span style="color: #008000;">=</span> Owner<span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span><span style="color: #008000;">;</span>
			newBullet<span style="color: #008000;">.</span><span style="color: #0000FF;">PositionX</span> <span style="color: #008000;">+=</span> Owner<span style="color: #008000;">.</span><span style="color: #0000FF;">BoundingRectSize</span><span style="color: #008000;">.</span><span style="color: #0000FF;">X</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span>
			Owner<span style="color: #008000;">.</span><span style="color: #0000FF;">SceneParent</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RegisterSceneItem</span><span style="color: #008000;">&#40;</span>newBullet<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #008080; font-style: italic;">//[...] Unused code relating to PlayerTwo</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>InputCore<span style="color: #008000;">.</span><span style="color: #0000FF;">IsKeyDown</span><span style="color: #008000;">&#40;</span>Keys<span style="color: #008000;">.</span><span style="color: #0000FF;">Escape</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">ShouldQuit</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>This component watches for all player input, including the fire and drop-bomb buttons, so it also handles spawning those scene items when necessary. IceCream allows us to handle this very easily. With MilkShake, I created a FlamingBullet animated sprite with the following components already attached and configured:</p>
<ul>
<li>VelocityComponent: Give this bullet X and Y velocity.</li>
<li>LifeComponent: If this bullet lives for longer than 2 seconds, destroy it. This prevents bullets from slipping through other checks and living forever. This is more useful for testing by throwing an exception if 2 seconds is ever reached. Currently, no player bullets should live that long, so anything that does is an error. It&#8217;s possible and even prudent to write some components as small tests to ensure other components are doing their job.</li>
<li>BoundsComponent: If this bullet moves completely out of view of the camera, destroy it. We don&#8217;t want the player destroying objects all the way down the level.</li>
<li>BulletComponent: This component handles checking for collisions and dealing damage.</li>
</ul>
<p>When the player fires a flaming bullet, I ask IceCream to make a copy of this template, tweak the speed on the VelocityComponent, and register the scene item with IceCream. The IceCream engine and my components then take over the rest, and the PlayerControllableComponent can completely forget about it.</p>
<h2>Collision Detection</h2>
<p>Collision detection in this demo application is only relevant for &#8220;bullets&#8221;, aka projectiles. The player fires bullets, and enemies fire bullets. Each bullet is an animated sprite with a BulletComponent, which has 2 flags for whether it can damage the player and whether it can damage enemies (it could be both).</p>
<p>When this component executes Update(), it looks through all scene items in the ActiveSceneItems list and compares its bounding rectangle to the bullets. If they intersect, it&#8217;s a collision. A better way of it doing it that I didn&#8217;t implement here is, after it&#8217;s determined the rectangles cross, drop into a more granular test of either pixel-by-pixel, or polygon detection. However, I again decided this was out of scope for this initial exercise. IceCream has some initial support for polygon collision detection, but it&#8217;s not yet fully implemented.</p>
<p>If there is a collision, an explosion animation is spawned and damage is applied appropriately. For enemies, right now they simply die. The player, however, has a life bar that decreases per hit. Additionally, if the player is hit, a post-processing effect is briefly played that causes the screen to blur and flash very briefly. This gives the player visual feedback that they were struck that is far more noticeable than looking to see if bullets hit or life decreased. It catches their attention regardless of what part of the screen they&#8217;re looking at.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> Update<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span> elapsedTime<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">//We get all scene items ( not recommended in bigger games, at least not every frame)</span>
	<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i<span style="color: #008000;">=</span><span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">ActiveSceneItems</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span> <span style="color: #008000;">++</span>i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		SceneItem si <span style="color: #008000;">=</span> GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">ActiveSceneItems</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>si <span style="color: #008000;">!=</span> Owner <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;&amp;</span>amp<span style="color: #008000;">;</span> <span style="color: #008000;">&#40;</span>si<span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>Sprite<span style="color: #008000;">&#41;</span> <span style="color: #008000;">||</span> si<span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>AnimatedSprite<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;&amp;</span>amp<span style="color: #008000;">;</span> <span style="color: #008000;">!</span>Owner<span style="color: #008000;">.</span><span style="color: #0000FF;">MarkForDelete</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>CanDamageEnemy<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
				<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>si<span style="color: #008000;">.</span><span style="color: #0000FF;">CheckType</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;&amp;</span>amp<span style="color: #008000;">;</span> Owner<span style="color: #008000;">.</span><span style="color: #0000FF;">BoundingRect</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Intersects</span><span style="color: #008000;">&#40;</span>si<span style="color: #008000;">.</span><span style="color: #0000FF;">BoundingRect</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
					si<span style="color: #008000;">.</span><span style="color: #0000FF;">MarkForDelete</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
					Owner<span style="color: #008000;">.</span><span style="color: #0000FF;">MarkForDelete</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
					GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">ActiveSceneItems</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Remove</span><span style="color: #008000;">&#40;</span>si<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
					GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">ActiveSceneItems</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Remove</span><span style="color: #008000;">&#40;</span>Owner<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
					<span style="color: #008000;">--</span>i<span style="color: #008000;">;</span>
&nbsp;
					AnimatedSprite explosion <span style="color: #008000;">=</span> Owner<span style="color: #008000;">.</span><span style="color: #0000FF;">SceneParent</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CreateCopy</span><span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>AnimatedSprite<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;BigExplosion&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
					explosion<span style="color: #008000;">.</span><span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
					explosion<span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span> <span style="color: #008000;">=</span> si<span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span><span style="color: #008000;">;</span>
					explosion<span style="color: #008000;">.</span><span style="color: #0000FF;">PositionX</span> <span style="color: #008000;">+=</span> si<span style="color: #008000;">.</span><span style="color: #0000FF;">BoundingRectSize</span><span style="color: #008000;">.</span><span style="color: #0000FF;">X</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span>
					explosion<span style="color: #008000;">.</span><span style="color: #0000FF;">PositionY</span> <span style="color: #008000;">+=</span> si<span style="color: #008000;">.</span><span style="color: #0000FF;">BoundingRectSize</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span>
					explosion<span style="color: #008000;">.</span><span style="color: #0000FF;">CurrentAnimation</span><span style="color: #008000;">.</span><span style="color: #0000FF;">LoopMax</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
					explosion<span style="color: #008000;">.</span><span style="color: #0000FF;">CurrentAnimation</span><span style="color: #008000;">.</span><span style="color: #0000FF;">HideWhenStopped</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
					Owner<span style="color: #008000;">.</span><span style="color: #0000FF;">SceneParent</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RegisterSceneItem</span><span style="color: #008000;">&#40;</span>explosion<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
					GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">PlayerOnePointTracking</span><span style="color: #008000;">.</span><span style="color: #0000FF;">AddScore</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">50</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
					Sound<span style="color: #008000;">.</span><span style="color: #0000FF;">Play</span><span style="color: #008000;">&#40;</span>Sound<span style="color: #008000;">.</span><span style="color: #0000FF;">ExplosionHit</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
				<span style="color: #008000;">&#125;</span>
			<span style="color: #008000;">&#125;</span>
			<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>CanDamagePlayer<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
				<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>Owner<span style="color: #008000;">.</span><span style="color: #0000FF;">BoundingRect</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Intersects</span><span style="color: #008000;">&#40;</span>GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">PlayerAnimatedSprite</span><span style="color: #008000;">.</span><span style="color: #0000FF;">BoundingRect</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
					<span style="color: #008000;">--</span>GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">PlayerHealth</span><span style="color: #008000;">;</span>
					Owner<span style="color: #008000;">.</span><span style="color: #0000FF;">MarkForDelete</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
&nbsp;
					GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">ScreenDamageEffect</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Reset</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><span style="color: #008080; font-style: italic;">//if the player is getting bombarded, we want many flashes</span>
					GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">ScreenDamageEffect</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Play</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
					Sound<span style="color: #008000;">.</span><span style="color: #0000FF;">Play</span><span style="color: #008000;">&#40;</span>Sound<span style="color: #008000;">.</span><span style="color: #0000FF;">Quick_Hit</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
				<span style="color: #008000;">&#125;</span>
			<span style="color: #008000;">&#125;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<h2>Post Processing Effect on Player-Bullet Collision</h2>
<p>As I mentioned earlier, IceCream supports various post-prcessing effects out of the box. Many classic scrolling shooters have some sort of screen-flashing effect when the player is hit and loses a health point. A post-processing effect is the natural way to pull off this trick. I load and cache the effect when the scene is first loaded, and just instruct IceCream to play it a single time whenever a collision occurs.</p>
<p>I set up the effect through this UI in Milkshake:</p>
<p><a href="http://tylerforsythe.com/wp-content/uploads/2012/02/PostProcessorUI_2.jpg"><img class="alignnone size-full wp-image-94" title="PostProcessorUI_2" src="http://tylerforsythe.com/wp-content/uploads/2012/02/PostProcessorUI_2.jpg" alt="" width="861" height="614" /></a></p>
<p>And then call it in the BulletComponent. I call Reset() before I call play, so if the player is hit repeatedly the effect will start over instantly rather than only finishing playing once. I think this sort of immediate feedback to the player is key to a game that feels &#8220;tight&#8221;.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>CanDamagePlayer<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>Owner<span style="color: #008000;">.</span><span style="color: #0000FF;">BoundingRect</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Intersects</span><span style="color: #008000;">&#40;</span>GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">PlayerAnimatedSprite</span><span style="color: #008000;">.</span><span style="color: #0000FF;">BoundingRect</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #008000;">--</span>GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">PlayerHealth</span><span style="color: #008000;">;</span>
		Owner<span style="color: #008000;">.</span><span style="color: #0000FF;">MarkForDelete</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
&nbsp;
		GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">ScreenDamageEffect</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Reset</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><span style="color: #008080; font-style: italic;">//if the player is getting bombarded, we want many flashes</span>
		GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">ScreenDamageEffect</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Play</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		Sound<span style="color: #008000;">.</span><span style="color: #0000FF;">Play</span><span style="color: #008000;">&#40;</span>Sound<span style="color: #008000;">.</span><span style="color: #0000FF;">Quick_Hit</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<h2>Enemy Movement and AI, and Tags Feature</h2>
<p>One of the wonderful things about IceCream being open-source is that you&#8217;re free to modify it if you don&#8217;t think it serves all your needs. One of the neat changes I made was to add a &#8220;tags&#8221; property, which is a simple list of strings that I use for grouping and other attributes. Because it would be slow to parse this tag data during game-play, I parse and cache in one pass when the scene is loaded.</p>
<p><em>Group (Tag) Caching</em></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">protected</span> Dictionary<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>string, List<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>SceneItem<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;&amp;</span>gt<span style="color: #008000;">;</span> Cache_TagItems<span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> GameScene<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> sceneName<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #008000;">&#91;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#93;</span>
	Cache_TagItems <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Dictionary<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>string, List<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>SceneItem<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> LoadContent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #008000;">&#91;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#93;</span>
	CacheTagItems<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#91;</span><span style="color: #008000;">...</span><span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetGroupTagFor<span style="color: #008000;">&#40;</span>SceneItem si<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> tag <span style="color: #0600FF; font-weight: bold;">in</span> si<span style="color: #008000;">.</span><span style="color: #0000FF;">Tags</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>tag<span style="color: #008000;">.</span><span style="color: #0000FF;">StartsWith</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;group&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> tag<span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> CacheTagItems<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>scene <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
		<span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> Exception<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Can't cache tags before loading a scene (scene == null)&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>SceneItem si <span style="color: #0600FF; font-weight: bold;">in</span> scene<span style="color: #008000;">.</span><span style="color: #0000FF;">SceneItems</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> tag <span style="color: #0600FF; font-weight: bold;">in</span> si<span style="color: #008000;">.</span><span style="color: #0000FF;">Tags</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #008000;">&#40;</span>tag<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
				<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>Cache_TagItems<span style="color: #008000;">.</span><span style="color: #0000FF;">ContainsKey</span><span style="color: #008000;">&#40;</span>tag<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
					Cache_TagItems<span style="color: #008000;">&#91;</span>tag<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>SceneItem<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
				<span style="color: #008000;">&#125;</span>
				Cache_TagItems<span style="color: #008000;">&#91;</span>tag<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>si<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #008000;">&#125;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> List GetItemsWithTag<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> tag<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>Cache_TagItems<span style="color: #008000;">.</span><span style="color: #0000FF;">ContainsKey</span><span style="color: #008000;">&#40;</span>tag<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
		<span style="color: #0600FF; font-weight: bold;">return</span> Cache_TagItems<span style="color: #008000;">&#91;</span>tag<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">else</span>
		<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>In IceCream1945, the primary use of tags is for grouping enemies. As the level is scrolled, each Update() call checks to see if a sprite has crossed a threshold near the camera&#8217;s view and should come to life in the scene. Because this is a top-down shooter, sprites tend to come to life in waves. That is, 4 or more sprites will move across the scene as one. To facilitate this, each sprite is assigned a group through the tag mechanism. When one sprite is activated, the group tag is read, and all other scene items with a matching group are activated. This activates the entire &#8220;wave&#8221; and keeps them moving as one without extra code or level design complexity.</p>
<p><em>SceneItem Activation and Group Activation Snippet</em></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">int</span> activationBufferUnits <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i<span style="color: #008000;">=</span><span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">InactiveSceneItems</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span> <span style="color: #008000;">++</span>i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	SceneItem si <span style="color: #008000;">=</span> GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">InactiveSceneItems</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>si<span style="color: #008000;">.</span><span style="color: #0000FF;">BoundingRect</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Bottom</span> <span style="color: #008000;">+</span> activationBufferUnits <span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span> scene<span style="color: #008000;">.</span><span style="color: #0000FF;">ActiveCameras</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">BoundingRect</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Top</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #008080; font-style: italic;">//grab all other scene items in the same group and turn them on as well</span>
		EnableSceneItem<span style="color: #008000;">&#40;</span>si<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">InactiveSceneItems</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RemoveAt</span><span style="color: #008000;">&#40;</span>i<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">--</span>i<span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #6666cc; font-weight: bold;">string</span> groupTag <span style="color: #008000;">=</span> GetGroupTagFor<span style="color: #008000;">&#40;</span>si<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>groupTag <span style="color: #008000;">==</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">&#41;</span>
			<span style="color: #0600FF; font-weight: bold;">continue</span><span style="color: #008000;">;</span>
		List groupItems <span style="color: #008000;">=</span> GetItemsWithGroupTag<span style="color: #008000;">&#40;</span>groupTag<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>SceneItem gsi <span style="color: #0600FF; font-weight: bold;">in</span> groupItems<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			EnableSceneItem<span style="color: #008000;">&#40;</span>gsi<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			GlobalGameData<span style="color: #008000;">.</span><span style="color: #0000FF;">InactiveSceneItems</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Remove</span><span style="color: #008000;">&#40;</span>gsi<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008080; font-style: italic;">//if we didn't find anything to activate, we can just abort the loop. Our inactive list is sorted</span>
		<span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">//so that the &quot;earliest&quot; items are first. Thus, continuing the loop is pointless.</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<h2>Scoring and Achievements</h2>
<p>Finally, for scoring and achievement tracking, I have a PointTracking singleton that can be created per-player (or configured for multi-player storage) if you wanted to add multi-player support. Right now it&#8217;s only used for scoring, but it&#8217;s intended to be in scope for the entire application for other things like number of shots fired, number of kills, etc that can be fun stats to view at the end of a level, or even track for the life of a player and grant achievements.</p>
<p><em>PointTracking code snippet</em></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &amp;lt;summary&amp;gt;</span>
<span style="color: #008080; font-style: italic;">/// General class for tracking score, number of kills, shots fired, and other metrics for achivements and similar</span>
<span style="color: #008080; font-style: italic;">/// &amp;lt;/summary&amp;gt;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> PointTracking
<span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> PlayerScore <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">private</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> AddScore<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> additionalPoints<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		PlayerScore <span style="color: #008000;">+=</span> additionalPoints<span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>That concludes this intro to the 2d XNA IceCream library through the sample game IceCream1945. I hope you enjoyed the article and will download the sample application and source code. IceCream is a phenominal library that deserves more attention and contributions.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://tylerforsythe.com/2012/02/learning-xna-2d-engine-icecream-with-1945-demo-project/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>XNA SpriteBatch.Draw (and IceCream) Use a Rotation Value in Radians</title>
		<link>http://tylerforsythe.com/2011/11/xna-spritebatch-draw-and-icecream-use-a-rotation-value-in-radians/</link>
		<comments>http://tylerforsythe.com/2011/11/xna-spritebatch-draw-and-icecream-use-a-rotation-value-in-radians/#comments</comments>
		<pubDate>Tue, 29 Nov 2011 02:18:27 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[developer]]></category>
		<category><![CDATA[icecream]]></category>
		<category><![CDATA[xna]]></category>

		<guid isPermaLink="false">http://tylerforsythe.com/?p=86</guid>
		<description><![CDATA[Note to self: XNA SpriteBatch.Draw, and by extension the IceCream framework, expect the rotation value to be in radians, not degrees. This took far too long for me to find.]]></description>
			<content:encoded><![CDATA[<p>Note to self: XNA SpriteBatch.Draw, and by extension the IceCream framework, expect the rotation value to be in radians, not degrees. <a href="http://msdn.microsoft.com/en-us/library/bb203869.aspx">This took far too long for me to find</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://tylerforsythe.com/2011/11/xna-spritebatch-draw-and-icecream-use-a-rotation-value-in-radians/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Peer to Peer Networking Example Using the Lidgren.Network Framework</title>
		<link>http://tylerforsythe.com/2011/11/peer-to-peer-networking-example-using-the-lidgren-network-framework/</link>
		<comments>http://tylerforsythe.com/2011/11/peer-to-peer-networking-example-using-the-lidgren-network-framework/#comments</comments>
		<pubDate>Fri, 11 Nov 2011 02:26:23 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[developer]]></category>
		<category><![CDATA[networking]]></category>

		<guid isPermaLink="false">http://lonecone.com/?p=74</guid>
		<description><![CDATA[Brief topic switch: Peer to peer networking. I had wanted to get this example in a simple movement game in IceCream but found I needed to start with a console app first. So here it is. I&#8217;ve cleverly named it &#8230; <a href="http://tylerforsythe.com/2011/11/peer-to-peer-networking-example-using-the-lidgren-network-framework/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Brief topic switch: Peer to peer networking. I had wanted to get this example in a simple movement game in IceCream but found I needed to start with a console app first. So here it is. I&#8217;ve cleverly named it NetConsoles, and the purpose is to teach myself how to link multiple nodes in a peer to peer fashion using the <a href="http://code.google.com/p/lidgren-network-gen3/">Lidgren.Network framework</a>. While I had some initial issues, it wasn&#8217;t all that hard.</p>
<p>Nearly every example I could find using Lidgren.Network was a client/server architecture, so I had to do quite a bit of experimenting to get peer to peer going. Finding sample code for it was completely fruitless. But I did see a post indicating it is possible and relatively easy, so I pressed on. <strong>It turns out that the base object of NetClient and NetServer is NetPeer, and it&#8217;s all you need to connect p2p</strong> (I&#8217;m now tired of typing it out).</p>
<p>Two things stand out from this experience: the first is that I tried to create a semi-contained and reusable networking object. It&#8217;s far from robust, but I think it will be a sufficient base to carry into my next networking endeavor. The second is that I don&#8217;t typically need to do much threading, but it was necessary for this application. The reason is that we need to be constantly polling for incoming network data while also waiting for the user to type commands (like to send a test message). Console.WriteLine is blocking, so <strong>my main networking object is written so that when Listen() is called, it spins off a thread that continuously asks Lidgren.Network, &#8220;do we have messages to process?&#8221;</strong> If yes, parse and handle. While basic, I enjoyed the exercise because threads are not in my day to day toolbox (but maybe they should be!).</p>
<p><strong>You can download all the code here, which includes binaries, in case people have trouble building: <a href="http://lonecone.com/wp-content/uploads/2011/11/NetConsoles.zip">NetConsoles</a></strong></p>
<p>Note that the folder structure expects the lidgren-network-gen3 folder to be just one-level above the solution folder. I&#8217;d rather include the code library than just a DLL to make debugging and stepping through easier. While learning, it was very handle to be able to visually scan the internal workings of the library rather than be stuck with just IntelliSense (even though IntelliSense is very nice).</p>
<p>Some highlights of the code include:</p>
<p>Construction of the NetPeerConfiguration object (only the first two NetIncomingMessageType are required for basic functionality, but I wanted to see the other 2 in action).</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Config <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> NetPeerConfiguration<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;test_console&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
Config<span style="color: #008000;">.</span><span style="color: #0000FF;">EnableMessageType</span><span style="color: #008000;">&#40;</span>NetIncomingMessageType<span style="color: #008000;">.</span><span style="color: #0000FF;">DiscoveryRequest</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
Config<span style="color: #008000;">.</span><span style="color: #0000FF;">EnableMessageType</span><span style="color: #008000;">&#40;</span>NetIncomingMessageType<span style="color: #008000;">.</span><span style="color: #0000FF;">DiscoveryResponse</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
Config<span style="color: #008000;">.</span><span style="color: #0000FF;">EnableMessageType</span><span style="color: #008000;">&#40;</span>NetIncomingMessageType<span style="color: #008000;">.</span><span style="color: #0000FF;">ConnectionApproval</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
Config<span style="color: #008000;">.</span><span style="color: #0000FF;">EnableMessageType</span><span style="color: #008000;">&#40;</span>NetIncomingMessageType<span style="color: #008000;">.</span><span style="color: #0000FF;">UnconnectedData</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
Config<span style="color: #008000;">.</span><span style="color: #0000FF;">LocalAddress</span> <span style="color: #008000;">=</span> NetUtility<span style="color: #008000;">.</span><span style="color: #0000FF;">Resolve</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;localhost&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>The initialization of the NetPeer object (extremely simple) and starting up the listener thread:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Peer <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> NetPeer<span style="color: #008000;">&#40;</span>Config<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
Peer<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;listening on &quot;</span> <span style="color: #008000;">+</span> Config<span style="color: #008000;">.</span><span style="color: #0000FF;">Port</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
NetWorker <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MyNetWorker<span style="color: #008000;">&#40;</span>Peer, <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
NetThread <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Thread<span style="color: #008000;">&#40;</span>NetWorker<span style="color: #008000;">.</span><span style="color: #0000FF;">ProcessNet</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
NetThread<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Sending a basic string message (the <em>MessageType</em> enum is my own, not part of the framework):</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> SendMessage<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> message<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>Peer<span style="color: #008000;">.</span><span style="color: #0000FF;">Connections</span> <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">||</span> Peer<span style="color: #008000;">.</span><span style="color: #0000FF;">Connections</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;No connections to send to.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    NetOutgoingMessage msg <span style="color: #008000;">=</span> Peer<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateMessage</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    msg<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>MessageType<span style="color: #008000;">.</span><span style="color: #0000FF;">StringMessage</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    msg<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span>message<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    Peer<span style="color: #008000;">.</span><span style="color: #0000FF;">SendMessage</span><span style="color: #008000;">&#40;</span>msg, Peer<span style="color: #008000;">.</span><span style="color: #0000FF;">Connections</span>, NetDeliveryMethod<span style="color: #008000;">.</span><span style="color: #0000FF;">ReliableOrdered</span>, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Sending peer info to all connected peers (by passing Peer.Connections to Peer.SendMessage):</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> SendPeerInfo<span style="color: #008000;">&#40;</span>IPAddress ip, <span style="color: #6666cc; font-weight: bold;">int</span> port<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Broadcasting {0}:{1} to all (count: {2})&quot;</span>, ip<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>,
        port<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, Peer<span style="color: #008000;">.</span><span style="color: #0000FF;">ConnectionsCount</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    NetOutgoingMessage msg <span style="color: #008000;">=</span> Peer<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateMessage</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    msg<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>MessageType<span style="color: #008000;">.</span><span style="color: #0000FF;">PeerInformation</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> addressBytes <span style="color: #008000;">=</span> ip<span style="color: #008000;">.</span><span style="color: #0000FF;">GetAddressBytes</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    msg<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span>addressBytes<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    msg<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span>addressBytes<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    msg<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span>port<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    Peer<span style="color: #008000;">.</span><span style="color: #0000FF;">SendMessage</span><span style="color: #008000;">&#40;</span>msg, Peer<span style="color: #008000;">.</span><span style="color: #0000FF;">Connections</span>, NetDeliveryMethod<span style="color: #008000;">.</span><span style="color: #0000FF;">ReliableOrdered</span>, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>And finally&#8211;huge code dump&#8211;the listen thread class:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> MyNetWorker
<span style="color: #008000;">&#123;</span>
    NetPeer peer <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
    NetManager netManager <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> volatile <span style="color: #6666cc; font-weight: bold;">bool</span> shouldQuit <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> MyNetWorker<span style="color: #008000;">&#40;</span>NetPeer inPeer, NetManager inNetManager<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        peer <span style="color: #008000;">=</span> inPeer<span style="color: #008000;">;</span>
        netManager <span style="color: #008000;">=</span> inNetManager<span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> ProcessNet<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// read messages</span>
        <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>shouldQuit<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            Thread<span style="color: #008000;">.</span><span style="color: #0000FF;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>peer <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
                <span style="color: #0600FF; font-weight: bold;">continue</span><span style="color: #008000;">;</span>
            NetIncomingMessage msg<span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>msg <span style="color: #008000;">=</span> peer<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadMessage</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">switch</span> <span style="color: #008000;">&#40;</span>msg<span style="color: #008000;">.</span><span style="color: #0000FF;">MessageType</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">case</span> NetIncomingMessageType<span style="color: #008000;">.</span><span style="color: #0000FF;">DiscoveryRequest</span><span style="color: #008000;">:</span>
                        Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ReceivePeersData DiscoveryRequest&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        peer<span style="color: #008000;">.</span><span style="color: #0000FF;">SendDiscoveryResponse</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">null</span>, msg<span style="color: #008000;">.</span><span style="color: #0000FF;">SenderEndpoint</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">case</span> NetIncomingMessageType<span style="color: #008000;">.</span><span style="color: #0000FF;">DiscoveryResponse</span><span style="color: #008000;">:</span>
                        <span style="color: #008080; font-style: italic;">// just connect to first server discovered</span>
                        Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ReceivePeersData DiscoveryResponse CONNECT&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        peer<span style="color: #008000;">.</span><span style="color: #0000FF;">Connect</span><span style="color: #008000;">&#40;</span>msg<span style="color: #008000;">.</span><span style="color: #0000FF;">SenderEndpoint</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">case</span> NetIncomingMessageType<span style="color: #008000;">.</span><span style="color: #0000FF;">ConnectionApproval</span><span style="color: #008000;">:</span>
                        Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ReceivePeersData ConnectionApproval&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        msg<span style="color: #008000;">.</span><span style="color: #0000FF;">SenderConnection</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Approve</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #008080; font-style: italic;">//broadcast this to all connected clients</span>
                        <span style="color: #008080; font-style: italic;">//msg.SenderEndpoint.Address, msg.SenderEndpoint.Port</span>
                        netManager<span style="color: #008000;">.</span><span style="color: #0000FF;">SendPeerInfo</span><span style="color: #008000;">&#40;</span>msg<span style="color: #008000;">.</span><span style="color: #0000FF;">SenderEndpoint</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Address</span>, msg<span style="color: #008000;">.</span><span style="color: #0000FF;">SenderEndpoint</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Port</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">case</span> NetIncomingMessageType<span style="color: #008000;">.</span><span style="color: #0000FF;">Data</span><span style="color: #008000;">:</span>
                        <span style="color: #008080; font-style: italic;">//another client sent us data</span>
                        Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;BEGIN ReceivePeersData Data&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        MessageType mType <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>MessageType<span style="color: #008000;">&#41;</span>msg<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadInt32</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>mType <span style="color: #008000;">==</span> MessageType<span style="color: #008000;">.</span><span style="color: #0000FF;">StringMessage</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                            Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Message received: &quot;</span> <span style="color: #008000;">+</span> msg<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #008000;">&#125;</span>
                        <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>mType <span style="color: #008000;">==</span> MessageType<span style="color: #008000;">.</span><span style="color: #0000FF;">PeerInformation</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                            Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Data::PeerInfo BEGIN&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                            <span style="color: #6666cc; font-weight: bold;">int</span> byteLenth <span style="color: #008000;">=</span> msg<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadInt32</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                            <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> addressBytes <span style="color: #008000;">=</span> msg<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadBytes</span><span style="color: #008000;">&#40;</span>byteLenth<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                            IPAddress ip <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> IPAddress<span style="color: #008000;">&#40;</span>addressBytes<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                            <span style="color: #6666cc; font-weight: bold;">int</span> port <span style="color: #008000;">=</span> msg<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadInt32</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                            <span style="color: #008080; font-style: italic;">//connect</span>
                            IPEndPoint endPoint <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> IPEndPoint<span style="color: #008000;">&#40;</span>ip, port<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                            Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Data::PeerInfo::Detecting if we're connected&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>peer<span style="color: #008000;">.</span><span style="color: #0000FF;">GetConnection</span><span style="color: #008000;">&#40;</span>endPoint<span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008080; font-style: italic;">//are we already connected?</span>
                                <span style="color: #008080; font-style: italic;">//Don't try to connect to ourself!</span>
                                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>peer<span style="color: #008000;">.</span><span style="color: #0000FF;">Configuration</span><span style="color: #008000;">.</span><span style="color: #0000FF;">LocalAddress</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetHashCode</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">!=</span> endPoint<span style="color: #008000;">.</span><span style="color: #0000FF;">Address</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetHashCode</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
                                        <span style="color: #008000;">||</span> peer<span style="color: #008000;">.</span><span style="color: #0000FF;">Configuration</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Port</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetHashCode</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">!=</span> endPoint<span style="color: #008000;">.</span><span style="color: #0000FF;">Port</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetHashCode</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                                    Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Data::PeerInfo::Initiate new connection to: {0}:{1}&quot;</span>,
                                        endPoint<span style="color: #008000;">.</span><span style="color: #0000FF;">Address</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, endPoint<span style="color: #008000;">.</span><span style="color: #0000FF;">Port</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                                    peer<span style="color: #008000;">.</span><span style="color: #0000FF;">Connect</span><span style="color: #008000;">&#40;</span>endPoint<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                                <span style="color: #008000;">&#125;</span>
                            <span style="color: #008000;">&#125;</span>
                            Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Data::PeerInfo END&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #008000;">&#125;</span>
                        Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;END ReceivePeersData Data&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">case</span> NetIncomingMessageType<span style="color: #008000;">.</span><span style="color: #0000FF;">UnconnectedData</span><span style="color: #008000;">:</span>
                        <span style="color: #6666cc; font-weight: bold;">string</span> orphanData <span style="color: #008000;">=</span> msg<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;UnconnectedData: &quot;</span> <span style="color: #008000;">+</span> orphanData<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">default</span><span style="color: #008000;">:</span>
                        Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ReceivePeersData Unknown type: &quot;</span> <span style="color: #008000;">+</span> msg<span style="color: #008000;">.</span><span style="color: #0000FF;">MessageType</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #0600FF; font-weight: bold;">try</span> <span style="color: #008000;">&#123;</span>
                            Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>msg<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #008000;">&#125;</span>
                        <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#123;</span>
                            Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Couldn't parse unknown to string.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #008000;">&#125;</span>
                        <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
        Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Exiting net thread!&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Whew! It&#8217;s a lot, but p2p is pretty cool! Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://tylerforsythe.com/2011/11/peer-to-peer-networking-example-using-the-lidgren-network-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moving the Camera in IceCream</title>
		<link>http://tylerforsythe.com/2011/10/moving-the-camera-in-icecream/</link>
		<comments>http://tylerforsythe.com/2011/10/moving-the-camera-in-icecream/#comments</comments>
		<pubDate>Sun, 16 Oct 2011 21:44:27 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[developer]]></category>
		<category><![CDATA[icecream]]></category>
		<category><![CDATA[xna]]></category>

		<guid isPermaLink="false">http://lonecone.com/?p=52</guid>
		<description><![CDATA[I know this sounds silly, so it&#8217;s mostly just a note to myself. The proper way to move the camera in IceCream is: scene.ActiveCameras&#91;0&#93;.Position = new Vector2&#40;300, 300&#41;; I know this may seem obvious, but looking at the various properties, this was not the &#8230; <a href="http://tylerforsythe.com/2011/10/moving-the-camera-in-icecream/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I know this sounds silly, so it&#8217;s mostly just a note to myself. The proper way to move the camera in IceCream is:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">scene<span style="color: #008000;">.</span><span style="color: #0000FF;">ActiveCameras</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Vector2<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">300</span>, <span style="color: #FF0000;">300</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>I know this may seem obvious, but looking at the various properties, this was not the first thing I tried.</p>
<p>Also, if you&#8217;re relying on the camera BoundingRect for anything (like bounds-checking), IceCream by default does not recompute the BoundingRect when the camera is moved. I had to patch that one in, too. I&#8217;m really starting to get a feel for the IceCream code base, and I like what I see when I&#8217;m digging around.</p>
]]></content:encoded>
			<wfw:commentRss>http://tylerforsythe.com/2011/10/moving-the-camera-in-icecream/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IceCream Parallax Scrolling</title>
		<link>http://tylerforsythe.com/2011/10/icecream-parallax-scrolling/</link>
		<comments>http://tylerforsythe.com/2011/10/icecream-parallax-scrolling/#comments</comments>
		<pubDate>Sun, 16 Oct 2011 20:08:14 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[developer]]></category>
		<category><![CDATA[icecream]]></category>
		<category><![CDATA[xna]]></category>

		<guid isPermaLink="false">http://lonecone.com/?p=47</guid>
		<description><![CDATA[On my mission to create the perfect side-scroller action game, parallax scrolling is a key component. After diving into the IceCream code base, I thought I was going to have to create my own. I started on the feature (fortunately &#8230; <a href="http://tylerforsythe.com/2011/10/icecream-parallax-scrolling/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>On my mission to create the perfect side-scroller action game, parallax scrolling is a key component. After diving into the IceCream code base, I thought I was going to have to create my own. I started on the feature (fortunately it&#8217;s a relatively small thing) when I discovered that IceCream has a built-in sprite property called AutoScroll. Setting this to true and the AutoScrollSpeed &gt; 0 causes the sprite to &#8220;scroll&#8221; just like a background, making a copy of itself and everything necessary to cover the entire camera width.</p>
<p>Wow, how cool!</p>
<p>There are a few bugs with it, though. One, the AutoScroll properties are configurable in MilkShake but don&#8217;t save to the scene XML, or load. So I had to add that in (quick). It also doesn&#8217;t work if you want to move the image from right to left, only vertical or left to right. This is a bit of an oversight, as no one wants to play a game that scrolls from left to right. The <em>character/level</em> should move left to right, but the <em>background</em> should move right to left. Basically, I just need to add support for AutoScrollSpeed being negative.</p>
<p>The third nitpick isn&#8217;t a bug, but it doesn&#8217;t support a linked background. So if my background is chopped into multiple images to save time/memory when rendering back-to-back, they&#8217;ll have to be combined into a single material in IceCream. This isn&#8217;t the end of the world and could be patched in if it became an issue (via LinkPoints property or something). Not low-hanging fruit in terms of performance.</p>
<p>I don&#8217;t understand why this engine never caught on or wasn&#8217;t pushed more by the developers. It&#8217;s very powerful and extremely easy to use. It&#8217;s the perfect combination of GUI + code, not to mention all the core engine components are already written for you.</p>
<p><strong>Update</strong>: I realized later that the reason AutoScroll isn&#8217;t saved to XML by MilkShake is probably because it&#8217;s more common to set it up via code after the scene loads and the scene has truly started.</p>
<p>It also brings up two other points to investigate: is AutoScroll meant to scroll w/ the camera automatically? And, can the AutoScroll functionality work in a scenario that does not use a constant speed? E.g., in an action sort of game where the player can freely move left (&#8220;back&#8221; in the level), or right (&#8220;forward in the level&#8221;), at varying speeds.</p>
]]></content:encoded>
			<wfw:commentRss>http://tylerforsythe.com/2011/10/icecream-parallax-scrolling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reusable IceCream Utilities and Components</title>
		<link>http://tylerforsythe.com/2011/10/reusable-icecream-utilities-and-components/</link>
		<comments>http://tylerforsythe.com/2011/10/reusable-icecream-utilities-and-components/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 03:53:33 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[developer]]></category>
		<category><![CDATA[icecream]]></category>
		<category><![CDATA[xna]]></category>

		<guid isPermaLink="false">http://lonecone.com/?p=33</guid>
		<description><![CDATA[Since the IceCream library seems to be somewhat abandoned (though they graciously committed an XNA4-compatible version) I&#8217;ve created my own private repository for my own changes and fixes. If I continue to add-on, I&#8217;ll contact the original authors and see &#8230; <a href="http://tylerforsythe.com/2011/10/reusable-icecream-utilities-and-components/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Since the IceCream library seems to be somewhat abandoned (though they graciously committed an XNA4-compatible version) I&#8217;ve created my own private repository for my own changes and fixes. If I continue to add-on, I&#8217;ll contact the original authors and see if they want the changes to be official or what, but for now I&#8217;m keeping it private so the authors don&#8217;t feel like I&#8217;m trying to take credit for their great work. (It really is great stuff.)</p>
<p>Anyway, one of the first things I did was add a Utility directory and drop in IceTimer, which is a rip of timer code in <a href="http://www.amazon.com/Advanced-Game-Development-Jonathan-Harbour/dp/1598633422">Advanced 2D Game Development</a> (a great book!, though written for C++ programmers). I&#8217;ve used it in previous game demos with great success. Here&#8217;s the code for IceCream:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// To use, instantiate new IceTimer(). Then call Stopwatch() with ms intervals. It will auto-reset, so</span>
<span style="color: #008080; font-style: italic;">/// just call/monitor return value of Stopwatch().</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> IceTimer
<span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> IceTimer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		timer_start <span style="color: #008000;">=</span> TimeGetTime<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		Reset<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">long</span> TimeGetTime<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">return</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Ticks</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">10000</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">//convert ticks to milliseconds. 10,000 ticks in 1 millisecond.</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">long</span> GetTimer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">long</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>TimeGetTime<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">long</span> GetStartTimeMillis<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">long</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>TimeGetTime<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">-</span> timer_start<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Sleep<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> ms<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #6666cc; font-weight: bold;">long</span> start <span style="color: #008000;">=</span> GetTimer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span>start <span style="color: #008000;">+</span> ms <span style="color: #008000;">&gt;</span> GetTimer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Reset<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		stopwatch_start <span style="color: #008000;">=</span> GetTimer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> Stopwatch<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> ms<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>TimeGetTime<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&gt;</span> stopwatch_start <span style="color: #008000;">+</span> ms<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			Reset<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
		<span style="color: #0600FF; font-weight: bold;">else</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #6666cc; font-weight: bold;">long</span> timer_start<span style="color: #008000;">;</span>
	<span style="color: #6666cc; font-weight: bold;">long</span> stopwatch_start<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>All you have to do is instantiate it and then call something like:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>myTimer<span style="color: #008000;">.</span><span style="color: #0000FF;">Stopwatch</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">1000</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #008080; font-style: italic;">/* this code will fire once every second */</span> <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Next up, a couple highly reusable components. In fact, I was surprised their functionality wasn&#8217;t already built-in to the IceCream framework. Maybe it is and I missed it? Anyway, here&#8217;s a component to destroy a scene item after a user-provided number of seconds (useful for, say, bullets flying off-screen that you don&#8217;t want to zoom into infinity).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>IceComponentAttribute<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;LifeComponent&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> LifeComponent <span style="color: #008000;">:</span> IceComponent
<span style="color: #008000;">&#123;</span>
	<span style="color: #008000;">&#91;</span>IceComponentProperty<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Life in Seconds&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> LifeInSeconds <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> LifeComponent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> CopyValuesTo<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> target<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CopyValuesTo</span><span style="color: #008000;">&#40;</span>target<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>target <span style="color: #008000;">is</span> LifeComponent<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			LifeComponent targetCom <span style="color: #008000;">=</span> target <span style="color: #0600FF; font-weight: bold;">as</span> LifeComponent<span style="color: #008000;">;</span>
			targetCom<span style="color: #008000;">.</span><span style="color: #0000FF;">LifeInSeconds</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">LifeInSeconds</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnRegister<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		Enabled <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
		LifeTimer <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> IceTimer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> Update<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span> elapsedTime<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>LifeTimer<span style="color: #008000;">.</span><span style="color: #0000FF;">Stopwatch</span><span style="color: #008000;">&#40;</span>LifeInSeconds <span style="color: #008000;">*</span> <span style="color: #FF0000;">1000</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
			<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Owner</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MarkForDelete</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">private</span> IceTimer LifeTimer<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>And here&#8217;s another for moving a SceneItem given an X and Y velocity:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>IceComponentAttribute<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;VelocityComponent&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> VelocityComponent <span style="color: #008000;">:</span> IceComponent
<span style="color: #008000;">&#123;</span>
	<span style="color: #008000;">&#91;</span>IceComponentProperty<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Velocity Vector&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> Vector2 Velocity <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> VelocityComponent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnRegister<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		Enabled <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> CopyValuesTo<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> target<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CopyValuesTo</span><span style="color: #008000;">&#40;</span>target<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>target <span style="color: #008000;">is</span> VelocityComponent<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			VelocityComponent targetCom <span style="color: #008000;">=</span> target <span style="color: #0600FF; font-weight: bold;">as</span> VelocityComponent<span style="color: #008000;">;</span>
			targetCom<span style="color: #008000;">.</span><span style="color: #0000FF;">Velocity</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Velocity</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> Update<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span> elapsedTime<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Owner</span><span style="color: #008000;">.</span><span style="color: #0000FF;">PositionX</span> <span style="color: #008000;">+=</span> Velocity<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Owner</span><span style="color: #008000;">.</span><span style="color: #0000FF;">PositionY</span> <span style="color: #008000;">+=</span> Velocity<span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Let me know if you use these! So far I think most of my objects will be having these components.</p>
]]></content:encoded>
			<wfw:commentRss>http://tylerforsythe.com/2011/10/reusable-icecream-utilities-and-components/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IceCream XNA4 Tutorial</title>
		<link>http://tylerforsythe.com/2011/10/icecream-xna4-tutorial/</link>
		<comments>http://tylerforsythe.com/2011/10/icecream-xna4-tutorial/#comments</comments>
		<pubDate>Sun, 09 Oct 2011 19:24:29 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[developer]]></category>
		<category><![CDATA[icecream]]></category>
		<category><![CDATA[xna]]></category>

		<guid isPermaLink="false">http://lonecone.com/?p=25</guid>
		<description><![CDATA[The IceCream Pong tutorial is still working in the latest version, and because the official source is no longer available, I&#8217;ve uploaded a final working version of it here: IceCream Pong Sample Code  It should open and build in Visual Studio &#8230; <a href="http://tylerforsythe.com/2011/10/icecream-xna4-tutorial/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.assembla.com/spaces/IceCream/wiki/Pong_Tutorial">IceCream Pong tutorial</a> is still working in the latest version, and because the official source is no longer available, I&#8217;ve uploaded a final working version of it here: <a href="http://lonecone.com/wp-content/uploads/2011/10/PongIC.zip">IceCream Pong Sample Code</a>  It should open and build in Visual Studio 2010 as long as your directory structure alongside the IceCream project code is as follows:</p>
<p><a href="http://lonecone.com/wp-content/uploads/2011/10/PongIC-Directory-Structure.png"><img class="alignnone size-full wp-image-27" title="PongIC-Directory-Structure" src="http://lonecone.com/wp-content/uploads/2011/10/PongIC-Directory-Structure.png" alt="Pong IceCream Tutorial Directory Structure Layout" width="307" height="162" /></a></p>
<p>To clarify, that&#8217;s a root folder that contains both the base IceCream directory from their SVN, and a folder called PongIC that contains the solution file and all child directories of the linked archive.</p>
<p>The &#8220;game&#8221; is obviously very simplistic, but it does give a great overview of how to use the Milkshake GUI if you decide to build it yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://tylerforsythe.com/2011/10/icecream-xna4-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IceCream for XNA 4 Available via SVN!</title>
		<link>http://tylerforsythe.com/2011/10/icecream-for-xna-4-available-via-svn/</link>
		<comments>http://tylerforsythe.com/2011/10/icecream-for-xna-4-available-via-svn/#comments</comments>
		<pubDate>Sun, 09 Oct 2011 04:24:16 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[developer]]></category>
		<category><![CDATA[icecream]]></category>
		<category><![CDATA[xna]]></category>

		<guid isPermaLink="false">http://lonecone.com/?p=21</guid>
		<description><![CDATA[I&#8217;ve been in touch with Loïc, one of the author&#8217;s (the primary?) of IceCream, the 2d framework and toolset for XNA. He just committed to SVN the codebase compatible with XNA 4! You can grab it from their repository URL: http://svn.assembla.com/svn/IceCream (that URL &#8230; <a href="http://tylerforsythe.com/2011/10/icecream-for-xna-4-available-via-svn/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been in touch with Loïc, one of the author&#8217;s (the primary?) of <a href="http://icecream.epsicode.net/">IceCream, the 2d framework and toolset for XNA</a>. He just committed to SVN the codebase compatible with XNA 4! You can grab it from their repository URL: <a href="http://svn.assembla.com/svn/IceCream">http://svn.assembla.com/svn/IceCream</a> (that URL has both the XNA 3.1 and 4 code).</p>
<p>Not all of it is done, but I think it&#8217;s enough for me to get going. I tried updating the Visual Studio templates for VS2010 and XNA 4, but the format has changed for multi-project solutions and templates are just not something I&#8217;m very familiar with. I actually got it about 90% of the way there, but it&#8217;s not something I would feel comfortable releasing (I don&#8217;t release things at 90%). I had spent too much time already as I had <a title="PSA: If the ‘Export Template…’ File Menu Option Isn’t Available in Visual Studio 2010" href="http://lonecone.com/2011/10/export-template-visual-studio-2010/">issues with my Export Template menu item</a>, and I was more eager to get in and play with code. Maybe I&#8217;ll try to complete it sometime this week.</p>
<p>I&#8217;m also having difficulty building the XBox 360 and Windows Phone 7 versions of the library because of the reliance on XML, but they&#8217;re not critical platforms for me. PC is all I need for now. (X360 and WP7 run reduced versions of the .NET framework where the standard XML routines are not included).</p>
<p>Here&#8217;s hoping to more IceCream updates soon! Thanks, Loïc!</p>
]]></content:encoded>
			<wfw:commentRss>http://tylerforsythe.com/2011/10/icecream-for-xna-4-available-via-svn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PSA: If the &#8216;Export Template&#8230;&#8217; File Menu Option Isn&#8217;t Available in Visual Studio 2010</title>
		<link>http://tylerforsythe.com/2011/10/export-template-visual-studio-2010/</link>
		<comments>http://tylerforsythe.com/2011/10/export-template-visual-studio-2010/#comments</comments>
		<pubDate>Sun, 09 Oct 2011 04:12:29 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[developer]]></category>

		<guid isPermaLink="false">http://lonecone.com/?p=17</guid>
		<description><![CDATA[PSA: If the &#8216;Export Template&#8230;&#8217; File menu option isn&#8217;t available in Visual Studio 2010, it&#8217;s probably because you imported your settings from a previous version of Visual Studio (I did because I use custom text coloring). To get this option &#8230; <a href="http://tylerforsythe.com/2011/10/export-template-visual-studio-2010/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>PSA: If the &#8216;Export Template&#8230;&#8217; File menu option isn&#8217;t available in Visual Studio 2010, it&#8217;s probably because you imported your settings from a previous version of Visual Studio (I did because I use custom text coloring). To get this option back, you can either:</p>
<p><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">Reset your settings. This is a bummer because all of your coloring goes back to default too, though you could just re-import them after you&#8217;ve done your export work.</span></p>
<p><span class="Apple-style-span" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">Or, even better:</span></p>
<ol>
<li>Go to Tools, then &#8220;Customize&#8230;&#8221;, then click the &#8220;Commands&#8221; tab.</li>
<li>At the top of the dialog is a radio button called Menu bar with a dropdown next to it. Select &#8220;File&#8221; from that dropdown.</li>
<li>Click the &#8220;Add Command&#8221; button.</li>
<li>In the dialog that appears, from the Categories list, select File.</li>
<li>Scroll through the commands list to find &#8220;Export Template&#8230;&#8221; and select it.</li>
<li>Click Ok and use the Move Up and Move Down buttons to move it down near all the other save commands (I put mine last of the save&#8217;s).</li>
</ol>
<div>And you&#8217;re done! I suggest re-exporting your settings so you have a fresh copy for the future.</div>
]]></content:encoded>
			<wfw:commentRss>http://tylerforsythe.com/2011/10/export-template-visual-studio-2010/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>XNA 2d Framework</title>
		<link>http://tylerforsythe.com/2011/10/xna-2d-framework/</link>
		<comments>http://tylerforsythe.com/2011/10/xna-2d-framework/#comments</comments>
		<pubDate>Thu, 06 Oct 2011 02:55:47 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[developer]]></category>
		<category><![CDATA[gamer]]></category>
		<category><![CDATA[icecream]]></category>
		<category><![CDATA[xna]]></category>

		<guid isPermaLink="false">http://lonecone.com/?p=13</guid>
		<description><![CDATA[I&#8217;ll just come out and say it: I really enjoy 2d games. I love it when game companies license classic IP, like from the SNES era, and revamp it with HD graphics and modern gameplay, while keeping it 2d (or &#8230; <a href="http://tylerforsythe.com/2011/10/xna-2d-framework/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll just come out and say it: I really enjoy 2d games. I love it when game companies license classic IP, like from the SNES era, and revamp it with HD graphics and modern gameplay, while keeping it 2d (or 2.5d). When going from 2d to 3d, it often changes the gameplay so significantly that it&#8217;s no longer the same game, it&#8217;s just the same brand.</p>
<p>Consequently, I plan to focus on 2d games for the foreseeable future. All my current ideas are 2d, and the people who appreciate the sort of gameplay 2d offers are my peeps.</p>
<p>I already have a game started with all my own code, but as I build one reusable component after another, I can&#8217;t help but think these same objects have been written hundreds of times before me. For example: sprite sheets, animation, a &#8220;SceneItem&#8221; base class, etc. I found that there aren&#8217;t any maintained 2d frameworks for XNA right now. There are plenty of 2d engines that want to do everything for you, and some 3d engines. But nothing (that I could find) that gives a developer full source and says, &#8220;here&#8217;s a great base, now go forth, programmer!&#8221;</p>
<p>What to do? I&#8217;m not a game programming expert, but I&#8217;m an experienced enough developer to know that reinventing the code wheel is not a good way to spend time (<a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself">DRY principle</a>, except at a higher level). So I started looking around and found <a href="http://icecream.epsicode.net/what-is-icecream/">IceCream</a>. IceCream is a 2d XNA framework with its own GUI even, called MilkShake. I haven&#8217;t been able to actually run it yet though, because it&#8217;s targeting the XNA 3.1 framework (downloading now). Building the source targeting XNA 4 leads to many (many) errors, that I&#8217;m thinking about fixing. If I can get it working in a few evenings and get all that usable code, it&#8217;ll be worth it. I&#8217;ve just emailed the author to find out what license the code has been released in (I think MS-PL) before I spend time on it.</p>
]]></content:encoded>
			<wfw:commentRss>http://tylerforsythe.com/2011/10/xna-2d-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

