<?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>Sgt. Conker</title>
	<atom:link href="http://www.sgtconker.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sgtconker.com</link>
	<description>We are &#34;absolutely fine&#34;</description>
	<lastBuildDate>Wed, 01 Sep 2010 19:58:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Article: Node-Based Scripting</title>
		<link>http://www.sgtconker.com/2010/09/article-node-based-scripting/</link>
		<comments>http://www.sgtconker.com/2010/09/article-node-based-scripting/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 19:36:55 +0000</pubDate>
		<dc:creator>Absolutely Fine Tutorial Contest</dc:creator>
				<category><![CDATA["Absolutely fine"]]></category>
		<category><![CDATA[2010 Contest Entries]]></category>
		<category><![CDATA[Articles]]></category>
		<category><![CDATA[Contest]]></category>
		<category><![CDATA[Absolutely Fine Tutorial Contest]]></category>
		<category><![CDATA[Blecki]]></category>
		<category><![CDATA[JEmgine]]></category>
		<category><![CDATA[node-based scripting]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.sgtconker.com/?p=1641</guid>
		<description><![CDATA[by Blecki

Node-based scripting is not a traditional scripting language. And it's not a new idea, though it seems like people have forgotten about it. New systems appear - see Unreal Engine's Kismet - which people think are amazing new technologies. They aren't new; just amazing. I first encountered this scripting system in the quake engine. [...]]]></description>
			<content:encoded><![CDATA[<h4 style="text-align: center;">by <a href="http://jemgine.omnisu.com/">Blecki</a></h4>
<p style="text-align: center;"><img class="aligncenter" src="http://www.sgtconker.com/wp-content/uploads/contest/2010/blecki/MoveEntityNode.jpg" alt="Node Based Scripting" /></p>
<p>Node-based scripting is not a traditional scripting language. And it's not a new idea, though it seems like people have forgotten about it. New systems appear - see Unreal Engine's Kismet - which people think are amazing new technologies. They aren't new; just amazing. I first encountered this scripting system in the quake engine. It was very crude, and limited, but it had all the basic properties of the system I am about to describe.</p>
<p>A brief note : Throughout this article, I use my own engine, Jemgine, and it's level editor for my examples. Jemgine is available at <a href="http://jemgine.codeplex.com">http://jemgine.codeplex.com</a> You'll need to have XNA Gamestudio 3.1 installed to compile it, and to run the editor.</p>
<p>The target user of a node-based scripting system isn't the programmer, it's the level designer. The level designer might not know how to program. They might be constantly bothering a programmer to write scripts for them. Node-based scripting is an attempt to give the non-programmer level designer tools they understand and can use to create interesting behavior in a level without involving the programmer, and without having to learn a complex scripting language.</p>
<p><span id="more-1641"></span></p>
<p>Node-based scripting is a visual programming language. Most visual programming languages make the same mistake. They try and present the nuts and bolts of programming in a visual manner. Programs are still made of for loops and variables, only they're little boxes on the screen instead of text. They require the same skill set as programming in a text editor, except it takes longer to put the program together. Understandably, they aren't terribly usefull languages. The target audience doesn't know how to program - getting rid of the text editor doesn't change that. And those that do know how to program aren't going to give up the text editor for a less productive environment. Node-based scripting doesn't have to fall into this trap.</p>
<p>First, what is a node? A node is a little atom of behavior. It's an action that can be applied to the objects in the game world, or a chunk of logic. It's important to strike a balance somewhere between the low level and the high level. If your nodes represent loops and variables and conditions, you'll fall into that trap I described earlier. Make the nodes too high level, and you'll lose their flexibility. It can be beneficial to have some of those low level constructs, and some of the high level. Focus on the middle ground, but understand that you're going to end up with a fair mix of both.</p>
<p>Nodes have inputs and outputs. These are represented by terminals. Output terminals are connected to input terminals. Nodes also have references. These reference terminals are connected to other nodes or game objects. For example, the node 'MoveGameObject' has one input to trigger the action. It has two outputs - Began and Arrived, which are triggered when the movement begins and when it ends, respectively. It also has two references. One that's connected to the game object that needs moving, and another that's connected to the waypoint to move it to.</p>
<p><img class="alignnone" title="Move Entity Node" src="http://www.sgtconker.com/wp-content/uploads/contest/2010/blecki/MoveEntityNode.jpg" alt="" width="256" height="256" /></p>
<p>A node can be as simple in code as a list of terminals and a virtual function. Like this.</p>
<pre class="brush: csharp;">
public class Input
{
	public Node Owner;
}

public class Output
{
	public Input Target;
}

public class Reference
{
	public Node Target;
}

public class Node
{
	public List&lt;Input&gt; Inputs;
	public List&lt;Output&gt; Outputs;
	public List&lt;Reference&gt; References;

	public virtual void FireInput(Input Input, ScriptContext Context) {}
}
</pre>
<p>You'll need a way to create the script. You can do it in code, or you can do it in XML, but since the whole point of this system is to make it easy for your level designers to use, you should do it in your level editor. The level editor only needs to support two basic operations. Creating nodes, and connecting terminals.</p>
<p>You can see this in action within the Jemgine level editor. In the editor, press Alt+S to create a new script node. Then, with that node selected, hold alt and left click and drag an output terminal to connect it to an input terminal. This is probably the most important part of the system, so why aren't I spending more time on it? Because it's a terribly complex system and it's way beyond the scope of this article. But, I do suply a reference implementation in the form of the Jemgine level Editor.</p>
<p>The other half of the system is the engine that executes a script in the game. At first blush it seems that this would be very complicated, but it turns out it's the simplest piece of the puzzle. Because it's so simple, here is the entire implementation.</p>
<pre class="brush: csharp;">
public class ScriptDriver
{
	class FireEvent
	{
		internal Output Output;
		internal ScriptContext Context;
	}

	List&lt;FireEvent&gt; FireEvents = new List&lt;FireEvent&gt;();

	public void FireOutput(Output Output, ScriptContext Context)
	{
		FireEvents.Add(new FireEvent { Output = Output, Context = Context });
	}

	public void Update(int Cycles)
	{
		while (Cycles &gt; 0)
		{
			--Cycles;

			var LocalList = new List&lt;FireEvents&gt;(FireEvents);
			FireEvents.clear();
			foreach (var FireEvent in LocalList)
				if (FireEvent.Output.Target != null)
					FireEvent.Output.Target.Owner.FireInput(FireEvent.Output.Target, FireEvent.Context);
		}
	}
}
</pre>
<p>You might not need a script engine at all. When a script is fired, you could just call FireInput on it yourself. The benefit of a scripting engine is that it can delay the execution of a fired input until the next update cycle, which will prevent a bad script from creating an infinite script loop and freezing the game. This is why the Update function makes a copy of the fire list.</p>
<p>The only piece of the puzzle left is getting these scripts from the editor to the game. I use XNA's built in XML serializer. Actually, this is the only part of the article that actually depends on XNA. The XML Serializer is great, and it's already integrated into the content pipeline. But it has a few flaws. Notably, our script is a graph, and the XML Serializer can't handle a graph. We have to flatten it first, by which I mean replace all the references with simple indicies we can use to restore the references at load time. You could keep the script in a flat format all the time, but I found it was easier to flatten and restore than to work with the flat format all the time.</p>
<p>Flattening isn't complicated. First, assign all the objects an id. Then, copy the id of the referenced object into the terminal. The XML Serializer can be setup to serialize that id, and not the reference.</p>
<p>If game objects and entity components are themselves script nodes, this will allow you to attach scripts to all sorts of things. A health component, for example, could have an output terminal that it fires when the game object it is attached to dies. Now a script can be attached to an object's death very easily.</p>
<p>In a traditional scripting system, it can be pretty hard to tell what's going on in a level, especially if you aren't the level designer that built it. A node-based scripting system solves this problem. In a traditional system, what you see in the level editor is a filename. With this node-based system, the script is right there, in the level. This can be a disadvantage too.</p>
<p>It's a pain to build a complex script over and over for different levels, so the editor should be able to import a script into the level. The Jemgine level editor can import entire levels into another, so I can create a level that includes not just the script but the objects it operates on. This solves one of the disadvantages, but if there is an error in the original script, fixing that script won't fix every level that uses it. We've traded this 'fix in one place' for a bit of additional flexibility. Because the script is copied into the level, we can make customizations to the script specific to that level.</p>
<p>When you first start working with a scripting system like this, it's going to seem like there is no advantage at all. You'll still have level designers taking up valuable programmer time, but instead of scripts the programmers will be writing nodes. Eventually you'll build up a large library of script nodes and the level designers will find fewer and fewer things to bug the programmers about.</p>
<p>At first, the level designers just won't get it. You probably won't get it either. But after you write a few scripts, after you solve a few problems, it will click, and soon your level designers will be doing things you had never imagined.</p>
<p>This is a script for a door I created in the Jemgine level Editor.</p>
<p><img src="http://www.sgtconker.com/wp-content/uploads/contest/2010/blecki/DoorScript.jpg" alt="Door Script" /></p>
<p>In this script, there are two game objects. One is the door itself, the other implements the trigger zone for the door's button. The nodes labelled 'PolygonPhysics' are entity components attached to the game objects that interact with the engine's physics sub system. When the player touches the trigger zone, the PolygonPhysics component fires it's OnContact output. This is connected to a UseAction node, which will wait until the player presses a button before firing it's output. So if the player is touching the trigger zone, and presses the button, the UseAction node will fire that relay, which fires four other nodes. MoveEntity does exactly what you would expect. Disable disables the original switch, so the player can't press it again. Show and Hide work together with two other game objects (Switch On, and Switch Off) to change the switch graphic. Finally, MoveEntity plays some sounds.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sgtconker.com/2010/09/article-node-based-scripting/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Submissions Closed</title>
		<link>http://www.sgtconker.com/2010/09/submissions-closed/</link>
		<comments>http://www.sgtconker.com/2010/09/submissions-closed/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 06:23:25 +0000</pubDate>
		<dc:creator>Captain ZSquare</dc:creator>
				<category><![CDATA["Absolutely fine"]]></category>
		<category><![CDATA[Contest]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Absolutely Fine Tutorial Contest]]></category>
		<category><![CDATA[End of Submissions]]></category>

		<guid isPermaLink="false">http://www.sgtconker.com/?p=1638</guid>
		<description><![CDATA[Yeah, as pointed out in the comments, the deadline was sooner than I actually said in my last email.
The submission for the 'Absolutely Fine' XNA Tutorial Contest is now closed.
We'll soon be starting formatting the rest of the articles, posting them, and then posting a master list of all entries. After that, judging and voting [...]]]></description>
			<content:encoded><![CDATA[<p>Yeah, as pointed out in the comments, the deadline was sooner than I actually said in my last email.<br />
The submission for the <a href="http://www.sgtconker.com/2010/07/the-sgt-conker-xna-tutorial-contest-2">'Absolutely Fine' XNA Tutorial Contest</a> is <strong>now</strong> closed.</p>
<p>We'll soon be starting formatting the rest of the articles, posting them, and then posting a master list of all entries. After that, judging and voting will begin.</p>
<p>Meanwhile, enjoy our news feed <img src='http://www.sgtconker.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.sgtconker.com/2010/09/submissions-closed/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>1 Day remaining</title>
		<link>http://www.sgtconker.com/2010/08/1-day-remaining/</link>
		<comments>http://www.sgtconker.com/2010/08/1-day-remaining/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 19:26:00 +0000</pubDate>
		<dc:creator>Captain ZSquare</dc:creator>
				<category><![CDATA["Absolutely fine"]]></category>
		<category><![CDATA[Contest]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Absolutely Fine Tutorial Contest]]></category>
		<category><![CDATA[deadline]]></category>

		<guid isPermaLink="false">http://www.sgtconker.com/?p=1635</guid>
		<description><![CDATA[Quick reminder for our 'Absolutely Fine' XNA Tutorial Contest: The deadline is about 1 day away, so if you want to enter the contest, send us your entry!
At the moment, we have 4 published entries, and another around 14 entries that we're preparing for publishing.
Good luck!
]]></description>
			<content:encoded><![CDATA[<p>Quick reminder for our <a href="http://www.sgtconker.com/2010/07/the-sgt-conker-xna-tutorial-contest-2/">'Absolutely Fine' XNA Tutorial Contest</a>: The deadline is about 1 day away, so if you want to enter the contest, <a href="http://www.sgtconker.com/2010/07/the-sgt-conker-xna-tutorial-contest-2/">send us your entry</a>!</p>
<p>At the moment, we have 4 published entries, and another around 14 entries that we're preparing for publishing.</p>
<p>Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sgtconker.com/2010/08/1-day-remaining/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>XPF: A Layout Framework for XNA</title>
		<link>http://www.sgtconker.com/2010/08/xpf-a-layout-framework-for-xna/</link>
		<comments>http://www.sgtconker.com/2010/08/xpf-a-layout-framework-for-xna/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 14:29:40 +0000</pubDate>
		<dc:creator>Captain boki</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[XNA 4.0]]></category>
		<category><![CDATA[XPF]]></category>

		<guid isPermaLink="false">http://www.sgtconker.com/2010/08/xpf-a-layout-framework-for-xna/</guid>
		<description><![CDATA[Right after Mr. Styrchak shared his work on a Sinner clone now comes the word that the brave people at Red Badger just released a first build of BronzeglowXPF – I even named it XPF at first, too  
]]></description>
			<content:encoded><![CDATA[<p>Right after <a href="http://badcorporatelogo.spaces.live.com/">Mr. Styrchak</a> <a title="An Optimizing MSIL Rewriter (First Working Prototype)" href="http://badcorporatelogo.spaces.live.com/blog/cns!43EB71B104A2D711!505.entry">shared his work</a> on a <a title="Sinner &amp; Inquisitor: The Gathering" href="http://bxnaa.spaces.live.com/blog/cns!85007EAD17D3E592!387.entry">Sinner clone</a> now comes the word that the brave people at <a href="http://red-badger.com/">Red Badger</a> just <a href="http://red-badger.com/Blog/post/Introducing-XPF-e28093-A-Layout-Framework-for-XNA.aspx">released a first build of <strike>Bronzeglow</strike>XPF</a> – I even <a title="Björn&#39;s XNA Adventures: XPF (Working Title)" href="http://bxnaa.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&amp;_c=BlogPart&amp;partqs=cat%3DXPF%2520%2528Working%2520Title%2529">named it XPF at first</a>, too <img src='http://www.sgtconker.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.sgtconker.com/2010/08/xpf-a-layout-framework-for-xna/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Article: Programming your first XNA 4.0 game for PC, Xbox 360 &amp; Windows Phone 7: Pong</title>
		<link>http://www.sgtconker.com/2010/08/programming-your-first-xna-4-game-pong/</link>
		<comments>http://www.sgtconker.com/2010/08/programming-your-first-xna-4-game-pong/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 19:58:10 +0000</pubDate>
		<dc:creator>Absolutely Fine Tutorial Contest</dc:creator>
				<category><![CDATA[2010 Contest Entries]]></category>
		<category><![CDATA[2D]]></category>
		<category><![CDATA[Articles]]></category>
		<category><![CDATA[Contest]]></category>
		<category><![CDATA[WP7]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[Absolutely Fine Tutorial Contest]]></category>
		<category><![CDATA[Mister Helmut]]></category>
		<category><![CDATA[Pong]]></category>
		<category><![CDATA[Thomas Altenburger]]></category>

		<guid isPermaLink="false">http://www.sgtconker.com/?p=1626</guid>
		<description><![CDATA[by Thomas "Mister Helmut" Altenburger

I’d like to introduce the XNA framework to you with this very simple   and straightforward tutorial. We will see what XNA is and how its basic features works to continue with the programming of your first game, a simple Pong clone for Windows. At last, we’ll try to convert [...]]]></description>
			<content:encoded><![CDATA[<h4 style="text-align: center;">by Thomas "Mister Helmut" Altenburger</h4>
<p style="text-align: center;"><img class="aligncenter" src="http://www.sgtconker.com/wp-content/uploads/contest/2010/Altenburger/images/emulator.png" alt="Programming your first XNA 4.0 game" /></p>
<p style="text-align: justify;">I’d like to introduce the XNA framework to you with this very simple   and straightforward tutorial. We will see what XNA is and how its basic features works to continue with the programming of your first game, a simple <a hreflang="en" href="http://en.wikipedia.org/wiki/Pong">Pong</a> clone for Windows. At last, we’ll try to convert it to the Xbox 360 and  Windows Phone 7. This tutorial assumes that the readers have a basic C#/.Net  understanding. I hope that it will help you to understand the  basics of  the framework and that it will motivate you to go further in. The article should be suitable to complete beginners in game  programming.</p>
<p style="text-align: justify;"><strong>About this tutorial:</strong> I wrote this tutorial back in the days of XNA 2.0 beta and used it as an introductory course I taught to master degree students. Since then, it evolved to support XNA 4.0 beta with added Window Phone 7 development.</p>
<p style="text-align: justify;">English not being my native language, please forgive and/or report   any English oddities.</p>
<p style="text-align: justify;"><em>This tutorial targets XNA 4.0 beta. It will be   updated when the final version will be released. It uses some new   features of XNA 4.0 so it will not run out-of-the-box on previous XNA   version (mainly due to the usage of <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.viewport.bounds%28XNAGameStudio.40%29.aspx">Viewport.Bounds</a> and changed <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch.draw%28v=XNAGameStudio.40%29.aspx">SpriteBatch.Draw</a> arguments order).</em></p>
<p><span id="more-1626"></span></p>
<p style="text-align: justify;"><strong> </strong><strong>Required assets:</strong> <a hreflang="en" href="http://www.sgtconker.com/wp-content/uploads/contest/2010/Altenburger/PongCloneContent.zip">download  link</a>.</p>
<h1 style="text-align: justify;">The XNA framework</h1>
<p style="text-align: justify;">XNA is a free development framework by Microsoft, enabling  cross-platform game development thanks to simple and comprehensive  programming tools. The supported platforms are Windows PC’s, the Xbox  360, Zune media players and Windows Phone 7. The framework integrates  itself into Visual Studio 2010 (as of XNA 4.0), including the free  Express edition, and features the following components:</p>
<ul style="text-align: justify;">
<li>A powerful .NET API to handle graphics, sounds, videos, inputs,  networking and storage;</li>
<li>An audio development tool, XACT, to build complex cross-platform  sound banks;</li>
<li>A debugger capable of remote debugging Xbox 360 and Zune games;</li>
<li>A Windows Phone 7 emulator so that you don’t need to own such a  device to debug WP7 games.</li>
</ul>
<p style="text-align: justify;">XNA has been designed for hobbyist and independent developers and  builds upon a strong community. If you have any problems during your XNA  journey, don’t hesitate to ask for help at the official XNA community, <a hreflang="en" href="http://creators.xna.com/">the creators club</a>. If  correctly and gently exposed, your problem will most likely be resolved  with the help of XNA experts or the XNA team itself.</p>
<p style="text-align: justify;">Last but not least, the creators club allows you to release and sell  your creations on the Xbox 360 or Windows Phone 7 marketplaces.</p>
<h1 style="text-align: justify;">First steps to the XNA framework</h1>
<p style="text-align: justify;">In order to begin with the framework, let’s review the requirements before setting up our environment. You’ll need a computer with the following  specifications (see XNA 4 specs):</p>
<ul style="text-align: justify;">
<li>Windows Vista or Seven (or their “server” equivalent);</li>
<li>A <a hreflang="en" href="http://www.microsoft.com/windows/directx/">DirectX  9.1c</a> capable graphic card (or better) with up to date drivers and  DirectX runtime; A DirectX 10 capable graphic card if you’d like to  debug Windows Phone 7 XNA projects;</li>
<li><a hreflang="en" href="http://creators.xna.com/en-US/downloads">Windows Phone 7 Development Tools</a> (which includes XNA 4.0 and an Express edition of Visual Studio 2010).</li>
</ul>
<p style="text-align: justify;">If you’re a student, you may be able to get a copy of Windows  Vista/Seven and/or a professional release of Visual Studio through the  MSDN AA of your school (if it has subscribed to it). So go ask the IT  manager of your school for further detail. If you’re school don’t have  access to the MSDN AA, you can still pretend to student advantages  thanks to the <a hreflang="en" href="https://www.dreamspark.com/">Microsoft’s  Dreamspark program</a> (sign up and follow the instructions).</p>
<p style="text-align: justify;">If you’re not a student or simply don’t want to bother with a  professional edition of Visual Studio, the Express edition (included in the WP7 dev tools) is fairly  enough for XNA purpose. Another version wouldn’t bring you more features  unless you have other programming need than XNA.</p>
<p style="text-align: justify;">When you’re fully equipped and may now install the WP7 dev tools. You’re now ready to go.</p>
<p style="text-align: justify;"><strong>Note about XNA 4.0 beta:</strong> commercial copies of Visual Studio aren't supported by XNA 4.0 beta.</p>
<h1 style="text-align: justify;">Creating your first project</h1>
<p style="text-align: justify;">Start up Visual Studio and create a new project by clicking the  “File/New Project…” menu. Here you’ll have a list of the available  project templates. Give the name and directory you want to your project  and under the Visual C# item, pick “Windows Game (4.0)”.</p>
<p style="text-align: justify;">The project you’ve just created is now composed of the following  elements:</p>
<p><img class="aligncenter size-full wp-image-9" title="solution" src="http://www.sgtconker.com/wp-content/uploads/contest/2010/Altenburger/images/solution.png" alt="" width="302" height="262" /></p>
<ul>
<li style="text-align: justify;">The “Properties” directory, holding application manifest  (not-so-important stuff for our needs);</li>
<li style="text-align: justify;">The “References” meta-directory, listing all the .Net assemblies  your project needs;</li>
<li style="text-align: justify;">The “Content References”, listing the linked Content Pipeline (we’ll  see what it is soon);</li>
<li style="text-align: justify;">The “App.config” file, holding basic .Net setup, no need to edit it  (for a XNA game);</li>
<li style="text-align: justify;">The “Game.ico” file, is the icon of the executable file of your  game;</li>
<li style="text-align: justify;">The “Game1.cs” file, is the main source code file of a XNA project  (I’ll detail this later);</li>
<li style="text-align: justify;">The “GameThumbnail.png” file, is the icon of your game that will be  displayed on the Xbox 360 and Windows Phone 7 marketplaces;</li>
<li style="text-align: justify;">The “Program.cs” file, is the entry point of your program  (initializing your Game1 class).</li>
</ul>
<p style="text-align: justify;">Alongside your project, you’ll find another project having the same  name with a “Content” suffix. This represents the Content Pipeline of  your project, a very important XNA component.</p>
<h2 style="text-align: justify;">The Content Pipeline</h2>
<p style="text-align: justify;">The <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/bb203887%28v=XNAGameStudio.40%29.aspx">Content Pipeline</a> has an almost explicit name. Its  purpose is to manage your game assets (graphics, sounds, 3D models…)  from the importation up to the execution with barely any hassle. Its  main features are:</p>
<ul style="text-align: justify;">
<li>Importing the most common asset file formats and transparently load  them into comprehensible C# objects;</li>
<li>Ease of use (one line asset loading);</li>
<li>Automatically links dependent assets (3D models, textures,  shaders…);</li>
<li>Ensures that your assets are cross-platform, loaded and displayed  the same way;</li>
<li>Offers on-the-fly assets compression/decompression;</li>
<li>Bake up your assets and bundle it with you game.</li>
</ul>
<p style="text-align: justify;">The use of the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/bb203887%28v=XNAGameStudio.40%29.aspx">Content Pipeline</a> is mandatory for non-Windows  deployment. You can still load your assets the “hard way” from files on  PC if you’d like to.</p>
<p style="text-align: justify;">You can create as many Content projects as you want but it is more  convenient to stick with one per game project. Remember the “Content  References” in your game project? This is where you link your project to  your Content project. By default, your project is linked to the already  created Content project (you can check this by unfolding the “Content  References”).</p>
<p style="text-align: justify;">Now for the supported file formats, here’s the list:</p>
<ul style="text-align: justify;">
<li><strong>2D graphics</strong>: .bmp, .png, .jpg;</li>
<li><strong>3D models</strong>: .x, .fbx;</li>
<li><strong>Shaders</strong>: .fx;</li>
<li><strong>Audio</strong>: .mp3, .wav, .wma;</li>
<li><strong>Video</strong>: .wmv;</li>
<li><strong>Font</strong>: TrueType;</li>
<li>Any XML, text or binary files.</li>
</ul>
<p style="text-align: justify;">You may find many other format importers on the web or code one  yourself if you need to (<a hreflang="en" href="http://msdn.microsoft.com/en-us/library/bb447754.aspx">http://msdn.microsoft.com/en-us/library/bb447754.aspx</a>).</p>
<h3 style="text-align: justify;">Adding assets to your project</h3>
<p style="text-align: justify;">To add assets to your project, right click on your Content project,  and “Add/Add an existing item” and pick your assets. You can also  organize your assets into folders or add assets just by drag’n’droping  files to your Content project.</p>
<h3 style="text-align: justify;">The Game class</h3>
<p style="text-align: justify;">Now open up the Game1.cs file. You should notice that the Game1 class  is inherited from a class named <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game%28v=XNAGameStudio.40%29.aspx">Game</a>. The <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game%28v=XNAGameStudio.40%29.aspx">Game</a> class is provided by XNA and manages the game  loop (more generally the game workflow). It is composed of the following  methods:</p>
<ul style="text-align: justify;">
<li><a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.initialize%28v=XNAGameStudio.40%29.aspx">Initialize</a>: called after the construction of the  class, it ensures that all the class fields are constructed and ready to  be initialized. The purpose of this method is (as you may have guessed)  to initialize class members (in the same way of the Winforms’  Initialize method);</li>
<li><a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.loadcontent%28v=XNAGameStudio.40%29.aspx">LoadContent</a>: called after Initialize, this method is  meant to be used to load your game assets;</li>
<li><a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.unloadcontent%28v=XNAGameStudio.40%29.aspx">UnloadContent</a>: called during the disposal of  the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game%28v=XNAGameStudio.40%29.aspx">Game</a> class and ensure that your game assets are  disposed correctly when you exit it (it doesn’t mean that you don’t have  to take care of your memory allocation);</li>
<li><a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.update%28v=XNAGameStudio.40%29.aspx">Update</a>: called every time before the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.draw%28v=XNAGameStudio.40%29.aspx">Draw</a> method and should be used to update your game  engine. This will be the place of collision handling, inputs handling,  game world updating etc. Its <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.gametime%28v=XNAGameStudio.40%29.aspx">GameTime</a> argument propose services to know the amount  of time elapsed since the last Update call. This is very useful to  synchronize your game engine;</li>
<li><a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.draw%28v=XNAGameStudio.40%29.aspx">Draw</a>: called in an infinite loop, it is meant to draw  your game. Even if it is possible, for the sake of clean code, you  should avoid writing any logic update here.</li>
</ul>
<p style="text-align: justify;">The <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.update%28v=XNAGameStudio.40%29.aspx">Update</a> and <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.draw%28v=XNAGameStudio.40%29.aspx">Draw</a> methods represent the Game Loop and are called  in an infinite loop so that your game is constantly refreshed and  running. XNA default settings set the loop frequency to 60 loops per  second, meaning that your game should run at 60 frames per second (as  long as your <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.update%28v=XNAGameStudio.40%29.aspx">Update</a>/<a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.draw%28v=XNAGameStudio.40%29.aspx">Draw</a> don’t take too much time). You can adjust the  settings to void this limit so that your game runs as fast as your <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.update%28v=XNAGameStudio.40%29.aspx">Update</a>/<a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.draw%28v=XNAGameStudio.40%29.aspx">Draw</a> allow it to, but we’re not going to cover this  in this tutorial.</p>
<p style="text-align: justify;">The following figure depicts the general workflow of a game:</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-10" title="workflow" src="http://www.sgtconker.com/wp-content/uploads/contest/2010/Altenburger/images/workflow.png" alt="" width="507" height="208" />You’re free to not use the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game%28v=XNAGameStudio.40%29.aspx">Game</a> class but it provides useful services behind the  Game Loop and if you’re coding yourself such a class, you’ll most  likely end up with a pretty similar one. So why bothering re-writing the  wheel? Plus the fact the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game%28v=XNAGameStudio.40%29.aspx">Game</a> class ensures the workflow of your game.</p>
<p style="text-align: justify;">The <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game%28v=XNAGameStudio.40%29.aspx">Game1</a> class comes with two fields initialized:</p>
<ul style="text-align: justify;">
<li><a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphicsdevicemanager%28v=XNAGameStudio.40%29.aspx">GraphicsDeviceManager</a> graphics: manages what is  called the “graphical context”. More accurately, it allows you to setup  the graphics card states (i.e. screen resolution, vertical  synchronization, anti-aliasing, etc.) and to get information about the  hardware capabilities;</li>
<li><a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch%28v=XNAGameStudio.40%29.aspx">SpriteBatch</a> spriteBatch: provides services for 2D  drawings. This will be the most important object covered by this  tutorial.</li>
</ul>
<h3 style="text-align: justify;">Initializing and drawing 2D graphics</h3>
<p style="text-align: justify;">We will now take a look at how one can import 2D graphics and display  it. You will need some game assets in order to continue. I’ve prepared a  bundle with everything you need to follow this tutorial: <a hreflang="en" href="http://www.sgtconker.com/wp-content/uploads/contest/2010/Altenburger/PongCloneContent.zip">grab it there</a>.</p>
<p style="text-align: justify;">Now take a look at the file named texture1.bmp. It is a simple image  with 2D graphics. Notice that there are many single graphic entities  inside the picture. An individual graphical entity is called a sprite  and if an image contains many sprites, we’re in front of a sprite sheet.</p>
<p style="text-align: justify;">Other terms do exist to describe sprites and sprite sheets. Like  tiles and tile sets. If you have already toyed with some “RPG maker”,  you should be familiar with their meanings. Like a sprite sheet, a tile  set is an image containing several tiles, a tile being an independent  rectangle of your image. To the difference with sprites, tiles inside a  tile set are usually the same size, forming a regular grid. You may have  noticed that tiles can be disposed side by side to form complex  graphics, like a puzzle, using several times the same tile. This  technique is commonly used in 2D games (RPG, side-scroller…) and was  historically used because of the lack of memory of the 8/16bit systems.</p>
<p style="text-align: justify;">Let’s import the texture: right click on your Content project, create  a new folder named “Textures”, and add the existing texture1.bmp to  this folder. It should now appear in your project. Right click on the  texture1.bmp item and select “properties”, this will obviously show the  asset properties. You’ll see a bunch of stuff, the one that is important  for now is the “Asset Name” which should be set to “texture1”. This is  the internal name of your asset, not its filename. XNA set a default  name corresponding to the filename without its file extension, but you  can freely change it. Keep in mind it has nothing to do with the  filename.</p>
<p style="text-align: justify;">Now, inside your <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game%28v=XNAGameStudio.40%29.aspx">Game1</a> class, as a class member, add a new member to  host our texture. To this purpose, the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.texture2d%28v=XNAGameStudio.40%29.aspx">Texture2D</a> is intended manage your 2D texture (as you  could have found out by yourself).</p>
<pre class="brush: csharp;">
Texture2D myTexture;
</pre>
<p style="text-align: justify;">We now need to code the actual loading of the asset, so go inside the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.loadcontent%28v=XNAGameStudio.40%29.aspx">LoadContent</a> method and add the following line of code:</p>
<pre class="brush: csharp;">
myTexture = Content.Load&lt;Texture2D&gt;(@&quot;Textures/texture1&quot;);
</pre>
<p style="text-align: justify;">The <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.content.contentmanager%28v=XNAGameStudio.40%29.aspx">Content</a> object is a default <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game%28v=XNAGameStudio.40%29.aspx">Game</a> class member representing your Content project.  Everything linked to your Content project should be accessed through the  Content member. Its Load function is generic and will allow you to  easily load any supported type of asset by specifying the wanted type to  the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/bb197848%28v=XNAGameStudio.40%29.aspx">Load&lt;Type&gt;</a> template. To load an asset, just  specify the desired type and the asset name (not its file name). If you  try to load an unsupported type for the given asset, you’ll encounter an  exception at runtime. The “@” before the asset name is a C# operator  specifying that the special characters of the following string don’t  need to be escaped. It is way more convenient to use it when dealing  with asset locations since it will avoid you from doubling all the  dashes (making your code more readable). Notice that you access assets  as if they were files in the hierarchy of your Content project, but with  assets names as their filename (this may be a bit puzzling at first  glance).</p>
<p style="text-align: justify;">Take a look at the content of the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.draw%28v=XNAGameStudio.40%29.aspx">Draw</a> method:</p>
<pre class="brush: csharp;">
protected override void Draw(GameTime gameTime)
{
      GraphicsDevice.Clear(Color.CornflowerBlue);
      // TODO: Add your drawing code here
      base.Draw(gameTime);
}
</pre>
<p style="text-align: justify;">The first line cleans the entire buffer so that the whole screen is  reset to a blue color (the infamous <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.color.cornflowerblue%28v=XNAGameStudio.40%29.aspx">CornflowerBlue</a>). The last line calls the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game%28v=XNAGameStudio.40%29.aspx">Game</a> base <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.draw%28v=XNAGameStudio.40%29.aspx">Draw</a> method and should always be the last instruction  of your <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.draw%28v=XNAGameStudio.40%29.aspx">Draw</a> method. I will not cover this feature as we will  not use inheritance and game components.</p>
<h3 style="text-align: justify;">The SpriteBatch.Draw(…) method</h3>
<p style="text-align: justify;">To draw 2D graphics, the only thing you will need is the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch.draw%28v=XNAGameStudio.40%29.aspx">SpriteBatch.Draw(…)</a> method. But beforehand, take a  look at how the screen is addressed by XNA:</p>
<p style="text-align: center;"><img class="aligncenter" title="axes.png, Jun 2010" src="http://www.sgtconker.com/wp-content/uploads/contest/2010/Altenburger/images/axes.png" alt="axes.png" /></p>
<p style="text-align: justify;">As you can see, the screen origin is in the upper left corner and  goes positively to the opposite screen corner. This is a bit strange if  you’re used to <a hreflang="en" href="http://en.wikipedia.org/wiki/Cartesian_coordinate_system">the Cartesian system</a>. The unit is the pixel, meaning  that (with default XNA screen resolution of 800x480) the X axis goes up  to 800 and the Y one to 480. Textures are addressed the same way.</p>
<p style="text-align: justify;">Here’s one the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch.draw%28v=XNAGameStudio.40%29.aspx">SpriteBatch.Draw(…)</a> overload header:</p>
<p><a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch.draw%28v=XNAGameStudio.40%29.aspx">SpriteBatch.Draw</a>( <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.texture2d%28v=XNAGameStudio.40%29.aspx">Texture2D</a>, <span style="color: #339966;">// the texture to use for drawing</span><br />
<a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.rectangle%28v=XNAGameStudio.40%29.aspx">Rectangle</a>, <span style="color: #339966;">// the rectangle where you want to draw on  the screen (in screen coordinate) </span><a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.rectangle%28v=XNAGameStudio.40%29.aspx">Rectangle</a>,<span style="color: #339966;"> // the part of the texture you want to  draw (in texture coordinate)</span><br />
<a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.color%28v=XNAGameStudio.40%29.aspx">Color</a>); <span style="color: #339966;">// the color hue of the drawing, Color.White  will give a default hue</span></p>
<p style="text-align: justify;">Now, considering our texture1, here’s an example call and the  expected result:</p>
<pre class="brush: csharp;">
spriteBatch.Begin();
spriteBatch.Draw(
      myTexture,
      new Rectangle(10, 20, 50, 100),
      new Rectangle(0, 0, 50, 100),
      Color.White);
spriteBatch.End();
</pre>
<p style="text-align: justify;">The main difficulty in understanding 2D drawing is to understand the difference between source and destination rectangles. Have a look at the following illustration.</p>
<p style="text-align: center;"><img class="aligncenter" title="sprite.png, Jun 2010" src="http://www.sgtconker.com/wp-content/uploads/contest/2010/Altenburger/images/sprite.png" alt="sprite.png" /></p>
<p style="text-align: justify;">On the left, we have the texture containing the objects we’d like to  draw, but we only want to draw a portion of that texture. The source  rectangle defines this portion and must use the texture coordinates.  Then, you define where on the screen you want that portion to be drawn  by defining the destination rectangle (in screen coordinates). Note that  the destination rectangle doesn’t have to be as wide/high as the source  rectangle. Different sizes will result in stretched drawing.</p>
<h3 style="text-align: justify;">SpriteBatch.Begin(…) / End()</h3>
<p style="text-align: justify;">You may notice that the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch.draw%28v=XNAGameStudio.40%29.aspx">SpriteBatch.Draw</a> call is surrounded by two other  methods, namely <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch.begin%28v=XNAGameStudio.40%29.aspx">Begin</a> and <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch.end%28v=XNAGameStudio.40%29.aspx">End</a>. <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch.begin%28v=XNAGameStudio.40%29.aspx">Begin</a> could mean “ok mister GPU, here’s what you’re  going to draw and how you’re going to draw it”. It tells the GPU to draw  what’s coming and the properties to apply, like the usage of <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.blendstate.alphablend%28v=XNAGameStudio.40%29.aspx">AlphaBlend</a>, the order in which the sprites are going  to be drawn etc.</p>
<p style="text-align: justify;">The <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch.end%28v=XNAGameStudio.40%29.aspx">End</a> method tells to the GPU that the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch.draw%28v=XNAGameStudio.40%29.aspx">Draw</a> calls are complete and that he can now draw  everything with the properties it have been configured.</p>
<p style="text-align: justify;">You have to know that the CPU will tell the GPU what to draw only  when you call the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch.end%28v=XNAGameStudio.40%29.aspx">End</a> method. The result of this method is the transfer  of the drawing primitives to the GPU and transferring data between the  CPU and the GPU is very expensive. So try to put as many Draw calls as  possible between the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch.begin%28v=XNAGameStudio.40%29.aspx">Begin</a> and <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch.end%28v=XNAGameStudio.40%29.aspx">End</a> statements, this will greatly improve your game  performance by reducing transfers to the GPU. Using several <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch.begin%28v=XNAGameStudio.40%29.aspx">Begin</a>/<a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch.end%28v=XNAGameStudio.40%29.aspx">End</a> is mainly intended to use different drawing  parameters or to ensure that some elements are drawn before/after other  elements.</p>
<h1>Coding a Pong clone in 5 minutes</h1>
<p style="text-align: justify;">You should now master the basics of XNA. Despite the title of this  section, we’re not going to write a Pong clone in 5 minutes, but if you  were confident in XNA, you should be able to do it.</p>
<h2>Defining the basics</h2>
<p style="text-align: justify;">Ok, what do we need to make a Pong game?</p>
<ul style="text-align: justify;">
<li>Two playable bars (2 x <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.rectangle%28v=XNAGameStudio.40%29.aspx">Rectangle</a>);</li>
<li>A ball (1 x Circle);</li>
<li>A tennis field;</li>
<li>A score display;</li>
<li>Motivated supporters.</li>
</ul>
<p style="text-align: justify;">Inside the assets package you should have already downloaded (if not  so, <a hreflang="en" href="http://www.sgtconker.com/wp-content/uploads/contest/2010/Altenburger/PongCloneContent.zip">grab it here</a>), you should find the following files:</p>
<ul style="text-align: justify;">
<li><strong>Objects.png</strong>: an image file containing the graphics  for the two bars and the ball;</li>
<li><strong>Grass.png</strong>: an image file, a grass texture;</li>
<li><strong>Bounce.wav</strong>: a sound file for ball bounces;</li>
<li><strong>Supporters.wav</strong>: a sound file for goals.</li>
</ul>
<p style="text-align: justify;">Add all of them to your Content project.</p>
<p style="text-align: justify;">Let’s now define all those entities in our project, as <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game%28v=XNAGameStudio.40%29.aspx">Game1</a> class members.</p>
<pre class="brush: csharp;">
// our pong entities
Rectangle blueBar;
Rectangle redBar;
Rectangle ball; // since there’s no &quot;circle&quot; class in XNA, we’ll simulate it with a bounding rectangle box

// our pong clone textures
Texture2D grass;
Texture2D spriteSheet;

// our sound effects
SoundEffect ballBounce;
SoundEffect playerScored;
</pre>
<p style="text-align: justify;">We now need to initialize our three Rectangle structures and we’ll do it  in the (suspense…) <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.initialize%28v=XNAGameStudio.40%29.aspx">Initilize</a> method:</p>
<pre class="brush: csharp;">
protected override void Initialize()
{
      // initializing our entities
      blueBar = new Rectangle(
            32, // x coordinate of the upper left corner of our rectangle
            GraphicsDevice.Viewport.Bounds.Height / 2 - 64, // y coordinate of the upper left corner
            32, // its width
            128); // and its height
      redBar = new Rectangle(
            GraphicsDevice.Viewport.Bounds.Width - 64, // x coordinate of the upper left corner of our rectangle
            GraphicsDevice.Viewport.Bounds.Height / 2 - 64, // y coordinate of the upper left corner
            32, // its width
            128); // and its height
      ball = new Rectangle(
            GraphicsDevice.Viewport.Bounds.Width / 2 - 16, // x coordinate of the upper left corner of our rectangle
            GraphicsDevice.Viewport.Bounds.Height / 2 - 16, // y coordinate of the upper left corner
            32, // its width
            32); // and its height

      base.Initialize();
}
</pre>
<p style="text-align: justify;"><strong>Explanation:</strong></p>
<p style="text-align: justify;">We want our bars to be 32x128 pixels and be placed left and right to  the screen and perfectly centered. Defining a <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.rectangle%28v=XNAGameStudio.40%29.aspx">Rectangle</a> consist of four parameter: the x coordinate  of the upper left corner (in screen coordinate), the y coordinate of  the upper left corner, the width of the rectangle (32) and its height  (128).</p>
<p style="text-align: justify;">Noticed this kind of math?</p>
<pre class="brush: csharp;">
GraphicsDevice.Viewport.Bounds.Height / 2 - 64
</pre>
<p style="text-align: justify;">This is how we vertically center our bars. <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.viewport.bounds%28XNAGameStudio.40%29.aspx">GraphicsDevice.Viewport.Bounds</a> is a <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.rectangle%28v=XNAGameStudio.40%29.aspx">Rectangle</a> provided by XNA that will always represent  the actual bounds of the screen. If the resolution of your game is  800x480, the bounds will be <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.rectangle.rectangle%28v=XNAGameStudio.40%29.aspx">Rectangle(0, 0, 800, 480)</a>. So if we want to center  something, we just have to consider the half of the screen, minus the  half of the rectangle we’d like to be centered (or else only its upper  left corner will be centered).</p>
<p style="text-align: justify;">If you understood all this, you shouldn’t have difficulties  understanding our ball definition. We’d like our ball to have a 32  pixels diameter so we bound it with a 32x32 <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.rectangle%28v=XNAGameStudio.40%29.aspx">Rectangle</a> (since no circle class exists in XNA, up to  you write one). Yes, using a <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.rectangle%28v=XNAGameStudio.40%29.aspx">Rectangle</a> to simulate a circle isn't very accurate, but as long as our game is simple enough, we just don't care about it (the purpose of this tutorial isn't to be super accurate).</p>
<p style="text-align: justify;">Let’s now load the assets we’ve defined earlier, so go to the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.loadcontent%28v=XNAGameStudio.40%29.aspx">LoadContent</a> method. The following code should be  straightforward if you read the introduction of this article:</p>
<pre class="brush: csharp;">
protected override void LoadContent()
{
      // Create a new SpriteBatch, which can be used to draw textures.
      spriteBatch = new SpriteBatch(GraphicsDevice);

      // load our textures from the Content Pipeline
      grass = Content.Load&lt;Texture2D&gt;(@&quot;Textures/Grass&quot;);
      spriteSheet = Content.Load&lt;Texture2D&gt;(@&quot;Textures/Objects&quot;);

      // load our sound effects from the Content Pipeline
      ballBounce = Content.Load&lt;SoundEffect&gt;(@&quot;Sounds/Bounce&quot;);
      playerScored = Content.Load&lt;SoundEffect&gt;(@&quot;Sounds/Supporters&quot;);
}
</pre>
<h2 style="text-align: justify;">Drawing the scene</h2>
<p style="text-align: justify;">At last, we will draw the entire scene but beforehand, I’ll introduce  to you a simple problem.</p>
<p style="text-align: justify;"><a hreflang="en" href="http://en.wikipedia.org/wiki/Painter%27s_algorithm">The painter’s problem</a>: even if you never heard about  it, you should be familiar to it. When a painter would like to drawn a  landscape on the background and a house in front of it, it has to first  complete the background and then paint the house over it. If he did the  house first, he would encounter problems detailing the background at the  house’s edges. Graphics API works pretty much the same way but are more  restrictive: everything that is drawn will recover what’s already drawn  if it overlaps. So you have to draw graphics according to their distance  from the camera.</p>
<p style="text-align: justify;">Currently, what I said is not completely true since there’s some  hardware magic called the Z-buffer which sorts everything out even if  you draw everything in a random order. But the Z-buffer has been  designed for 3D purposes and when dealing with 2D graphics, we’re no  more working with Z coordinate so we have to sort this ourselves.</p>
<p style="text-align: justify;">XNA offers mechanisms to sort 2D graphics via the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritesortmode%28v=XNAGameStudio.40%29.aspx">SpriteSortMode</a> argument of the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch.draw%28v=XNAGameStudio.40%29.aspx">SpriteBatch.Draw</a> method but it is cleaner to draw  things in the right order and to tell XNA to draw directly (<a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritesortmode%28v=XNAGameStudio.40%29.aspx">SpriteSortMode.Immediate</a>) because: 1) your code will  be much more readable 2) it will be faster at execution.</p>
<p style="text-align: justify;">Let’s draw our background first:</p>
<pre class="brush: csharp;">
protected override void Draw(GameTime gameTime)
{
      GraphicsDevice.Clear(Color.CornflowerBlue); // clear all the screen with a blue color

      // draw the grass background
      spriteBatch.Begin();
      spriteBatch.Draw(
            grass, // use the grass texture
            GraphicsDevice.Viewport.Bounds, // stretch the texture to the whole screen
            // GraphicsDevice.Viewport.Bounds is Rectangle corresponding to the actual viewport (meaning the entire screen no matter the resolution), only available as of XNA 4.0
            Color.White);
      spriteBatch.End();
</pre>
<p style="text-align: justify;">What’s new here? We’re using the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.viewport.bounds%28XNAGameStudio.40%29.aspx">Viewport.Bounds</a> as our destination <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.rectangle%28v=XNAGameStudio.40%29.aspx">Rectangle</a>, why? Do you remember that this Rectangle  always represent the whole screen resolution? We’re just telling the  Draw method to stretch the entire grass texture to the entire screen.  And we’re done with our background. At this state, if you try to run the  game (by pressing F5 to debug it), it should display our nice grass  tennis field.</p>
<p>game (by pressing F5 to debug it), it should display our nice grass  tennis field.</p>
<p style="text-align: center;"><img class="aligncenter" title="grass.png, Jun 2010" src="http://www.sgtconker.com/wp-content/uploads/contest/2010/Altenburger/images/grass.png" alt="grass.png" /></p>
<p style="text-align: justify;">What comes after the background? The bars and the ball should be on  the same plane. We can draw all of them at the same time since there’s  no risk that they overlap but, wait… all the assets of those entities  are in the same single texture. Once again, do you remember the usage of  “source rectangle”? (Check the introduction if the answer is no).  Before drawing our elements we need to define a source rectangle for  each of them to access individual portion of the texture. Look at what’s  inside the texture and how it is placed:</p>
<p style="text-align: center;"><img class="aligncenter" title="spritesheet.png, Jun 2010" src="http://www.sgtconker.com/wp-content/uploads/contest/2010/Altenburger/images/spritesheet.png" alt="spritesheet.png" /></p>
<p style="text-align: justify;">The following three source rectangles should be easy to understand  (define them as <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game%28v=XNAGameStudio.40%29.aspx">Game1</a> class members):</p>
<pre class="brush: csharp;">
// source rectangles of our graphics
Rectangle blueSrcRect = new Rectangle( // blue bar src rectangle
      0, // upper left corner x-coordinate of the blue bar inside the spriteSheet
      0, // upper left corner y-coordinate
      32, // width
      128); // height
Rectangle redSrcRect = new Rectangle( // red bar src rectangle
      32, // upper left corner x-coordinate of the red bar inside the spriteSheet
      0,
      32,
      128);
Rectangle ballSrcRect = new Rectangle( // ball src rectangle
      64, // upper left corner x-coordinate of the ball inside the spriteSheet
      0,
      32,
      32);
</pre>
<p style="text-align: justify;">We now have everything up to draw the remaining elements. Here’s what  comes after our backgrounds drawing:</p>
<pre class="brush: csharp;">
// draw the entities (bars and ball)
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend); // setup alpha blend to support transparency
// draw the red bar
spriteBatch.Draw(
      spriteSheet, // use the sprites texture
      redBar, // the rectangle where to draw the bar on the screen
      redSrcRect, // the source rectangle of the bar inside the sprite sheet
      Color.White);
// draw the blue bar
spriteBatch.Draw(
      spriteSheet,
      blueBar,
      blueSrcRect,
      Color.White);
// draw the ball
spriteBatch.Draw(
      spriteSheet,
      ball,
      ballSrcRect,
      Color.White);
spriteBatch.End();
</pre>
<p style="text-align: justify;">Press F5, and see that our game almost look like it is finished.  There’s still all the gameplay to implement but our graphics are setup  and we’re now free to toy with the gameplay.</p>
<p style="text-align: center;"><img class="aligncenter" title="nogameplay.png, Jun 2010" src="http://www.sgtconker.com/wp-content/uploads/contest/2010/Altenburger/images/nogameplay.png" alt="nogameplay.png" /></p>
<h2 style="text-align: justify;">Coding the gameplay</h2>
<h3 style="text-align: justify;">Handling the inputs</h3>
<p style="text-align: justify;">Now that we’re done with the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.draw%28v=XNAGameStudio.40%29.aspx">Draw</a> method, we’ll take a look at the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.update%28v=XNAGameStudio.40%29.aspx">Update</a> method, so go at the corresponding line of  code, we’re going to examine its default content:</p>
<pre class="brush: csharp;">
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) // if the Back gamepad button is pressed
      this.Exit(); // exit our game
</pre>
<p style="text-align: justify;">The <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepad%28v=XNAGameStudio.40%29.aspx">GamePad</a> class allows getting the current state of an  Xbox 360 gamepad, being plugged to a PC or to your 360. Its <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepad.getstate%28v=XNAGameStudio.40%29.aspx">GetState(PlayerIndex)</a> method returns the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepadstate%28v=XNAGameStudio.40%29.aspx">GamePadState</a> of the player corresponding to the given  <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.playerindex%28v=XNAGameStudio.40%29.aspx">PlayerIndex</a>.</p>
<p style="text-align: justify;">A <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepadstate%28v=XNAGameStudio.40%29.aspx">GamePadState</a> object has a Buttons member, listing  every up-down buttons and their state (A, B, Y, X, RB, LB, Back, Start,  and Buttons on Sticks). If you want to know if a button is pressed, just  compare a button to a <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.buttonstate%28v=XNAGameStudio.40%29.aspx">ButtonState</a>. Buttons of the directional pad works the  same way and their states are stored in the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepadstate.dpad%28v=XNAGameStudio.40%29.aspx">DPad</a> member of a <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepadstate%28v=XNAGameStudio.40%29.aspx">GamePadState</a>. The other inputs of a gamepad are  different, they’re continuous (Sticks’ X &amp; Y axes and Triggers) so  you can’t compare them to a <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.buttonstate%28v=XNAGameStudio.40%29.aspx">ButtonState</a> since they are floating point values.  When in default position, those controls have 0.0f value. Triggers go up  to 1.0f when fully pressed and the axes range from -1.0f up to 1.0f  depending the direction of the axes. (X = 1.0f and Y = -1.0f would mean  that the stick is in the lower right corner).</p>
<p style="text-align: justify;">Getting the keyboard state works pretty much the same way. Let’s add a  keyboard control to the default code:</p>
<pre class="brush: csharp;">
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || // if the Back gamepad button is pressed
      Keyboard.GetState().IsKeyDown(Keys.Escape)) // or if the Escape key is down
      this.Exit(); // exit our game
</pre>
<p style="text-align: justify;"><a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.keyboard.getstate%28v=XNAGameStudio.40%29.aspx">Keyboard.GetState()</a> should be simple to understand  now. But what is this <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.keyboardstate.iskeydown%28v=XNAGameStudio.40%29.aspx">IsKeyDown</a> method? Unlike a <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepadstate%28v=XNAGameStudio.40%29.aspx">GamePadState</a>, <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.keyboardstate%28v=XNAGameStudio.40%29.aspx">KeyboardState</a> don’t hold directly fields with keys’  states, you have to ask for a state with the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.keyboardstate.iskeydown%28v=XNAGameStudio.40%29.aspx">IsKeyDown</a> / <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.keyboardstate.iskeyup%28v=XNAGameStudio.40%29.aspx">IsKeyUp</a> methods. Actually, <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepadstate%28v=XNAGameStudio.40%29.aspx">GamePadState</a> has a similar mechanism and propose the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepadstate.isbuttondown%28v=XNAGameStudio.40%29.aspx">IsButtonDown</a> / <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepadstate.isbuttonup%28v=XNAGameStudio.40%29.aspx">IsButtonUp</a> methods.</p>
<h3>Moving the bars</h3>
<p style="text-align: justify;">Our bars are represented by the redBar and blueBar rectangles, so if  we want them to move, when need to modify their Y position (in a Pong  game, bars only move along the Y axis). We will use the keyboard as our  main input method, up to you to andle two different gamepads (this will be covered later).</p>
<pre class="brush: csharp;">
// handling keyboard inputs
if (Keyboard.GetState().IsKeyDown(Keys.E)) // E key down ?
      blueBar.Y -= 10; // move the blue bar up
else if (Keyboard.GetState().IsKeyDown(Keys.D)) // D key down ?
      blueBar.Y += 10; // move the blue bar down
if (Keyboard.GetState().IsKeyDown(Keys.Up)) // Up key down ?
      redBar.Y -= 10; // move the red bar up
else if (Keyboard.GetState().IsKeyDown(Keys.Down)) // Down key down ?
      redBar.Y += 10; // move the red bar down
</pre>
<p style="text-align: justify;">Quite simply isn’t it? If you launch the game and try to move the bars  (with the E/D and Up/Down keys) you’ll notice that the bar can go behind  the screen. We don’t want that behavior since they should stop at  screen borders.</p>
<pre class="brush: csharp;">
// limit the bars movement to the screen bounds
if (redBar.Y &lt; 0) // upper bound
      redBar.Y = 0; // limit
if (blueBar.Y &lt; 0)
      blueBar.Y = 0;
if (redBar.Y + redBar.Height &gt; GraphicsDevice.Viewport.Bounds.Height)
      redBar.Y = GraphicsDevice.Viewport.Bounds.Height - redBar.Height;
if (blueBar.Y + blueBar.Height &gt; GraphicsDevice.Viewport.Bounds.Height)
      blueBar.Y = GraphicsDevice.Viewport.Bounds.Height - blueBar.Height;
</pre>
<p style="text-align: justify;">Now the bars don’t move outside the screen. The only trick resides in  the handling of the lower bound: don’t forget to consider the bar  height (the Y coordinates being the one of the upper left corner).</p>
<h3>Ball’s motion</h3>
<p style="text-align: justify;">In order to make the ball moving, we need something to represent its  velocity. Using a 2D vector seems to be the way to go. Fortunately, XNA  already have everything at your disposal. Here we define a 2D vector (<a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.vector2%28v=XNAGameStudio.40%29.aspx">Vector2</a>) for our ball velocity (as a <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game%28v=XNAGameStudio.40%29.aspx">Game1</a> class member):</p>
<pre class="brush: csharp;">
// ball speed
Vector2 ballVelocity = Vector2.Zero;
</pre>
<p style="text-align: justify;">And back in the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.update%28v=XNAGameStudio.40%29.aspx">Update</a> method, we can now make our ball move by  adding its velocity to its current position:</p>
<pre class="brush: csharp;">
// move the ball
ball.X += (int)ballVelocity.X;
ball.Y += (int)ballVelocity.Y;
</pre>
<p style="text-align: justify;">But, our ball isn’t really moving yet. Notice that we initialized the  velocity to zero speed. We need to set a positive speed somewhere so the  gameplay can begin. We will do this by adding a separate method we can  re-use to re-initialize the ball every time we need it (when players  score):</p>
<pre class="brush: csharp;">
private void InitBall()
{
      int speed = 5; // default velocity
      Random rand = new Random();

      // randomize the ball orientation
      switch (rand.Next(4))
      {
            case 0: ballVelocity.X = speed; ballVelocity.Y = speed; break;
            case 1: ballVelocity.X = -speed; ballVelocity.Y = speed; break;
            case 2: ballVelocity.X = speed; ballVelocity.Y = -speed; break;
            case 3: ballVelocity.X = -speed; ballVelocity.Y = -speed; break;
      }

      // initialize the ball to the center of the screen
      ball.X = GraphicsDevice.Viewport.Bounds.Width / 2 - ball.Width / 2;
      ball.Y = GraphicsDevice.Viewport.Bounds.Height / 2 - ball.Height / 2;
}
</pre>
<p style="text-align: justify;">We have a default velocity defined and a random number generator to  add some unpredictability to the ball direction. In a switch statement,  we make the ball go randomly in one of the four diagonal. Then, we set  the ball’s position to the center of the screen, and the gameplay shall  begin.</p>
<p style="text-align: justify;">We can now call our newly created method to initialize the game. Back  in the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.update%28v=XNAGameStudio.40%29.aspx">Update</a> method:</p>
<pre class="brush: csharp;">
// handling ball initialization
if (Keyboard.GetState().IsKeyDown(Keys.Space))
      InitBall();
</pre>
<p style="text-align: justify;">This code means that every time we press the space bar, the ball is  reset. Meaning that even during the gameplay, one can re-init the ball.  That’s not a correct behavior but we don’t care since we’re aiming a  playable game, not a polished one <img src='http://www.sgtconker.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> . Keep in mind that this is for  educational purpose.</p>
<h3>Worlds collide</h3>
<p style="text-align: justify;">If you tried to run the project, you’ll see that the ball is not  bouncing on screen bounds. In the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.update%28v=XNAGameStudio.40%29.aspx">Update</a> method, we add the required code:</p>
<pre class="brush: csharp;">
// collision handling
if (ball.Y &lt; 0 || // if the ball reach the upper bound of the screen
      ball.Y + ball.Height &gt; GraphicsDevice.Viewport.Bounds.Height) // or the lower one
{
      ballVelocity.Y = -ballVelocity.Y; // make if bounce by inverting the Y velocity
}
</pre>
<p style="text-align: justify;">This is similar to the way we managed the bars’ movement, with the  particularity that instead of blocking the movement, we invert the Y  velocity so the ball bounce.</p>
<p style="text-align: justify;">We also need to manage the collision with the bars. It is a little  bit different, since we’re going to check for Rectangle to <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.rectangle%28v=XNAGameStudio.40%29.aspx">Rectangle</a> collisions. To this purpose, XNA is making  our life a lot easier since the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.rectangle%28v=XNAGameStudio.40%29.aspx">Rectangle</a> class has a very useful method to test if  two <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.rectangle%28v=XNAGameStudio.40%29.aspx">Rectangle</a> are colliding:</p>
<pre class="brush: csharp;">
if (ball.Intersects(redBar) || // if the ball collide with blue bar
      ball.Intersects(blueBar)) // or the red one
{
      ballVelocity.X = -ballVelocity.X; // make if bounce by inverting the X velocity
}
</pre>
<p style="text-align: justify;">Very simple: we just check if the ball (which is a Rectangle) is  colliding with either one of the bars, and invert the X velocity to make  it bounce.</p>
<p style="text-align: justify;">Here we are! We have a fully playable gameplay. The game only need  some polish and it is almost ready for huge commercial success (if we  were in the 70’s by the way…).</p>
<h3>Scoring</h3>
<p style="text-align: justify;">To add some competition, we will handle a simple score counter and  display. We’ll use two more <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game%28v=XNAGameStudio.40%29.aspx">Game1</a> class members to manage the scores:</p>
<pre class="brush: csharp;">
// scores
int blueScore = 0;
int redScore = 0;
</pre>
<p style="text-align: justify;">We need to detect if the ball goes behind a bar in order to increment  the corresponding score. We’ll do it in the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.update%28v=XNAGameStudio.40%29.aspx">Update</a> method:</p>
<pre class="brush: csharp;">
// score handling
if (ball.X &lt; 0) // red scores
{
      redScore++;
      InitBall(); // re-init the ball
}
else if (ball.X + ball.Width &gt; GraphicsDevice.Viewport.Bounds.Width) // blue scores
{
      blueScore++;
      InitBall(); // re-init the ball
}
</pre>
<p style="text-align: justify;">Same math as before to check screen bounds. When the ball goes behind  the left or right bound, a player just scored and we re-initialize the  ball.</p>
<p style="text-align: justify;">Displaying the score involves to draw some text. Drawing text with  graphics API is a bit problematic, text fonts are not ready-to-be-drawn  graphics and their structure is not suitable with how graphics cards  operate. Prior to use a font, it has to be processed or converted to a  suitable asset. Some tools allow you to do so by generating a sprite  sheet containing one sprite per character in the font. I let you imagine  how boring it is to write a helper class able to seamlessly use this  sprite sheet. Graphics API like SDL or OpenGL don’t do this  out-of-the-box but some useful libraries exist.</p>
<p style="text-align: justify;">XNA has the feature to handle fonts easily. Let’s have a look at it.  We need to add a special type of asset to our Content project: right on  the Content project, add a new file, select the Sprite Font item and  name it “ScoreFont.spritefont”. An XML file should be showing up after  you added it. This file will hold the properties of the font we want to  use: the font name, its size, its type (bold, italic…) and other  not-so-important stuff. We want the score to be displayed with big  readable font, so change the size to 18 and the type to “Bold” (case  sensitive!):</p>
<pre class="brush: xml;">
&lt;Size&gt;18&lt;/Size&gt;
...
&lt;Style&gt;Bold&lt;/Style&gt;
</pre>
<p style="text-align: justify;">Like any asset, we have to define the corresponding variable and to load  it. As a <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game%28v=XNAGameStudio.40%29.aspx">Game1</a> member:</p>
<pre class="brush: csharp;">
SpriteFont font;
</pre>
<p style="text-align: justify;">And then in the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.loadcontent%28v=XNAGameStudio.40%29.aspx">LoadContent</a> method:</p>
<pre class="brush: csharp;">
// load our score font
font = Content.Load&lt;SpriteFont&gt;(@&quot;ScoreFont&quot;);
</pre>
<p style="text-align: justify;">All we have to do now is to draw the text, the same way if it was 2D  graphics with the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch%28v=XNAGameStudio.40%29.aspx">SpriteBatch</a> (in the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.draw%28v=XNAGameStudio.40%29.aspx">Draw</a> method, after the grass drawing so it isn’t  underneath):</p>
<pre class="brush: csharp;">
// draw the score
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
spriteBatch.DrawString( // draw our score string
      font, // our score font
      blueScore.ToString() + &quot; - &quot; + redScore.ToString(), // building the string
      new Vector2( // text position
      GraphicsDevice.Viewport.Bounds.Width / 2 - 25, // half the screen and a little to the left
      10.0f),
      Color.Yellow); // yellow text
spriteBatch.End();
</pre>
<p style="text-align: justify;">Note that drawing text needs a dedicated method, <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch.drawstring%28v=XNAGameStudio.40%29.aspx">DrawString</a>. It takes as argument the font, the string  to display, a 2D vector for the screen coordinate where we want the  text to be displayed (remind that it consider the upper left corner of  the text box), and finally, the color of the text.</p>
<h3>Sound blasting</h3>
<p style="text-align: justify;">Last but not least, the sound. We already have our two <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.audio.soundeffect%28v=XNAGameStudio.40%29.aspxhttp:/msdn.microsoft.com/en-us/library/microsoft.xna.framework.audio.soundeffect%28v=XNAGameStudio.40%29.aspx">SoundEffect</a> ready (ballBounce &amp; playerScored).  Since XNA 3.0, playing a sound is simple as pie: <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.audio.soundeffect.play%28v=XNAGameStudio.40%29.aspx">SoundEffect.Play()</a>. All we have to do, is to call the  play method when the ball bounce and when a player scores. Here’s the  code update:</p>
<pre class="brush: csharp;">
// collision handling
if (ball.Y &lt; 0 || // if the ball reach the upper bound of the screen
      ball.Y + ball.Height &gt; GraphicsDevice.Viewport.Bounds.Height) // or the lower one
{
      ballVelocity.Y = -ballVelocity.Y; // make if bounce by inverting the Y velocity
      ballBounce.Play(); // bounce sound
}

if (ball.Intersects(redBar) || // if the ball collide with blue bar
      ball.Intersects(blueBar)) // or the red one
{
      ballVelocity.X = -ballVelocity.X; // make if bounce by inverting the X velocity
      ballBounce.Play(); // bounce sound
}

// score handling
if (ball.X &lt; 0) // red scores
{
      redScore++;
      playerScored.Play(); // hurray !
      InitBall(); // re-init the ball
}
else if (ball.X + ball.Width &gt; GraphicsDevice.Viewport.Bounds.Width) // blue scores
{
      blueScore++;
      playerScored.Play(); // hurray !
      InitBall(); // re-init the ball
}
</pre>
<h2>Intermediary conclusion</h2>
<p style="text-align: center;"><img class="aligncenter" title="full.png, Jun 2010" src="http://www.sgtconker.com/wp-content/uploads/contest/2010/Altenburger/images/full.png" alt="full.png" /></p>
<p style="text-align: justify;">Our Windows game is now complete! At least what I wanted to expose.  Our prototype is far from being perfect, but one of the goals of this  article is to give you opportunity to express yourself in the polishing  of the game. You may copy/pasted everything but now, it’s up to you to  enhance it. Here’s a list of thing you may consider doing:</p>
<ul>
<li style="text-align: justify;">Enhance collision handling: our model is very rough and far from a  true physical model, plus the fact that the bar-to-ball collision is  poorly managed (if the ball collide with another border than the front  one, you can expect strange behaviors);</li>
<li style="text-align: justify;">Enhance the beginning of the game: in a classic Pong, the ball  should go randomly in any direction while our game only throw the ball  with 45° angles (more randomness is needed!); when a player score, the  ball should be thrown at the him next (and not randomly);</li>
<li>Add a menu;</li>
<li>Handle the end of the game: our prototype doesn’t stop the score;</li>
<li style="text-align: justify;">Add an artificial intelligence: pretty easy, just apply a movement  to the enemy’s bar if the ball is up or down the middle of the bar;</li>
<li>…</li>
</ul>
<h2>Porting our Pong clone to the Xbox 360 and testing it</h2>
<p style="text-align: justify;">To run a game on the Xbox 360, we need to setup a new project, a 360  one. When it comes to port an existing project, XNA allow you to copy  your current project and to create a port with one click. Right click on  your Windows project, and select “Create a Copy of Project for Xbox  360”. Tadam, you’ve successfully ported your game. Note that this “copy”  isn’t really a copy: all the source files are the one from the original  project, they’re just shared between all the ports. This means that if  you modify the Windows project, the changes will be applied to the Xbox  360 version as well. You’ll see that you know have two Game1.cs files  (one in the Windows project, and one in the 360 one) but actually,  there’s only one file, shared. The fact that it appears in all the  projects is a little bit misleading.</p>
<h3>Running the game on your 360</h3>
<p style="text-align: justify;"><em>Please note that the XNA 4.0 beta doesn’t allow deploying games on an Xbox 360 yet. The following process is valid as of  XNA 3.1 and should remain the same with the final XNA 4.0 version. I’ll  update the article once it is released. <strong>Meanwhile, it is advised to skip this part</strong> since if you create an Xbox 360 project inside XNA 4.0 beta, it will prevent you from debugging any other project since you can't set a target device for the Xbox 360 port.<br />
</em></p>
<p style="text-align: justify;">Prior to be able to run code on your Xbox 360, you need your Xbox to  be on the same LAN as your computer (I suppose you know how to setup a  network) and a Creators Club license. This license is mandatory to  publish games on the Xbox and Windows Phone marketplaces and to debug  code on the gaming console. This is because Microsoft host and promote  your games on the marketplaces and it is a good way to regulate the  community by letting in only serious people (plus the fact that  Microsoft want to stay in control of what’s being executed on the 360,  for obvious security reasons). The license has a yearly cost of $99 and  can be acquired from the Xbox Live marketplace or from xbox.com.</p>
<p style="text-align: justify;">There’s a possibility to get a free trial license enabling you to  debug code on your console, but not to sell games (as well as not having  access to premium content and forums on the creators club). You may  find a trial license via a MSDN AA account, if you’re a student/teacher  and if your school has subscribed to the program. If you don’t know if  your school can get you a MSDN AA account, go ask the person in charge  of your school’s computers. Another way to a trial license is to (still)  be student and subscribe to the <a href="https://www.dreamspark.com/default.aspx">Microsoft’s Dreamspark program</a>.</p>
<p style="text-align: justify;">Once you have successfully registered your license, you can start  downloading the XNA launcher to your 360. You’ll find it on the games  marketplace along with the Indie Games. It should be named “XNA Game  Studio Connect”. This program will only run if you’re connected to the  Xbox Live and if the connected GamerTag has a valid creators club  license. Run it and go back to Visual Studio.</p>
<p style="text-align: justify;">You now have to link your PC to your Xbox 360. This is to ensure that  only trusted computer can deploy trusted code to a trusted console. In  Visual Studio, click on the “Add a New Device”.</p>
<p style="text-align: center;"><img class="aligncenter" title="add_device.png, Jun 2010" src="http://www.sgtconker.com/wp-content/uploads/contest/2010/Altenburger/images/add_device.png" alt="add_device.png" /></p>
<p style="text-align: justify;">Choose to add an Xbox 360 console. Visual Studio should now ask you  to enter a keycode, this code should be displayed on your 360 if you’ve  successfully started the XNA launcher. Enter the code and validate. If  everything went ok, you’re now ready to go and you won’t need to do this  step anymore. If not, check out your network setup.</p>
<p style="text-align: justify;">When you’re ready, select the Xbox 360 as the target of your  application.</p>
<p style="text-align: center;"><img class="aligncenter" title="change_target.png, Jun 2010" src="http://www.sgtconker.com/wp-content/uploads/contest/2010/Altenburger/images/change_target.png" alt="change_target.png" /></p>
<p style="text-align: justify;">Before launching our Pong game we need to adjust the screen resolution to fit the native Xbox 360 resolution of 1280x720. To do so, we will add a conditional pre-processing code so that the screen resolution code is only considered when the project is compiled to target the Xbox 360 (in the Game1 constructor):</p>
<pre class="brush: csharp;">
#ifdef XBOX360
graphics.PreferredBackBufferWidth = 1280;
graphics.PreferredBackBufferHeight = 720;
graphics.ApplyChanges();
#endif
</pre>
<p style="text-align: justify;">And run the Xbox 360 project. You now have your game running on your  TV! You can also debug the game like if it was running on the computer  by putting some break points etc. Remote debugging works pretty darn  well.</p>
<p style="text-align: justify;">We now have a problem: we didn’t handle the gamepad so the game isn’t  playable. The only thing you can do, is to press the “back” button to  exit the game. The update is simple to achieve:</p>
<pre class="brush: csharp;">
// handling keyboard and gamepad inputs
if (Keyboard.GetState().IsKeyDown(Keys.E) // E key down ?
      || GamePad.GetState(PlayerIndex.One).DPad.Up == ButtonState.Pressed)
      blueBar.Y -= 10; // move the blue bar up
else if (Keyboard.GetState().IsKeyDown(Keys.D) // D key down ?
      || GamePad.GetState(PlayerIndex.One).DPad.Down == ButtonState.Pressed)
      blueBar.Y += 10; // move the blue bar down
if (Keyboard.GetState().IsKeyDown(Keys.Up) // Up key down ?
      || GamePad.GetState(PlayerIndex.Two).DPad.Up == ButtonState.Pressed)
      redBar.Y -= 10; // move the red bar up
else if (Keyboard.GetState().IsKeyDown(Keys.Down) // Down key down ?
      || GamePad.GetState(PlayerIndex.Two).DPad.Down == ButtonState.Pressed)
      redBar.Y += 10; // move the red bar down
</pre>
<pre class="brush: csharp;">
// handling ball initialization
if (Keyboard.GetState().IsKeyDown(Keys.Space)
      || GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed)
      InitBall();
</pre>
<p>Here it is, we can now play with two gamepad and our Xbox 360 port is  complete!</p>
<h2 style="text-align: justify;">Serious business: porting our game to Windows Phone 7</h2>
<p style="text-align: justify;">As we did for the Xbox 360 port, create copy for Windows Phone of  your project. If you try to run the game in the emulator, you’ll most  likely end up with a cornflower blue screen. This means our game has  incompatible graphics properties. To fix this, we need to switch to  Windows Phone 7 specific parameters, namely a screen resolution of 800x480, a refresh rate of 30 frames per second, forcing the landscape mode (playing our Pong in lortrait wouldn't be natural for a Pong game) and updating the referenced assemblies. But we don’t want to  apply these changes to our other ports. Fortunately, there’s a way to  write code that we only be considered by a specific port thanks to  preprocessor statements (like we did for the Xbox 360 port). The changes will be applied in the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game%28v=XNAGameStudio.40%29.aspx">Game1</a> constructor:</p>
<pre class="brush: csharp;">
public Game1()
{
      graphics = new GraphicsDeviceManager(this);
      Content.RootDirectory = &quot;Content&quot;;

#if XBOX360
      graphics.PreferredBackBufferWidth = 1280;
      graphics.PreferredBackBufferHeight = 720;
#endif

#if WINDOWS_PHONE
      // Frame rate is 30 fps by default for Windows Phone.
      TargetElapsedTime = TimeSpan.FromTicks(333333);

      // Pre-autoscale settings.
      graphics.PreferredBackBufferWidth = 800;
      graphics.PreferredBackBufferHeight = 480;
      graphics.IsFullScreen = true; // so the battery meter and other stuff are not displayed
      graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft; // forcing our game to support only one landscape mode so the screen doesn't rotate if the two players are shaking the device
#endif

      graphics.ApplyChanges();
}
</pre>
<p style="text-align: justify;">Note that we also set the game to run in full screen mode. On Windows  Phone 7, it means that the battery status will not show up over the  game. If it wasn’t in full screen, the battery status would hide our  score display.</p>
<p style="text-align: justify;">We also need to update the references. Unfold the references of the Windows Phone 7 project and delete all references with a warning icon (Avatar, Net, Storage, Video, XACT) and add a new reference to the project: Microsoft.Xna.Framework.Input.Touch. Last thing to do, adding a conditional statement to include this new reference only to our WP7 port (after the other using statements):</p>
<pre class="brush: csharp;">
#if WINDOWS_PHONE
using Microsoft.Xna.Framework.Input.Touch;
#endif
</pre>
<p style="text-align: justify;">Try to run the game and look at our super pong.</p>
<p style="text-align: center;"><img class="aligncenter" title="emulator.png, Jun 2010" src="http://www.sgtconker.com/wp-content/uploads/contest/2010/Altenburger/images/emulator.png" alt="change_target.png" /></p>
<p style="text-align: justify;">You may notice that the inputs don’t work. Some Windows Phone 7  devices come with a physical keyboard, but since some are not, XNA  designer choose to not support keyboards as an input method so that  games are experienced the same way on all Windows Phone 7 devices. The  only method we have at our disposal if the multi-touch screen.</p>
<p style="text-align: justify;">First, we need to design some sort of interaction scheme: to move the  blue bar, we’ll consider the upper left and lower left corners of the  screen as our up and down buttons; the opposite corners will be used to  move the red bar; to initialize the game, we’ll consider a tap on the  middle of the screen. The following code comes right after the inputs  handling in the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.update%28v=XNAGameStudio.40%29.aspx">Update</a> method:</p>
<pre class="brush: csharp;">
#if WINDOWS_PHONE
// for each detected touch
TouchCollection touchCollection = TouchPanel.GetState();
foreach (TouchLocation touchLocation in touchCollection)
{
      // upper left corner touche detection
      if (touchLocation.Position.X &lt; 50
            &amp;&amp; touchLocation.Position.Y &lt; 50)
            blueBar.Y -= 10; // move the blue bar up
      // lower left corner
      else if (touchLocation.Position.X &lt; 750
            &amp;&amp; touchLocation.Position.Y &gt; 50)
            blueBar.Y += 10; // move the blue bar down

      // upper right corner touche detection
      if (touchLocation.Position.X &gt; 430
            &amp;&amp; touchLocation.Position.Y &lt; 50)
            redBar.Y -= 10; // move the red bar up
      // lower right corner
      else if (touchLocation.Position.X &gt; 750
            &amp;&amp; touchLocation.Position.Y &gt; 430)
            redBar.Y += 10; // move the red bar down

      // ball touch
      if (touchLocation.Position.X &lt; 420
            &amp;&amp; touchLocation.Position.X &gt; 380
            &amp;&amp; touchLocation.Position.Y &lt; 260
            &amp;&amp; touchLocation.Position.Y &gt; 220)
      InitBall();
}
#endif
</pre>
<p style="text-align: justify;">This is a quite rough technique. If you’d like to better use the  touch screen, try to use the <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.touch.touchlocation.trygetpreviouslocation%28v=XNAGameStudio.40%29.aspx">TryGetPreviousPosition</a> method of a <a hreflang="en" href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.touch.touchlocation%28v=XNAGameStudio.40%29.aspx">TouchLocation</a> to follow a finger along the left or  right corner of the screen and make the bar follow the gesture.</p>
<p style="text-align: justify;">By the way, our Pong clone is now fully playable on Windows Phone 7!  And that’s it.</p>
<h1>Conclusion</h1>
<p style="text-align: justify;">Your Pong clone is now (almost) finished and working on three  different platforms. There are still many aspects to fine tune, but this  up to you now. You should have the background to do basic 2D games.</p>
<p style="text-align: justify;">Hopefully, you noticed that I’m referring to the MSDN online  documentation as much as possible. This was a secret message telling you  that reading the documentation can save you much time and avoid you  some useless search on the internet. If you still have problems, search  on the creators club forum, or expose your problem on the forum.</p>
<p style="text-align: justify;">I hope that you enjoyed following this tutorial and don’t hesitate to  give me some feedback about it.</p>
<p><strong>Download sample code:</strong> <a href="http://www.sgtconker.com/wp-content/uploads/contest/2010/Altenburger/PongCode.zip">PongCode.zip</a> (public domain)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sgtconker.com/2010/08/programming-your-first-xna-4-game-pong/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Nick Gravelyn&#8217;s Alien Aggressors Tutorial</title>
		<link>http://www.sgtconker.com/2010/08/nick-gravelyns-alien-aggressors-tutorial/</link>
		<comments>http://www.sgtconker.com/2010/08/nick-gravelyns-alien-aggressors-tutorial/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 19:37:58 +0000</pubDate>
		<dc:creator>Captain ZSquare</dc:creator>
				<category><![CDATA[2D]]></category>
		<category><![CDATA[Articles]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[Alien Aggressors]]></category>
		<category><![CDATA[Nick Gravelyn]]></category>
		<category><![CDATA[really big]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[XNA 2.0]]></category>

		<guid isPermaLink="false">http://www.sgtconker.com/?p=1624</guid>
		<description><![CDATA[Nick Gravelyn (no introduction needed) has been kind enough to send us his Alien Aggressors tutorial (for XNA Game Studio 2.0) and allow us to share it with the world.
You can get the tutorial here: AlienAggressors.pdf
And you might also need the AlienAggressorsContent.zip pack of content to be used with the tutorial.

P.S. This article first appeared [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blogs.msdn.com/b/nicgrave/">Nick Gravelyn</a> (no introduction needed) has been kind enough to send us his Alien Aggressors tutorial (for XNA Game Studio 2.0) and allow us to share it with the world.</p>
<p>You can get the tutorial here:<a href="http://www.sgtconker.com/Downloads/articles/nickg/AlienAggressors.pdf"> AlienAggressors.pdf</a></p>
<p>And you might also need the <a href="http://www.sgtconker.com/Downloads/articles/nickg/AlienAggressorsContent.zip">AlienAggressorsContent.zip</a> pack of content to be used with the tutorial.</p>
<p><img class="alignleft" title="Alien Aggressors" src="http://www.sgtconker.com/Downloads/articles/nickg/agressors.png" alt="Alien Aggressors" width="484" height="375" /></p>
<p>P.S. This article first appeared on Ziggyware (now defunct) a while ago.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sgtconker.com/2010/08/nick-gravelyns-alien-aggressors-tutorial/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bob Taco Ind back to WP7 loving</title>
		<link>http://www.sgtconker.com/2010/08/bob-taco-ind-back-to-wp7-loving/</link>
		<comments>http://www.sgtconker.com/2010/08/bob-taco-ind-back-to-wp7-loving/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 19:20:59 +0000</pubDate>
		<dc:creator>Captain ZSquare</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[WP7]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[Bob Taco Ind]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Windows Phone 7]]></category>

		<guid isPermaLink="false">http://www.sgtconker.com/?p=1621</guid>
		<description><![CDATA[After having a rough day in his relationship with Windows Phone 7, Bob Taco Ind (Michael B. McLaughlin) is back in business, with two short tutorials related to programming for the upcoming device. First, he shows you how to pin your game to the start screen, followed by one option of properly exiting a Silverlight-based [...]]]></description>
			<content:encoded><![CDATA[<p>After having <a href="http://geekswithblogs.net/mikebmcl/archive/2010/08/18/wp7-questions-concerns-and-disappointments.aspx">a rough day</a> in his relationship with Windows Phone 7, Bob Taco Ind (Michael B. McLaughlin) is back in business, with two short tutorials related to programming for the upcoming device. First, he shows you how to <a href="http://geekswithblogs.net/mikebmcl/archive/2010/08/18/how-to-pin-your-game-or-app-in-the-emulator.aspx">pin your game to the start screen</a>, followed by one option of <a href="http://geekswithblogs.net/mikebmcl/archive/2010/08/22/properly-exiting-silverlight-based-wp7-games.aspx">properly exiting a Silverlight-based game on WP7</a>.</p>
<p>Post Scriptum thoughts for my colleague Cpt. Boki after realizing I'm kinda stalking Michael's blog... Where did the MVP Watch thingy go?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sgtconker.com/2010/08/bob-taco-ind-back-to-wp7-loving/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Contest deadline approaching!</title>
		<link>http://www.sgtconker.com/2010/08/contest-deadline-approaching/</link>
		<comments>http://www.sgtconker.com/2010/08/contest-deadline-approaching/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 16:46:47 +0000</pubDate>
		<dc:creator>Captain ZSquare</dc:creator>
				<category><![CDATA["Absolutely fine"]]></category>
		<category><![CDATA[Contest]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[Absolutely Fine Tutorial Contest]]></category>
		<category><![CDATA[deadline]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.sgtconker.com/?p=1619</guid>
		<description><![CDATA[Hi all,
Just a reminder that the deadline for our 'Absolutely Fine' XNA Tutorial Contest is closing in, and you have about 1 week to send your entries into the contest.
If you forgot the details of the contest, feel free to refresh your memory.
We're currently hard at work to get the rest of the entries online [...]]]></description>
			<content:encoded><![CDATA[<p>Hi all,</p>
<p>Just a reminder that the deadline for our<a href="http://www.sgtconker.com/2010/07/the-sgt-conker-xna-tutorial-contest-2/"> 'Absolutely Fine' XNA Tutorial Contest</a> is closing in, and you have about 1 week to send your entries into the contest.</p>
<p>If you forgot the details of the contest, feel free to <a href="http://www.sgtconker.com/2010/07/the-sgt-conker-xna-tutorial-contest-2/">refresh your memory</a>.</p>
<p>We're currently hard at work to get the rest of the entries online for your reading pleasure.</p>
<p>Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sgtconker.com/2010/08/contest-deadline-approaching/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>News from nuclex.org</title>
		<link>http://www.sgtconker.com/2010/08/news-from-nuclex-org/</link>
		<comments>http://www.sgtconker.com/2010/08/news-from-nuclex-org/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 16:27:38 +0000</pubDate>
		<dc:creator>Captain ZSquare</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[Cygon]]></category>
		<category><![CDATA[GameComponent]]></category>
		<category><![CDATA[Input]]></category>
		<category><![CDATA[Nuclex]]></category>
		<category><![CDATA[Sunburn]]></category>

		<guid isPermaLink="false">http://www.sgtconker.com/?p=1616</guid>
		<description><![CDATA[Here's a couple of news from nuclex.org.
A new tutorial for Synapse Gaming's SunBurn engine  demonstrating how SunBurn (and XNA) can be used in a dependency  injection environment, a programming technique in which components are  wired up to each automatically based on predefined bindings. Read more.
Cygon explains why he has chosen to reimplement [...]]]></description>
			<content:encoded><![CDATA[<p>Here's a couple of news from <a href="http://nuclex.org/">nuclex.org</a>.</p>
<p>A new tutorial for Synapse Gaming's SunBurn engine  demonstrating how SunBurn (and XNA) can be used in a dependency  injection environment, a programming technique in which components are  wired up to each automatically based on predefined bindings. <a href="http://www.nuclex.org/blog/gamedev/99-using-ninject-with-sunburn">Read more</a>.</p>
<p>Cygon explains why he has chosen to reimplement XNA's GameComponent/DrawableGameComponent  classes himself and how he's improved his design to cover environments  where the game renders into a scene graph instead of directly using the  graphics device. <a href="http://www.nuclex.org/blog/gamedev/100-to-gamecomponent-or-not-to-gamecomponent">Read more</a>.</p>
<p>Cygon is talking about a redesign of the event-based input handling system used by the GUI in his Nuclex Framework. <a href="http://www.nuclex.org/blog/gamedev/103-quo-vadis-input-system">Read more</a>.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sgtconker.com/2010/08/news-from-nuclex-org/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XNA-UK User Group Prize Giveway!</title>
		<link>http://www.sgtconker.com/2010/08/xna-uk-user-group-prize-giveway/</link>
		<comments>http://www.sgtconker.com/2010/08/xna-uk-user-group-prize-giveway/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 16:14:16 +0000</pubDate>
		<dc:creator>Captain ZSquare</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Charles Humphrey]]></category>
		<category><![CDATA[duper]]></category>
		<category><![CDATA[super]]></category>
		<category><![CDATA[user group]]></category>
		<category><![CDATA[XNA-UK]]></category>

		<guid isPermaLink="false">http://www.sgtconker.com/?p=1613</guid>
		<description><![CDATA[Actually, it's about a Super Duper Prize Giveway at the September 1st meeting of the user group. Also accompanied by presentations about XNA, WP7, shaders and a Xap-a-thon. If you're interested and want more details, jump on their site and read all the details.
]]></description>
			<content:encoded><![CDATA[<p>Actually, it's about a Super Duper Prize Giveway at the September 1st meeting of the user group. Also accompanied by presentations about XNA, WP7, shaders and a Xap-a-thon. If you're interested and want more details, <a href="http://xna-uk.net/blogs/randomchaos/archive/2010/08/17/xblig-uk-xna-uk-ug-super-duper-prize-give-away.aspx">jump on their site and read all the details</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sgtconker.com/2010/08/xna-uk-user-group-prize-giveway/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
