<?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"
	>

<channel>
	<title>Cheezeworld</title>
	<atom:link href="http://cheezeworld.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://cheezeworld.com</link>
	<description>The Cheeze to Your Macaroni - Games, Open Source Programming, and Other Odd Ramblings.</description>
	<pubDate>Wed, 12 Nov 2008 19:55:52 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>Building a Foundation For Your Games and Handling Screens</title>
		<link>http://cheezeworld.com/game-foundation-and-screens/</link>
		<comments>http://cheezeworld.com/game-foundation-and-screens/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 19:29:20 +0000</pubDate>
		<dc:creator>Colby Cheeze</dc:creator>
		
		<category><![CDATA[Game Library]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[foundation]]></category>

		<category><![CDATA[game structure]]></category>

		<category><![CDATA[screens]]></category>

		<guid isPermaLink="false">http://cheezeworld.com/?p=84</guid>
		<description><![CDATA[This article is part 1 of a series: The Structure of a Game. Read the Introduction here.

What does a game foundation consist of?
The starting point for any well built structure is a strong foundation. It is important that the foundation of your game is able to handle the basic functionality that will apply across all [...]]]></description>
			<content:encoded><![CDATA[<p>This article is part 1 of a series: The Structure of a Game. <a title="Game Structure - Introduction" href="http://cheezeworld.com/game-structure/">Read the Introduction here</a>.</p>
<p><a href="http://cheezeworld.com/wp-content/uploads/2008/11/dscf0007.jpg"><img class="size-full wp-image-85 alignnone" title="dscf0007" src="http://cheezeworld.com/wp-content/uploads/2008/11/dscf0007.jpg" alt="Building Foundation" width="350" height="263" /></a></p>
<h2>What does a game foundation consist of?</h2>
<p>The starting point for any well built structure is a strong foundation. It is important that the foundation of your game is able to handle the basic functionality that will apply across all of your games, and does it simply with little to no extra effort on your part.</p>
<p>Also, what do all games have in common? They consist of various screens (Oh yes they do, or your game would be considered a tech demo my friend). With that in mind, our structure should be able to handle the following:</p>
<ul>
<li>Context Menu Setup</li>
<li>Access to the Stage.</li>
<li>Tweaking of game speed</li>
<li>Frame Rate Tracking</li>
<li>Sending updates to your game</li>
<li>Custom Game Cursor ( if applicable to your game )</li>
<li>Global game pause</li>
<li>Ability to step through code 1 update at a time</li>
<li>Screen switching</li>
</ul>
<p>In order to implement all of these in a manner that we can easily and quickly transfer over to each and every project and use without any real need of changing the code at all we will create our structure using the following 3 classes:</p>
<ul>
<li>IScreenItem - Anything that will be considered a screen, such as MenuScreen, GameScreen, etc...</li>
<li>AScreen - An Abstract class which handles screen switching.</li>
<li>Root - Our meat and potatoes of the foundation. Handles the "Basic" functionality discussed above.</li>
</ul>
<h2>Lets build it!</h2>
<p>A few concepts for me to mention now before we start are that almost all of our game objects will use an update and dispose method. Updates will filter down from the Root class so as to keep greater control of the game and eliminate the inconvenience and speed hog of creating multiple frame event listeners to the stage. Also it is good practice to clean up your code on removal such as removing any event listeners and nulling any outside references.</p>
<p>Also we will be using a constant time step to update our code. It is quite simple to interchange actually which I can show you, but in my experience a non-constant time step can cause inconsistencies that are difficult to debug.</p>
<p>When I refer to "Global Game Pause" this means that all updates to the game objects and rendering. You may have seperate pause logic within your game screen that pauses only certain features, still allowing menus or other GUI to run.</p>
<h2>The IScreenItem and AScreen Classes</h2>
<p>Okay, so let's begin with the IScreenItem class. This will be the interface for any screen used in the game...<span id="more-84"></span></p>
<pre class="actionscript"><span style="color: #0066CC;">public</span> <span style="color: #0066CC;">interface</span> IScreenItem <span style="color: #0066CC;">extends</span> IEventDispatcher
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">function</span> setScreen<span style="color: #66cc66;">&#40;</span>screen:<span style="color: #000000; font-weight: bold;">Class</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>;
	<span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #66cc66;">&#40;</span>timePassed:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>;
	<span style="color: #000000; font-weight: bold;">function</span> dispose<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>;
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> parentScreen<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:IScreenItem;
	<span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> currentScreen<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:IScreenItem;
<span style="color: #66cc66;">&#125;</span></pre>
<p>All screens will have an interface for updating thier logic. We will send the time passed since the last update so that it is calculated in a centralized location ( The Root ). Also each screen is responsible for disposing of itself...if necessary.</p>
<p>We also build an abstract class AScreen which holds the basical functionality of screen switching for us.</p>
<pre class="actionscript"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AScreen <span style="color: #0066CC;">extends</span> Sprite <span style="color: #0066CC;">implements</span> IScreenItem
 <span style="color: #66cc66;">&#123;</span>
 <span style="color: #808080; font-style: italic;">// Initialization ---------------------------------------------------------------------------</span>
 <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> AScreen<span style="color: #66cc66;">&#40;</span> parentScreen:IScreenItem=<span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span>
 <span style="color: #66cc66;">&#123;</span>
 	m_parentScreen = parentScreen;
 	m_parentScreen == <span style="color: #000000; font-weight: bold;">null</span> ? m_currentScreen = <span style="color: #000000; font-weight: bold;">null</span> : m_currentScreen = currentScreen;
 <span style="color: #66cc66;">&#125;</span>
 <span style="color: #808080; font-style: italic;">// ------------------------------------------------------------------------------------------</span>
&nbsp;
 <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> parentScreen<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:IScreenItem<span style="color: #66cc66;">&#123;</span> <span style="color: #b1b100;">return</span> m_parentScreen; <span style="color: #66cc66;">&#125;</span>
&nbsp;
 <span style="color: #808080; font-style: italic;">/**
  * Will filter up to the top of the screen structure and return the root current screen.
  * This is done so that any screens created down the line may have access to change the
  * screen without actual reference to the root.
  *
  */</span>
 <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> currentScreen<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:IScreenItem
 <span style="color: #66cc66;">&#123;</span>
 	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> m_parentScreen != <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span>
 	<span style="color: #66cc66;">&#123;</span>
 		<span style="color: #b1b100;">return</span> m_parentScreen.<span style="color: #006600;">currentScreen</span>;
 	<span style="color: #66cc66;">&#125;</span>
 	<span style="color: #b1b100;">return</span> m_currentScreen;
 <span style="color: #66cc66;">&#125;</span>
&nbsp;
 <span style="color: #808080; font-style: italic;">// Override these functions with your subclasses ----------------------------------------------</span>
&nbsp;
 <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #66cc66;">&#40;</span> timePassed:<span style="color: #0066CC;">int</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
 <span style="color: #66cc66;">&#123;</span>
 	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> m_parentScreen==<span style="color: #000000; font-weight: bold;">null</span> &amp;amp;&amp;amp; m_currentScreen!=<span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span> m_currentScreen.<span style="color: #006600;">update</span><span style="color: #66cc66;">&#40;</span> timePassed <span style="color: #66cc66;">&#41;</span>; <span style="color: #66cc66;">&#125;</span>
 <span style="color: #66cc66;">&#125;</span>
&nbsp;
 <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> dispose<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>
&nbsp;
 <span style="color: #808080; font-style: italic;">// --------------------------------------------------------------------------------------------</span>
&nbsp;
 <span style="color: #808080; font-style: italic;">/**
  * Changes the root current screen to the screen specified.
  * All screen's dispose method are called for cleanup.
  *
  */</span>
 <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setScreen<span style="color: #66cc66;">&#40;</span> screen:<span style="color: #000000; font-weight: bold;">Class</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
 <span style="color: #66cc66;">&#123;</span>
 	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> m_parentScreen != <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span>
 	<span style="color: #66cc66;">&#123;</span>
 		m_parentScreen.<span style="color: #006600;">setScreen</span><span style="color: #66cc66;">&#40;</span> screen <span style="color: #66cc66;">&#41;</span>;
 		<span style="color: #b1b100;">return</span>;
 	<span style="color: #66cc66;">&#125;</span>
 	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> m_currentScreen!= <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span>
 	<span style="color: #66cc66;">&#123;</span>
 		removeChild<span style="color: #66cc66;">&#40;</span> m_currentScreen as Sprite <span style="color: #66cc66;">&#41;</span>;
 		m_currentScreen.<span style="color: #006600;">dispose</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
 	<span style="color: #66cc66;">&#125;</span>
 	m_currentScreen = <span style="color: #000000; font-weight: bold;">new</span> screen<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">this</span> <span style="color: #66cc66;">&#41;</span>;
 	addChild<span style="color: #66cc66;">&#40;</span> m_currentScreen as Sprite <span style="color: #66cc66;">&#41;</span>;
 <span style="color: #66cc66;">&#125;</span>
&nbsp;
 <span style="color: #808080; font-style: italic;">// -- PRIVATE --</span>
&nbsp;
 <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> m_parentScreen:IScreenItem;
 <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> m_currentScreen:IScreenItem;
 <span style="color: #66cc66;">&#125;</span></pre>
<h2>The Root Class</h2>
<p>Now finally we build the bread and butter, which is the Root class. I've left out loading of external data and setting up a custom cursor. We can discuss those topics in a later article. You can see that I handle game speed by using a multiplier on the update function. There is code in the handleInput function to help with some in game debugging.</p>
<p>Note also that I am using my Input Manager class. I HIGHLY recommend that you use some sort of class to manage input in your games, whether it is mine or one of your own creation. If you would like view the article on the Input Class you can <a href="http://cheezeworld.com/custom-input-class/">go here</a>. To download the input class files <a href="http://code.google.com/p/cheezeworld/">visit the google project page here</a>.</p>
<pre class="actionscript"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Root <span style="color: #0066CC;">extends</span> AScreen
<span style="color: #66cc66;">&#123;</span>		
&nbsp;
	<span style="color: #0066CC;">private</span> const DEFAULT_QUALITY:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;high&quot;</span>;
 	<span style="color: #0066CC;">private</span> const TIME_PASSED:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">20</span>;
 	<span style="color: #0066CC;">private</span> const ONE_SECOND:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">1000</span>;
 	<span style="color: #0066CC;">private</span> const FRAME_RATE:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">50</span>;
&nbsp;
 	<span style="color: #808080; font-style: italic;">// -- STATIC --</span>
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> gameSpeed<span style="color: #66cc66;">&#40;</span> value:<span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
	<span style="color: #66cc66;">&#123;</span>
		m_gameSpeed = value;
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> m_gameSpeed &amp;lt; <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> m_gameSpeed = <span style="color: #cc66cc;">0</span>; <span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> gameSpeed<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #b1b100;">return</span> m_gameSpeed; <span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> <span style="color: #0066CC;">fps</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">int</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #b1b100;">return</span> m_fps; <span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> avgFps<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">int</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #b1b100;">return</span> m_avgFps; <span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">stage</span>:<span style="color: #0066CC;">Stage</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * Use to globally pause the game.
	 *
	 */</span>
	<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> togglePause<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
 	<span style="color: #66cc66;">&#123;</span>
 		m_isUpdateOn = !m_isUpdateOn;
 	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * Place in code where you would like a breakpoint. The game will be paused globally
	 * and the message will be traced.
	 * @param a_message The message to output when this breakpoint is reached.
	 * @param a_forced Force this breakpoint to run, even if breakpoints are turned off.
	 *
	 */</span>
	<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> breakpoint<span style="color: #66cc66;">&#40;</span> a_message:<span style="color: #0066CC;">String</span>, a_forced:<span style="color: #0066CC;">Boolean</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
	<span style="color: #66cc66;">&#123;</span>
 		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> !m_areBreakpointsEnabled &amp;amp;&amp;amp; !a_forced <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span> <span style="color: #b1b100;">return</span>; <span style="color: #66cc66;">&#125;</span>
&nbsp;
 		<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot; Breakpoint: &quot;</span> + a_message <span style="color: #66cc66;">&#41;</span>;
 		m_isUpdateOn = <span style="color: #000000; font-weight: bold;">false</span>;
 	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">// -- PUBLIC --</span>
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Root<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>:<span style="color: #0066CC;">Stage</span>=<span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		m_gameSpeed = <span style="color: #cc66cc;">1</span>;
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">stage</span>==<span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			Root.<span style="color: #0066CC;">stage</span> = <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">stage</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #b1b100;">else</span>
		<span style="color: #66cc66;">&#123;</span>
			Root.<span style="color: #0066CC;">stage</span> = <span style="color: #0066CC;">stage</span>;
		<span style="color: #66cc66;">&#125;</span>
		Root.<span style="color: #006600;">m_fps</span> = Root.<span style="color: #006600;">m_avgFps</span> = <span style="color: #cc66cc;">0</span>;
		Root.<span style="color: #0066CC;">stage</span>.<span style="color: #0066CC;">quality</span> = DEFAULT_QUALITY;
&nbsp;
		m_isUpdateOn = <span style="color: #000000; font-weight: bold;">true</span>;
 		m_areBreakpointsEnabled = <span style="color: #000000; font-weight: bold;">true</span>;
&nbsp;
 		Input.<span style="color: #006600;">instance</span>.<span style="color: #006600;">activate</span><span style="color: #66cc66;">&#40;</span>Root.<span style="color: #0066CC;">stage</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
 		<span style="color: #808080; font-style: italic;">// External data will be discussed in a future article</span>
 		<span style="color: #808080; font-style: italic;">// Load External Data ----------------------------------------</span>
 		<span style="color: #808080; font-style: italic;">// ExternalData.instance.addEventListener( Event.COMPLETE, onDataLoad );</span>
 		<span style="color: #808080; font-style: italic;">// ExternalData.instance.load();</span>
 		<span style="color: #808080; font-style: italic;">// -----------------------</span>
 		onDataLoad<span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
 	<span style="color: #0066CC;">public</span> override <span style="color: #000000; font-weight: bold;">function</span> setScreen<span style="color: #66cc66;">&#40;</span>screen:<span style="color: #000000; font-weight: bold;">Class</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
 	<span style="color: #66cc66;">&#123;</span>
 		m_screenToSet = screen;
 	<span style="color: #66cc66;">&#125;</span>
&nbsp;
 	<span style="color: #808080; font-style: italic;">// -- PRIVATE --</span>
&nbsp;
 	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onDataLoad<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">e</span>:Event <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
 	<span style="color: #66cc66;">&#123;</span>
 		<span style="color: #808080; font-style: italic;">// ExternalData.instance.removeEventListener( Event.COMPLETE, onDataLoad );</span>
&nbsp;
 		Root.<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">ENTER_FRAME</span>,<span style="color: #0066CC;">onEnterFrame</span> <span style="color: #66cc66;">&#41;</span>;
 		Root.<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">showDefaultContextMenu</span> = <span style="color: #000000; font-weight: bold;">false</span>;
&nbsp;
 		<span style="color: #808080; font-style: italic;">// Set up custom cursor here -----</span>
 		<span style="color: #808080; font-style: italic;">// Mouse.hide();</span>
 		<span style="color: #808080; font-style: italic;">// m_customCursor = new CustomCursor();</span>
&nbsp;
 		m_stopWatch = <span style="color: #000000; font-weight: bold;">new</span> StopWatch<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
 		m_deltaTime = <span style="color: #cc66cc;">0</span>;
 	<span style="color: #66cc66;">&#125;</span>
&nbsp;
 	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">onEnterFrame</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">e</span>:Event <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
 	<span style="color: #66cc66;">&#123;</span>
 		recordFPS<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
 		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> m_isUpdateOn <span style="color: #66cc66;">&#41;</span>
 		<span style="color: #66cc66;">&#123;</span>
 			update<span style="color: #66cc66;">&#40;</span> TIME_PASSED * m_gameSpeed <span style="color: #66cc66;">&#41;</span>;
 		<span style="color: #66cc66;">&#125;</span>
&nbsp;
 		handleInput<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
 		Input.<span style="color: #006600;">instance</span>.<span style="color: #006600;">update</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
 		<span style="color: #808080; font-style: italic;">//handle custom cursor</span>
&nbsp;
 		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> m_screenToSet <span style="color: #66cc66;">&#41;</span>
 		<span style="color: #66cc66;">&#123;</span>
 			<span style="color: #0066CC;">super</span>.<span style="color: #006600;">setScreen</span><span style="color: #66cc66;">&#40;</span> m_screenToSet <span style="color: #66cc66;">&#41;</span>;
 			m_screenToSet = <span style="color: #000000; font-weight: bold;">null</span>;
 		<span style="color: #66cc66;">&#125;</span>
 	<span style="color: #66cc66;">&#125;</span>
&nbsp;
 	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> recordFps<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
 	<span style="color: #66cc66;">&#123;</span>
 		m_deltaTime = m_stopWatch.<span style="color: #006600;">timePassed</span>;
 		m_stopWatch.<span style="color: #006600;">reset</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
 		m_fps = ONE_SECOND / m_deltaTime;
 		m_fpsCount += Root.<span style="color: #006600;">m_fps</span>;
 		m_avgFpsCounter--;
 		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> m_avgFpsCounter &amp;lt;= <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#41;</span>
 		<span style="color: #66cc66;">&#123;</span>
 			m_avgFps = m_fpsCount / FRAME_RATE;
 			m_avgFpsCounter = FRAME_RATE;
 			m_fpsCount = <span style="color: #cc66cc;">0</span>;
 		<span style="color: #66cc66;">&#125;</span>
 	<span style="color: #66cc66;">&#125;</span>
&nbsp;
 	<span style="color: #808080; font-style: italic;">/**
 	 * Here we handle code for dealing with breakpoints, global pausing, and stepping.
 	 * Be sure to deactivate this code for the release of your game!
 	 *
 	 */</span>
 	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> handleInput<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
 	<span style="color: #66cc66;">&#123;</span>
 		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> Input.<span style="color: #006600;">instance</span>.<span style="color: #006600;">isKeyPressed</span><span style="color: #66cc66;">&#40;</span> KeyCode.<span style="color: #0066CC;">END</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>
 		<span style="color: #66cc66;">&#123;</span>
 			m_isUpdateOn = !m_isUpdateOn;
 			<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot; Game &quot;</span> + <span style="color: #66cc66;">&#40;</span> m_isUpdateOn ? <span style="color: #ff0000;">&quot;unpaused&quot;</span> : <span style="color: #ff0000;">&quot;paused&quot;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
 		<span style="color: #66cc66;">&#125;</span>
 		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> Input.<span style="color: #006600;">instance</span>.<span style="color: #006600;">isKeyPressed</span><span style="color: #66cc66;">&#40;</span> KeyCode.<span style="color: #006600;">PAGE_DOWN</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>
 		<span style="color: #66cc66;">&#123;</span>
 			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> !m_isUpdateOn <span style="color: #66cc66;">&#41;</span>
 			<span style="color: #66cc66;">&#123;</span>
 				<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot; Stepping foward &quot;</span> + TIME_PASSED + <span style="color: #ff0000;">&quot; milliseconds.&quot;</span> <span style="color: #66cc66;">&#41;</span>;
&nbsp;
 				update<span style="color: #66cc66;">&#40;</span> TIME_PASSED <span style="color: #66cc66;">&#41;</span>;
 			<span style="color: #66cc66;">&#125;</span>
 		<span style="color: #66cc66;">&#125;</span>
 		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> Input.<span style="color: #006600;">instance</span>.<span style="color: #006600;">isKeyPressed</span><span style="color: #66cc66;">&#40;</span> KeyCode.<span style="color: #006600;">PAGE_UP</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>
 		<span style="color: #66cc66;">&#123;</span>
 			m_areBreakpointsEnabled = != m_areBreakpointsEnabled;
 			<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot; Breakpoints &quot;</span> + <span style="color: #66cc66;">&#40;</span> m_areBreakpointsEnabled ? <span style="color: #ff0000;">&quot;enabled&quot;</span> : <span style="color: #ff0000;">&quot;disabled&quot;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
 		<span style="color: #66cc66;">&#125;</span>
 	<span style="color: #66cc66;">&#125;</span>
&nbsp;
 	<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> m_isUpdateOn:<span style="color: #0066CC;">Boolean</span>;
 	<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> m_areBreakpointsEnabled:<span style="color: #0066CC;">Boolean</span>;
&nbsp;
	<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> m_fps:<span style="color: #0066CC;">int</span>;
	<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> m_avgFps:<span style="color: #0066CC;">int</span>;
	<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> m_gameSpeed:<span style="color: #0066CC;">Number</span>;
&nbsp;
 	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> m_screenToSet:<span style="color: #000000; font-weight: bold;">Class</span>;
 	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> m_stopWatch:StopWatch;
 	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> m_newTime:<span style="color: #0066CC;">int</span>;
 	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> m_oldTime:<span style="color: #0066CC;">int</span>;
 	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> m_deltaTime:<span style="color: #0066CC;">int</span>;
 	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> m_fpsCount:<span style="color: #0066CC;">int</span>;
 	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> m_avgFpsCounter:<span style="color: #0066CC;">int</span>;
&nbsp;
<span style="color: #66cc66;">&#125;</span></pre>
<h2>Wrapping up</h2>
<p>Now that you have the basic structure set up, starting any new game project is extremely simple. Have your preloader call a "Main" class whose sole function is to be the Root screen. The main class will call the first screen in the game, usually the Menu.</p>
<pre class="actionscript"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> Root
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>:<span style="color: #0066CC;">Stage</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		setScreen<span style="color: #66cc66;">&#40;</span> Screen1 <span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>
<p>Now when creating your screens, just extend the AScreen class:</p>
<pre class="actionscript"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Screen1 <span style="color: #0066CC;">extends</span> AScreen
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Screen1<span style="color: #66cc66;">&#40;</span>parentScreen:IScreenItem=<span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span>parentScreen<span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #000000; font-weight: bold;">var</span> txt:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		txt.<span style="color: #0066CC;">htmlText</span> = <span style="color: #ff0000;">&quot;&lt;span style=&quot;</span><span style="color: #0066CC;">color</span>: <span style="color: #808080; font-style: italic;">#ffffff;&quot;&gt; Screen 1 &lt;/span&gt;&quot;;</span>
		txt.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">100</span>;
		txt.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">100</span>;
		addChild<span style="color: #66cc66;">&#40;</span> txt <span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #0066CC;">public</span> override <span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #66cc66;">&#40;</span>timePassed:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> Input.<span style="color: #006600;">instance</span>.<span style="color: #006600;">isKeyPressed</span><span style="color: #66cc66;">&#40;</span> KeyCode.<span style="color: #0066CC;">ENTER</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			setScreen<span style="color: #66cc66;">&#40;</span> Screen2 <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span></pre>
<p>Well, that's it for your game foundation! You can download the code along with an example project at the <a href="http://code.google.com/p/cheezeworld/">google project page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://cheezeworld.com/game-foundation-and-screens/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Programming Tidbit #1 - Eliminate Magic Numbers</title>
		<link>http://cheezeworld.com/tidbit1-magic-numbers/</link>
		<comments>http://cheezeworld.com/tidbit1-magic-numbers/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 16:09:14 +0000</pubDate>
		<dc:creator>Colby Cheeze</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Programming Tidbits]]></category>

		<category><![CDATA[best practices]]></category>

		<category><![CDATA[magic numbers]]></category>

		<category><![CDATA[tidbits]]></category>

		<guid isPermaLink="false">http://cheezeworld.com/?p=87</guid>
		<description><![CDATA[
This is the first post in a series "Programming Tidbits." Essentially there are some useful bits of information or code that I would like to relay, but don't REALLY warrant an entire article. You can view the full list of tidbits here.
The Wrong Thing...
When programming, a lot of times you may find yourself throwing together [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://cheezeworld.com/wp-content/uploads/2008/11/hocus-plate-small0003_edited-5.jpg"><img class="size-full wp-image-88 alignleft" title="hocus-plate-small0003_edited-5" src="http://cheezeworld.com/wp-content/uploads/2008/11/hocus-plate-small0003_edited-5.jpg" alt="" width="237" height="239" /></a></p>
<p>This is the first post in a series "Programming Tidbits." Essentially there are some useful bits of information or code that I would like to relay, but don't REALLY warrant an entire article. You can <a href="http://cheezeworld.com/category/programming-tidbits/">view the full list of tidbits here</a>.</p>
<h3>The Wrong Thing...</h3>
<p>When programming, a lot of times you may find yourself throwing together some code which uses "Magic Numbers." A magic number is basically just any static number sitting in your code such as:</p>
<pre class="actionscript"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> moveMyCharacter<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	myCharacter.<span style="color: #006600;">x</span> += <span style="color: #cc66cc;">5</span>;
	myCharacter.<span style="color: #006600;">y</span> += <span style="color: #cc66cc;">5</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> damageEnemy<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	someEnemy.<span style="color: #006600;">health</span> -= <span style="color: #cc66cc;">20</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<h3>Why is it bad?</h3>
<p>Now obviously that is just a simple example, but let's say you have code ALL OVER your project using these "magic numbers." What happens then, if later you want to change these numbers? You have a long and tedious process of finding all times that they are used. Not only that, but you are prone to missing something which will therefore lead to unpredictable code and bugs.</p>
<h3>The right thing...</h3>
<p>Instead of being mean to yourself, do the right thing and create constants or variables for all of your magic numbers. The usual place to put them is at the top of your class. Even better would be to externalize the data into some sort of settings file ( if the data is worthy of course ). I'll be discussing externalizing data in a future article if you aren't quite sure how to go about that...</p>
<p>So here is the code once again, done properly.</p>
<pre class="actionscript"><span style="color: #808080; font-style: italic;">// Top of your Class somewhere...</span>
<span style="color: #0066CC;">private</span> const MOVE_SPEED:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">5</span>;
<span style="color: #0066CC;">private</span> const HERO_DAMAGE:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">20</span>;
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> moveMyCharacter<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	myCharacter.<span style="color: #006600;">x</span> += MOVE_SPEED;
	myCharacter.<span style="color: #006600;">y</span> += MOVE_SPEED;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> damageEnemy<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	someEnemy.<span style="color: #006600;">health</span> -= HERO_DAMAGE;
<span style="color: #66cc66;">&#125;</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://cheezeworld.com/tidbit1-magic-numbers/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Structure of a Game - Introduction</title>
		<link>http://cheezeworld.com/game-structure/</link>
		<comments>http://cheezeworld.com/game-structure/#comments</comments>
		<pubDate>Sat, 08 Nov 2008 02:26:15 +0000</pubDate>
		<dc:creator>Colby Cheeze</dc:creator>
		
		<category><![CDATA[Game Library]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://cheezeworld.com/?p=72</guid>
		<description><![CDATA[
Inspiration
When I first began programming, it seemed like there were a vast amount of tutorials out there which taught you how to do a specific task such as "make a shooting game" or something of that nature. These were great for me at first, as I didn't know my left toe from my right thumb. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://cheezeworld.com/wp-content/uploads/2008/11/gears.jpg"><img class="size-medium wp-image-73 alignleft" title="gears" src="http://cheezeworld.com/wp-content/uploads/2008/11/gears-298x300.jpg" alt="" width="298" height="300" /></a></p>
<h3>Inspiration</h3>
<p>When I first began programming, it seemed like there were a vast amount of tutorials out there which taught you how to do a specific task such as "make a shooting game" or something of that nature. These were great for me at first, as I didn't know my left toe from my right thumb. Eventually however, I began to get better and I craved more organized and useful information such as how to actually structure games, and how to use proper OOP techniques etc. There simply just isn't enough of it out there. I found a few articles explaining several ideas and concepts, and I read many different books on OOP and design patterns…then after about a year of working together the different I came up with a great mesh of it all to develop my current game structure.</p>
<h3>Purpose</h3>
<p>My purpose for this article and those that follow in this series is to teach you piece by piece how to build a reusable game structure for your games as well as explain different game coding techniques and concepts along the way. I'll be providing code that I've written, however for maximum benefit I recommend that you modify or rewrite it to your style and needs. For example, each time I start a new project I simply copy all of my game code over from my latest game and then delete classes which I won't need, as well as tweak existing code to fit the current project.</p>
<h3>Requirements</h3>
<p>It is good practice to write down some goals and requirements for what you would like your game engine to incorporate, so let's consider this now.  Our game structure will have consist of the following:</p>
<ul>
<li>The ability to save game state, pause, speed up and slow down</li>
<li>We can set a camera position and size to render what is in the game world.</li>
<li>The game logic will be separate from the rendering logic.</li>
<li>Data driven development. IE: Creatures and levels will be built outside of the core code engine itself, usually from XML or on a higher level in an editor of some sorts.</li>
<li>Object creation is centered in one location</li>
<li>Control of entities is done through "controller" classes.</li>
<li>And of course...it will run incredibly fast.</li>
</ul>
<p>If any of that sounded complicated, fear not. I will be discussing the reasons for each part as well as explaining how it all works. We will create one piece at a time and build upon the structure as we move along, making improvements along the way.</p>
<p>As I complete each section I will update this article to link to each piece. You may visit the <a href="http://code.google.com/p/cheezeworld/" target="_self">google project page</a> to aquire all of the project files and source code as well.</p>
<h2>Additional Articles in this series:</h2>
<ul>
<li><a href="http://cheezeworld.com/game-foundation-and-screens/">Building a Foundation For Your Games and Handling Screens</a></li>
<li>Entity Class - Just what is an entity? ( Coming soon )</li>
<li>Seperating Game Logic from Rendering Logic</li>
<li>Setting up AI</li>
<li>Game Object Management</li>
<li>The Game Factory - How You Should REALLY be creating objects</li>
<li>Data Driven Development</li>
<li>And more...</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://cheezeworld.com/game-structure/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Programming on Paper</title>
		<link>http://cheezeworld.com/programming-on-paper/</link>
		<comments>http://cheezeworld.com/programming-on-paper/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 15:34:33 +0000</pubDate>
		<dc:creator>Colby Cheeze</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[organization]]></category>

		<category><![CDATA[paper]]></category>

		<category><![CDATA[planning]]></category>

		<category><![CDATA[pseudo code]]></category>

		<guid isPermaLink="false">http://cheezeworld.com/?p=62</guid>
		<description><![CDATA[
I want to discuss a technique that I have been using which works very well to get past the initial strain of programming a new part into your game. Yesterday I was trying to figure out how I would program the abilities system for units ( it is a Diablo style game, so there is [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://cheezeworld.com/wp-content/uploads/2008/10/pen-paper.jpg"><img class="alignleft size-full wp-image-63" title="pen-paper" src="http://cheezeworld.com/wp-content/uploads/2008/10/pen-paper.jpg" alt="" width="400" height="300" /></a></p>
<p>I want to discuss a technique that I have been using which works very well to get past the initial strain of programming a new part into your game. Yesterday I was trying to figure out how I would program the abilities system for units ( it is a Diablo style game, so there is a possibility for a lot of abilities ).</p>
<p>After staring at the screen for a while, I pulled out the ol' handy dandy notebook and just began writing things down on paper. Shortly thereafter I had the entire system programmed, and it worked great!</p>
<p>So, the process of programming on paper works like this:</p>
<ol>
<li>Decide your problem. Write it down.</li>
<li>List out the steps that need to take place from the player's view in order for the problem to work. IE:
<ul>
<li>Player chooses class ( Wizard for example )</li>
<li>Unit is given abilities.</li>
<li>Player presses ability 1 key, ability 1 activates.</li>
</ul>
</li>
<li>Now that you see what is required to complete your problem it is much easier to program it. Decide on which classes will be needed, and then write out how it will all work using pseudo code...so for me it was something like this:
<ul>
<li>Ability Class, abilities will extend this...for example: HealAbility, ProjectileAbility, etc.</li>
<li>onKeyPress( "A" ) : Unit.useAbility( 1 );</li>
<li>Unit.useAbility(): ability1.execute();</li>
<li>ability1.execute(): unit.addHealth( 20 ); //or spawnProjectile( "Fireball" ); //or unit.addBuff( ... )</li>
</ul>
</li>
<li>Once you have all of it written down in pseudo code like that it really makes it super simple to code everything because you are just basically putting it in Actionscript.</li>
</ol>
<p>Originally I had thought it would be difficult and take quite some time to design and program all of the things I did yesterday (it was a lot) however since I used this technique I believe it relieved the pressure of creating code that doesn't work and just let me focus on the concept of HOW it should work. Hopefully you can find a style or programming on paper that works best for you as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://cheezeworld.com/programming-on-paper/feed/</wfw:commentRss>
		</item>
		<item>
		<title>An update and something funny</title>
		<link>http://cheezeworld.com/an-update-and-something-funny/</link>
		<comments>http://cheezeworld.com/an-update-and-something-funny/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 13:12:46 +0000</pubDate>
		<dc:creator>Colby Cheeze</dc:creator>
		
		<category><![CDATA[News]]></category>

		<category><![CDATA[funny]]></category>

		<category><![CDATA[update]]></category>

		<guid isPermaLink="false">http://cheezeworld.com/?p=52</guid>
		<description><![CDATA[Last night I was looking on digg and found something hilarious.
Well I haven't written anything of value in a while due to being super busy ( and gone ) so here is a bit of an update. During half of September and most of October I was in Bridge City, Texas which is a small [...]]]></description>
			<content:encoded><![CDATA[<p>Last night I was looking on digg and found something hilarious.</p>
<div id="attachment_53" class="wp-caption alignnone" style="width: 510px"><a href="http://cheezeworld.com/wp-content/uploads/2008/10/funnydiggpic.png"><img class="size-full wp-image-53" title="funnydiggpic" src="http://cheezeworld.com/wp-content/uploads/2008/10/funnydiggpic.png" alt="Coincidence? Who knows..." width="500" height="79" /></a><p class="wp-caption-text">Coincidence? Who knows...</p></div>
<p>Well I haven't written anything of value in a while due to being super busy ( and gone ) so here is a bit of an update. During half of September and most of October I was in Bridge City, Texas which is a small town that was probably hit the hardest during the hurricane. Only 14 homes in the ENTIRE city were not destroyed by flood. The town has around 4000 homes.</p>
<p>Now that I am back I am working diligently on a new project, which should be done in the latter part of November if I keep on track ( which I am doing ). Also I have some articles planned which you all should look out for.</p>
]]></content:encoded>
			<wfw:commentRss>http://cheezeworld.com/an-update-and-something-funny/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Converted all code to MIT license.</title>
		<link>http://cheezeworld.com/converted-all-code-to-mit-license/</link>
		<comments>http://cheezeworld.com/converted-all-code-to-mit-license/#comments</comments>
		<pubDate>Sun, 07 Sep 2008 20:07:10 +0000</pubDate>
		<dc:creator>Colby Cheeze</dc:creator>
		
		<category><![CDATA[News]]></category>

		<category><![CDATA[license]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://cheezeworld.com/?p=50</guid>
		<description><![CDATA[After getting some messages informing me of why the GPL was the wrong license I looked it over and said to myself, "oops!" I didn't realize that by using them you would have to keep your project GPL as well.
I have converted all of the files to an MIT license so that you can reuse [...]]]></description>
			<content:encoded><![CDATA[<p>After getting some messages informing me of why the GPL was the wrong license I looked it over and said to myself, "oops!" I didn't realize that by using them you would have to keep your project GPL as well.</p>
<p>I have converted all of the files to an MIT license so that you can reuse them in any way that you please. Be sure to visit the google code page to download everything.</p>
<p><a title="google code page" href="http://code.google.com/p/cheezeworld">http://code.google.com/p/cheezeworld</a></p>
]]></content:encoded>
			<wfw:commentRss>http://cheezeworld.com/converted-all-code-to-mit-license/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Whoops! I&#8217;ve been away for a while.</title>
		<link>http://cheezeworld.com/whoops-ive-been-away-for-a-while/</link>
		<comments>http://cheezeworld.com/whoops-ive-been-away-for-a-while/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 23:21:53 +0000</pubDate>
		<dc:creator>Colby Cheeze</dc:creator>
		
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://cheezeworld.com/?p=45</guid>
		<description><![CDATA[So I haven't really been on the internet recently...somewhat of a leave of absence for the month of July or so. Sorry for anyone trying to access my website while it has been down, however that shouldn't happen again.
Anyways. I am back to work on Space Crusade and I should be done shortly. No more [...]]]></description>
			<content:encoded><![CDATA[<p>So I haven't really been on the internet recently...somewhat of a leave of absence for the month of July or so. Sorry for anyone trying to access my website while it has been down, however that shouldn't happen again.</p>
<p>Anyways. I am back to work on Space Crusade and I should be done shortly. No more demo updates until I am done though sorry! Also I have some plans for new articles and videos after I get some work done. Hope everyone has been having a great Summer. See you around!</p>
]]></content:encoded>
			<wfw:commentRss>http://cheezeworld.com/whoops-ive-been-away-for-a-while/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Adopt Some Coding Conventions for Projects: Sloppy Code SUCKS!</title>
		<link>http://cheezeworld.com/coding-standards/</link>
		<comments>http://cheezeworld.com/coding-standards/#comments</comments>
		<pubDate>Sun, 01 Jun 2008 17:57:10 +0000</pubDate>
		<dc:creator>Colby Cheeze</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[actionscript 3]]></category>

		<category><![CDATA[coding standards]]></category>

		<category><![CDATA[game]]></category>

		<category><![CDATA[speed]]></category>

		<guid isPermaLink="false">http://cheezeworld.com/?p=43</guid>
		<description><![CDATA[I am writing this article in the hopes that you will learn from mistakes that I have made. Let me just tell you...sloppy code SUCKS! Once you start getting into bigger projects (or even not such a big project) and even worse when you start to work with others and share code things can become [...]]]></description>
			<content:encoded><![CDATA[<p>I am writing this article in the hopes that you will learn from mistakes that I have made. Let me just tell you...sloppy code SUCKS! Once you start getting into bigger projects (or even not such a big project) and even worse when you start to work with others and share code things can become a mess. So I am hoping some of you with no coding standard or no idea of how to "properly" structure your code will get something out of this and decide to do the same or at the least come up with your own standard and stick with it.</p>
<p>Occasionally I do tweak or add to my standards but for the most part I really do keep everything the same.</p>
<p>Currently I've been improving some habits of mine (mainly things like spacing and brackets etc) a bit so my older code is a little sloppier than my newer stuff which is okay. I also want to first point out this <a href="http://www.gamepoetry.com/wpress/2008/04/04/improving-your-coding-habits-using-coding-conventions/">article by GamePoetry</a> which links to the <a href="http://www.gamepoetry.com/wpress/wp-content/uploads/2008/04/urbansquall_coding_convention.pdf">"UrbanSquall" coding standards</a>. Those are basically what I stick to except for the few additions / changes mentioned below.</p>
<p>So let's get started.</p>
<h3><span style="color: #ff0000;">Class properties / Members</span></h3>
<p><strong>Public</strong><br />
The idea here is to always avoid using getter/setter functions whenever possible. Well, atleast for anything that would be called once or more each frame. If it's an obscure variable that is rarely called or used for something that isn't speed related you can use them...otherwise NO. Anything that is both gettable/settable will be simply written as it is:</p>
<pre class="actionscript"><span style="color: #808080; font-style: italic;">//it probably wouldn't matter too much if you externally modified this variable</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> maxSpeed:<span style="color: #0066CC;">Number</span>;</pre>
<p><strong>Read-Only</strong><br />
In order to decipher between variables that <em>should</em> only be <strong>read-only</strong> I will use an underscore to define them as follows:</p>
<pre class="actionscript"><span style="color: #808080; font-style: italic;">//obviously you wouldn't want to externally change this variable...</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> _bulletsLeft:<span style="color: #0066CC;">int</span>;</pre>
<p>The speed difference of NOT using getters/setters can be very apparent with something like a "Vector" class where the 'x/y' variables are public. This adds probably 20-30 FPS to a demo with about 2-3000 sprites all doing world bounds wrap checks etc. Just imagine the speed difference when ALL of your code complies with this.</p>
<p>Obviously sometimes we may want to reduce the "_bulletsLeft" safely so in that case create your function "shootGun()" inside the class that holds "_bulletsLeft" rather than implementing some external code to reduce the "_bulletsLeft" variable. (This is more of a proper OO design practice: 'Encapsulate Change')</p>
<p><strong>Private / Protected</strong><br />
For all properties usable only by the class that created them we will use the m_:</p>
<pre class="actionscript"><span style="color: #808080; font-style: italic;">//this helps avoid naming conflicts...which is good!</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> m_beanCounter:<span style="color: #0066CC;">int</span>;
protected <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> m_nextID:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>;</pre>
<h3><span style="color: #ff0000;">Naming Conventions</span></h3>
<p><strong>Booleans</strong><br />
Any boolean properties and functions will always be structured in question format. They are followed by the words: "is, has, can, does":</p>
<pre class="actionscript"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> _isCollidable:<span style="color: #0066CC;">Boolean</span>;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> doesRayIntersectCircle<span style="color: #66cc66;">&#40;</span>rayOrigin:Vector, rayHeading:Vector, circleCenter:Vector, circleRadius:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span><span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">//code }</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> m_hasGun:<span style="color: #0066CC;">Boolean</span>;
protected <span style="color: #000000; font-weight: bold;">var</span> m_canComeToTheParty:<span style="color: #0066CC;">Boolean</span>; <span style="color: #808080; font-style: italic;">// lol</span></pre>
<p><strong>Constants</strong><br />
All constants will be in caps with phrases separated by underscores:</p>
<pre class="actionscript"><span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const HEAVY_ARMOR:<span style="color: #0066CC;">int</span> = 0x000001;
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const WOODEN_SHIELD:<span style="color: #0066CC;">int</span> = 0x000010;
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const SLARGH_FIGHTER:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;slargh_fighter&quot;</span>;
<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const ENEMIES_PER_WAVE:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">15</span>;</pre>
<p><strong>Public Functions / Private Functions</strong><br />
Usually I stick to the "Urbansquall" convention on this however I do not prefix an 'a_' before the parameter names. Sometimes my functions will stray slightly from the "verbNoun" format when parameters are available and instead I will try to complete a sentence with the parameters. In other words I use "verbPreposition(noun)" format:</p>
<pre class="actionscript"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addTo<span style="color: #66cc66;">&#40;</span>vector:Vector<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> wrapAround<span style="color: #66cc66;">&#40;</span>topLeft:Vector,bottomRight:Vector<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> dotOf<span style="color: #66cc66;">&#40;</span>vector:Vector<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span>;</pre>
<p><strong>Event Handler Functions</strong><br />
I will treat event handlers slightly different when naming them. I always name them as if they are happening because of an event (hmm...) Which means basically all of them have "on" preceding them.</p>
<pre class="actionscript">onScriptLoad<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>
onEntityCollision<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:CollisionEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span></pre>
<p>Alright well as far as I can think of those + the urbanSquall link from above are the conventions I stick with. Hopefully you decide to do the same! Also be sure to read: <a href="http://cheezeworld.com/better-debug-tracing/">Better Debug Tracing</a> for some tracing conventions that should be followed as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://cheezeworld.com/coding-standards/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Actionscript 3 Math Classes for Game Developers</title>
		<link>http://cheezeworld.com/actionscript-3-math-classes-for-game-developers/</link>
		<comments>http://cheezeworld.com/actionscript-3-math-classes-for-game-developers/#comments</comments>
		<pubDate>Sun, 01 Jun 2008 14:28:52 +0000</pubDate>
		<dc:creator>Colby Cheeze</dc:creator>
		
		<category><![CDATA[Game Library]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Actionscript]]></category>

		<category><![CDATA[classes]]></category>

		<category><![CDATA[game]]></category>

		<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://cheezeworld.com/?p=42</guid>
		<description><![CDATA[As I have been teaching myself game programming, one of the harder parts has been the math involved. It can be quite complex depending on what you are trying to do. While building various parts for my game engine I've needed several math functions. I've read through a couple of game and math books and [...]]]></description>
			<content:encoded><![CDATA[<p>As I have been teaching myself game programming, one of the harder parts has been the math involved. It can be quite complex depending on what you are trying to do. While building various parts for my game engine I've needed several math functions. I've read through a couple of game and math books and have also created quite a few extras just based on what I had learned. I have created a pretty good library of useful functions and so after showing a friend of mine and him remarking that it was quite helpful I decided I would go ahead and release the code for everyone else to use!</p>
<p>I currently don't really have any demos or anything showing how to use the code, however go ahead and take a browse through the functions and there may be some stuff you will use eventually. It's pretty self explanatory anyways and it is all documented. I will definitely be referring to a lot of the code from these classes in some upcoming posts as well so if you are waiting for a more detailed explanation of when and how to use some of it don't worry it's on the way!</p>
<p>You can download everything as a package or just get the classes you need in the repository from my google project page here: <a title="http://code.google.com/p/cheezeworld/" href="http://code.google.com/p/cheezeworld/" target="_blank">http://code.google.com/p/cheezeworld/</a></p>
<h3><span style="color: #ff0000;">As of writing this I currently have:</span></h3>
<p><strong>Vector </strong>- Perfect alternative to using the built in "Point" class and has basically ALL of the Vector operations you would need to perform plus a few more.</p>
<p><strong>AABBox </strong>- A very lightweight object to simply store "rect" data for whatever purpose.</p>
<p><strong>Matrix2D </strong>- Handles any Matrix math needed. Use in conjunction with the Vector class.</p>
<p><strong>Transformations </strong>- Some static functions for performing transformations to Vectors easily (such as local to global etc...)</p>
<p><strong>Geometry </strong>- A very powerful bunch of static functions for doing a wide range of math such as line intersection tests between rays, segments, polygons, circles, etc etc... This is great for most hit test operations and ray casting + other stuff...just check it out.</p>
<p><strong>Math Utils </strong>- This is pretty much just a small number of things that I actually just usually copy directly into the code I am working on or as a private function into a class that needs it but wanted to have a reference to it since they are useful so it's all bundled up in this class.</p>
]]></content:encoded>
			<wfw:commentRss>http://cheezeworld.com/actionscript-3-math-classes-for-game-developers/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Google Code Sharing Project Created</title>
		<link>http://cheezeworld.com/google-code-sharing-project-created/</link>
		<comments>http://cheezeworld.com/google-code-sharing-project-created/#comments</comments>
		<pubDate>Sat, 31 May 2008 19:15:05 +0000</pubDate>
		<dc:creator>Colby Cheeze</dc:creator>
		
		<category><![CDATA[Game Library]]></category>

		<category><![CDATA[News]]></category>

		<category><![CDATA[code sharing]]></category>

		<category><![CDATA[Google]]></category>

		<category><![CDATA[Library]]></category>

		<category><![CDATA[repository]]></category>

		<guid isPermaLink="false">http://cheezeworld.com/?p=40</guid>
		<description><![CDATA[Now that I will soon be releasing much more code and files I decided to go ahead and set up a google project page. You can set up a "read-only" repository to download all of my code as it is updated and added to or download the code as I post it in the packages [...]]]></description>
			<content:encoded><![CDATA[<p>Now that I will soon be releasing much more code and files I decided to go ahead and set up a google project page. You can set up a "read-only" repository to download all of my code as it is updated and added to or download the code as I post it in the packages with the demos / tutorials.</p>
<p>Check it out here: http://code.google.com/p/cheezeworld/</p>
<p>If you would like to contribute some code or a helpful tutorial etc I'd be happy to add it to the project!</p>
]]></content:encoded>
			<wfw:commentRss>http://cheezeworld.com/google-code-sharing-project-created/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
