<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Avoider Game . com</title>
	
	<link>http://avoidergame.com</link>
	<description>Learn to make Flash games with these simple tutorials</description>
	<lastBuildDate>Tue, 29 Dec 2009 01:10:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/AvoiderGame" /><feedburner:info uri="avoidergame" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>AvoiderGame</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Pigeon and Pigeonette: Flying Time [AS3 Game]</title>
		<link>http://feedproxy.google.com/~r/AvoiderGame/~3/YldJksy20pA/</link>
		<comments>http://avoidergame.com/2009/09/03/pigeon-and-pigeonette/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 14:20:09 +0000</pubDate>
		<dc:creator>MichaelJW</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[User Contributions]]></category>
		<category><![CDATA[dirk derom]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[pigeon and pigeonette]]></category>

		<guid isPermaLink="false">http://avoidergame.com/?p=487</guid>
		<description><![CDATA[Dirk Derom and Sarah Verroken have written a children&#8217;s book called Pigeon and Pigeonette. It&#8217;s for 3-6 year olds, and it&#8217;s about two pigeons: one who is very large and blind, and another who is small, with wings that can&#8217;t carry her. To promote the book, Dirk and Sarah put together an avoider game based [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_489" class="wp-caption aligncenter" style="width: 365px"><a href="http://www.pigeonandpigeonette.com/"><img src="http://avoidergame.com/wp-content/uploads/2009/09/FlyingTime.png" alt="Click to visit Pigeon and Pigeonette" title="Flying Time" width="355" height="295" class="size-full wp-image-489" /></a><p class="wp-caption-text">Click to visit Pigeon and Pigeonette</p></div>
<p><strong><em>Dirk Derom</em></strong> and <a href="http://www.sarahverroken.com/">Sarah Verroken</a> have written a children&#8217;s book called <a href="http://www.pigeonandpigeonette.com/">Pigeon and Pigeonette</a>. It&#8217;s for 3-6 year olds, and it&#8217;s about two pigeons: one who is very large and blind, and another who is small, with wings that can&#8217;t carry her.</p>
<p>To promote the book, Dirk and Sarah put together an avoider game based on the <a href="http://gamedev.michaeljameswilliams.com/as3-avoider-game-tutorial-base/">AS3 base tutorial</a>, but using their characters and Sarah&#8217;s wonderful style of illustration.</p>
<p>You can check it out at <a href="http://www.pigeonandpigeonette.com/">the book&#8217;s website</a> (head to the Games section) &#8212; bear in mind that it&#8217;s designed for kids, so those of you with millions of badges on Kongregate are unlikely to find it much of a challenge!</p>
<img src="http://feeds.feedburner.com/~r/AvoiderGame/~4/YldJksy20pA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://avoidergame.com/2009/09/03/pigeon-and-pigeonette/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://avoidergame.com/2009/09/03/pigeon-and-pigeonette/</feedburner:origLink></item>
		<item>
		<title>Robot Saga: Escape [AS3 Game]</title>
		<link>http://feedproxy.google.com/~r/AvoiderGame/~3/MtPzAXFVI9A/</link>
		<comments>http://avoidergame.com/2009/08/02/robot-saga-escape-as3-game/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 11:02:02 +0000</pubDate>
		<dc:creator>MichaelJW</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[User Contributions]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[Matthew Ammann]]></category>
		<category><![CDATA[Robot Saga]]></category>

		<guid isPermaLink="false">http://avoidergame.com/?p=479</guid>
		<description><![CDATA[Robot Saga: Escape, a Flash game by Matthew Ammann, based on this site's tutorials.]]></description>
			<content:encoded><![CDATA[<div id="attachment_480" class="wp-caption aligncenter" style="width: 366px"><a href="http://www.kongregate.com/games/musicdemon/robot-saga-escape"><img src="http://avoidergame.com/wp-content/uploads/2009/08/snapshot.png" alt="Click to play Robot Saga: Escape" title="Robot Saga Escape" width="356" height="230" class="size-full wp-image-480" /></a><p class="wp-caption-text">Click to play Robot Saga: Escape</p></div>
<p><em><strong>Matthew Ammann</strong></em> &#8212; who wrote the previously-mentioned <a href="http://avoidergame.com/2009/08/01/as3-soundobject/">SoundObject class</a> &#8212; has written a game called <a href="http://www.kongregate.com/games/musicdemon/robot-saga-escape">Robot Saga: Escape</a>.</p>
<p>It&#8217;s based on the AS3 version of the <a href="http://gamedev.michaeljameswilliams.com/as3-avoider-game-tutorial-base/">Flash avoider game tutorial</a>, and is the first AS3 game Matthew&#8217;s made. He&#8217;s uploaded some <a href="http://matthewammann.com/2009/07/16/inside-robot-saga-escape/">development notes</a> on his blog, which I found pretty interesting <img src='http://avoidergame.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Upon release it was also the <a href="http://matthewammann.com/2009/07/28/robot-saga-big-hit-on-big-fish-games/">tenth most popular game</a> on all of Big Fish Games &#8212; congratulations!</p>
<p><a href="http://www.kongregate.com/games/musicdemon/robot-saga-escape">Click here to play Robot Saga: Escape</a>.</p>
<img src="http://feeds.feedburner.com/~r/AvoiderGame/~4/MtPzAXFVI9A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://avoidergame.com/2009/08/02/robot-saga-escape-as3-game/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://avoidergame.com/2009/08/02/robot-saga-escape-as3-game/</feedburner:origLink></item>
		<item>
		<title>AS3: SoundObject, a Class for Managing Sounds</title>
		<link>http://feedproxy.google.com/~r/AvoiderGame/~3/q4fDEdjh5ZM/</link>
		<comments>http://avoidergame.com/2009/08/01/as3-soundobject/#comments</comments>
		<pubDate>Sat, 01 Aug 2009 18:24:46 +0000</pubDate>
		<dc:creator>MichaelJW</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[User Contributions]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[AvoiderGame]]></category>
		<category><![CDATA[Matthew Ammann]]></category>
		<category><![CDATA[music]]></category>
		<category><![CDATA[mute]]></category>
		<category><![CDATA[sfx]]></category>
		<category><![CDATA[sound]]></category>
		<category><![CDATA[sound object]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[useful classes]]></category>

		<guid isPermaLink="false">http://avoidergame.com/?p=473</guid>
		<description><![CDATA[Matthew Ammann has written a tutorial explaining how to write a separate class to handle all your game's sounds and music.]]></description>
			<content:encoded><![CDATA[<p>When <a href="http://matthewammann.com/">Matthew Ammann</a> was following the <a href="http://gamedev.michaeljameswilliams.com/as3-avoider-game-tutorial-base/">base AS3 tutorial</a>, he wrote a new class, <code>SoundObject</code>, to manage all the sounds inside his game.</p>
<p>He&#8217;s posted this class <a href="http://matthewammann.com/2009/07/24/soundobject-class-tutorial-as3/">on his blog</a> so that everyone can use it &#8212; and on top of that, he&#8217;s written <a href="http://matthewammann.com/2009/07/24/soundobject-class-tutorial-as3/">a great tutorial</a> to explain how it all works!</p>
<p>This makes it easy to mute songs, and switch between different tracks from different screens.</p>
<p><a href="http://matthewammann.com/2009/07/24/soundobject-class-tutorial-as3/">Check it out here</a>. Thanks, Matthew!</p>
<img src="http://feeds.feedburner.com/~r/AvoiderGame/~4/q4fDEdjh5ZM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://avoidergame.com/2009/08/01/as3-soundobject/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://avoidergame.com/2009/08/01/as3-soundobject/</feedburner:origLink></item>
		<item>
		<title>Wesley: A Game Based on the AS3 Tutorial</title>
		<link>http://feedproxy.google.com/~r/AvoiderGame/~3/nH8Dwsaavec/</link>
		<comments>http://avoidergame.com/2009/07/26/wesley-by-bram-van-damme/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 00:45:31 +0000</pubDate>
		<dc:creator>MichaelJW</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[User Contributions]]></category>
		<category><![CDATA[Bram Van Damme]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[Wesley]]></category>

		<guid isPermaLink="false">http://avoidergame.com/?p=465</guid>
		<description><![CDATA[Bram Van Damme has written a game about a man, a pizza and a whole bunch of rhinos. He made it for a Belgian magazine called Humo, which runs (or used to run) a comic strip about this guy Wesley. Now, I don&#8217;t spreak Dutch, but Bram translated one of the strips for me. It [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_466" class="wp-caption aligncenter" style="width: 429px"><a href="http://www.humo.be/tws/kabouter-wesley/computerspel.html"><img src="http://avoidergame.com/wp-content/uploads/2009/07/WesleyPreview.png" alt="Click to play Wesley" title="WesleyPreview" width="419" height="261" class="size-full wp-image-466" /></a><p class="wp-caption-text">Click to play Wesley</p></div>
<p><em><strong>Bram Van Damme</strong></em> has written a game about a man, a pizza and a whole bunch of rhinos.</p>
<p>He made it for a Belgian magazine called Humo, which runs (or used to run) <a href="http://www.humo.be/tws/kabouter-wesley/strips.html">a comic strip about this guy Wesley</a>. Now, I don&#8217;t spreak Dutch, but Bram translated one of the strips for me. It seems Wesley ordered a pizza, but was delivered a rhino instead. He phones the pizza guy, who apologises, and sends along another pizza. Except when it arrives &#8212; uh oh, it&#8217;s another rhino! And the situation escalates, of course. Eventually the rhinos drink some cola, which solves the problem in a sense, because naturally cola causes rhinos to explode (a fact I did not know previously).</p>
<p>The game pits Wesley against a whole horde of rhinos, trying to stop them stealing all his pizza by throwing cola bottles. It sounds a little silly (it IS a little silly) but it&#8217;s actually great fun.</p>
<p>I got to see this game develop from the start, which was really cool. Bram added in the walk-cycles and cola-throwing before I&#8217;d even written the <a href="http://gamedev.michaeljameswilliams.com/2009/06/03/basic-animation-as3-divided-timeline/">animation</a> and <a href="http://gamedev.michaeljameswilliams.com/2009/05/20/avoider-game-shmup/">shoot-&#8217;em-up</a> tutorials!</p>
<p><a href="http://www.humo.be/tws/kabouter-wesley/computerspel.html">Play the game here</a>, and leave a comment to let Bram know what you think <img src='http://avoidergame.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/AvoiderGame/~4/nH8Dwsaavec" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://avoidergame.com/2009/07/26/wesley-by-bram-van-damme/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://avoidergame.com/2009/07/26/wesley-by-bram-van-damme/</feedburner:origLink></item>
		<item>
		<title>Small Additions: Win the game based on score</title>
		<link>http://feedproxy.google.com/~r/AvoiderGame/~3/NyAslbMO_nc/</link>
		<comments>http://avoidergame.com/2009/07/23/win-the-game-based-on-score/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 22:42:49 +0000</pubDate>
		<dc:creator>rescue86k</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[User Contributions]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[avoider game]]></category>
		<category><![CDATA[Counter]]></category>
		<category><![CDATA[score]]></category>
		<category><![CDATA[winning conditions]]></category>

		<guid isPermaLink="false">http://avoidergame.com/?p=441</guid>
		<description><![CDATA[By rescue86k The Counter class: If you completed the 12 part base series, then you know what .as this is. I use the Counter class to show my hero&#8217;s health and ammo. I found the class lacking a few basic functions so I added them. Here&#8217;s the original class: ?View Code ACTIONSCRIPT31 2 3 4 [...]]]></description>
			<content:encoded><![CDATA[<p><strong><em>By rescue86k</em></strong></p>
<p>The <em>Counter</em> class: If you completed the <a href="http://gamedev.michaeljameswilliams.com/as3-avoider-game-tutorial-base/">12 part base series</a>, then you know what .as this is. I use the Counter class to show my hero&#8217;s health and ammo.</p>
<p>I found the class lacking a few basic functions so I added them. </p>
<p><span id="more-441"></span></p>
<p>Here&#8217;s the original class:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p441code4'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4414"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code" id="p441code4"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
   <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=movieclip%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:movieclip.html"><span style="color: #004993;">MovieClip</span></a><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Counter <span style="color: #0033ff; font-weight: bold;">extends</span> <a href="http://www.google.com/search?q=movieclip%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:movieclip.html"><span style="color: #004993;">MovieClip</span></a>
   <span style="color: #000000;">&#123;</span>
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> currentValue<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000066; font-weight: bold;">;</span>
      
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Counter<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
      <span style="color: #000000;">&#123;</span>
         <span style="color: #004993;">reset</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
      
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> addToValue<span style="color: #000000;">&#40;</span> amountToAdd<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
      <span style="color: #000000;">&#123;</span>
         currentValue = currentValue <span style="color: #000066; font-weight: bold;">+</span> amountToAdd<span style="color: #000066; font-weight: bold;">;</span>
         updateDisplay<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
      
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> setValue<span style="color: #000000;">&#40;</span> amount<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
      <span style="color: #000000;">&#123;</span>
         currentValue = amount<span style="color: #000066; font-weight: bold;">;</span>
         updateDisplay<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
      
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">reset</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
      <span style="color: #000000;">&#123;</span>
         currentValue = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
         updateDisplay<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
      
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> updateDisplay<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
      <span style="color: #000000;">&#123;</span>
         
      <span style="color: #000000;">&#125;</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>The new one&#8217;s here:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p441code5'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4415"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code" id="p441code5"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
   <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=movieclip%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:movieclip.html"><span style="color: #004993;">MovieClip</span></a><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Counter <span style="color: #0033ff; font-weight: bold;">extends</span> <a href="http://www.google.com/search?q=movieclip%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:movieclip.html"><span style="color: #004993;">MovieClip</span></a> <span style="color: #000000;">&#123;</span>
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> currentValue<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Counter<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
         <span style="color: #004993;">reset</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
      <span style="color: #000000;">&#125;</span>
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> addToValue<span style="color: #000000;">&#40;</span> amountToAdd<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
         currentValue = currentValue <span style="color: #000066; font-weight: bold;">+</span> amountToAdd<span style="color: #000066; font-weight: bold;">;</span>
         updateDisplay<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
      <span style="color: #000000;">&#125;</span>
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> removeToValue<span style="color: #000000;">&#40;</span> amountToremove<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
         currentValue = currentValue <span style="color: #000066; font-weight: bold;">-</span> amountToremove<span style="color: #000066; font-weight: bold;">;</span>
         updateDisplay<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
      <span style="color: #000000;">&#125;</span>
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">reset</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
         currentValue = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
         updateDisplay<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
      <span style="color: #000000;">&#125;</span>
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> updateDisplay<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
      <span style="color: #000000;">&#125;</span>
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> setValue<span style="color: #000000;">&#40;</span> amount<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
         currentValue = amount<span style="color: #000066; font-weight: bold;">;</span>
         updateDisplay<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> CurrentValue<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> <span style="color: #000000;">&#123;</span>
         <span style="color: #0033ff; font-weight: bold;">return</span> currentValue<span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>So I added the functions CurrentValue(), and removeToValue():</p>
<ul>
<li>removeToValue- used to remove X amount from &#8220;Score&#8221; for example.</li>
<li>CurrentValue- returns the current value of the subclass(such as gameScore in avoider game)</li>
</ul>
<p>Example use for CurrentValue():</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p441code6'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4416"><td class="code" id="p441code6"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>gameScore<span style="color: #000066; font-weight: bold;">.</span>CurrentValue <span style="color: #000066; font-weight: bold;">&gt;</span>= <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
<span style="color: #009900; font-style: italic;">//You win the game! (if goal was to score 100 pts)</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Put this code in your avoidergame.as.</p>
<p>Keep in mind my game is way past the original version of avoidergame, so if the code puts out some funny errors such as &#8220;Can&#8217;t find the  method/ or property of a null object reference&#8221; then dig in deep into the heart of OOP. I mean spend time understanding how to correctly reference objects. Is gameScore defined as a variable in your .as?  Is it a child of that class? Learn your game and how you built it. <img src='http://avoidergame.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/AvoiderGame/~4/NyAslbMO_nc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://avoidergame.com/2009/07/23/win-the-game-based-on-score/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://avoidergame.com/2009/07/23/win-the-game-based-on-score/</feedburner:origLink></item>
		<item>
		<title>Performance of Nested Loops in Bigger Games</title>
		<link>http://feedproxy.google.com/~r/AvoiderGame/~3/C_B3ATKIg6s/</link>
		<comments>http://avoidergame.com/2009/07/23/nested-arrays-performance/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 23:31:39 +0000</pubDate>
		<dc:creator>rescue86k</dc:creator>
				<category><![CDATA[General Game Development]]></category>
		<category><![CDATA[User Contributions]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[efficiency]]></category>
		<category><![CDATA[fps]]></category>
		<category><![CDATA[lag]]></category>
		<category><![CDATA[loops]]></category>
		<category><![CDATA[nesting]]></category>
		<category><![CDATA[optimisation]]></category>
		<category><![CDATA[rescue86k]]></category>

		<guid isPermaLink="false">http://avoidergame.com/?p=444</guid>
		<description><![CDATA[By rescue86k So my game is getting bigger, and keeping on top of lag is a high priority. Saying that I run the fps at 50, I never want it to go bellow a certain amount (such as 30, for a full blown battle, or 45 if only 2-3 objects/NPCs moving around). Considering a big [...]]]></description>
			<content:encoded><![CDATA[<p><strong><em>By rescue86k</em></strong></p>
<p>So my game is getting bigger, and keeping on top of lag is a high priority. Saying that I run the fps at 50, I never want it to go bellow a certain amount (such as 30, for a full blown battle, or 45 if only 2-3 objects/NPCs moving around).</p>
<p>Considering a big game, such as your own, you found arrays to be quite helpful. In my game, I have an enemy array (<code>enemies</code>) that checks hitTest() for each wall in the second array (<code>walls</code>) using a <em>nested loop</em>, presented in <a href="http://gamedev.michaeljameswilliams.com/as3-avoider-game-tutorial-base/">the base Avoider Game Tutorial</a>. I assume you have completed that series, and you know what a nested loop is so I wont go into explaining it if you don&#8217;t mind.</p>
<p>I&#8217;m about to add a third array (<code>allies</code>) which will include the avatar in it. Problem with performance is this:</p>
<p>if currently you have <code>enemies</code> with nested <code>walls</code>, then you have that code being checked X times like so: </p>
<p>enemies[# of arguments]  *  walls[# of arguments] = amount of hitTest checks.</p>
<p>Follow me?</p>
<p><span id="more-444"></span></p>
<p>So if there are 3 enemies in the <code>enemies</code> array, and 5 walls in the <code>walls</code> array, then the total number of checks would be:</p>
<p>3*5= 15</p>
<p>thus 15 times the code went through. Ok not bad. Lets add my <code>allies</code> array&#8217;s loop now by nesting it in the <code>walls</code> array&#8217;s loop.</p>
<p>enemies[# of arguments]  *  walls[# of arguments] *  allies[# of arguments] = amount of hitTest() checks.</p>
<p>There are three allies, the first argument is the avatar, the second two are your buddies fighting with you. So</p>
<p>3*5*3= 15*3, then 15*3 = 45</p>
<p>45 checks! 3 times as much strain put on flash player! Answer is low fps,  (regarding my game). What do we do?</p>
<p>Well I need each enemy and ally to recognize hitTests between each other as well as walls. Try this:</p>
<p>enemies[# of arguments]  *  allies[# of arguments] = subtotal1 amount of hitTest checks.</p>
<p>enemies[# of arguments]  *  walls[# of arguments] = subtotal2 amount of hitTest checks.</p>
<p>allies[# of arguments]  *  walls[# of arguments] = subtotal3 amount of hitTest checks.</p>
<p>subtotal1 + subtotal2 + subtotal3 = amount of hitTest checks.</p>
<p>so</p>
<p>3*3=9;</p>
<p>3*5=15;</p>
<p>3*5=15;</p>
<p>9+15+15=39;</p>
<p>39 sounds better than 45 <img src='http://avoidergame.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Why is this such a big deal? Well the answer is everything you do to your game should be a big deal if you plan on having a big game. If you could cut out every &#8220;fee&#8221; you got in life for a year, such as $2 for an ATM transaction, would it add up? Games work the same way. Down to the graphics. So now lets suppose you have:</p>
<p>20 walls, 2 enemies, and 1 ally (the avatar with no buddies in current level). Would the checking work the same? Save you a few checks, like 6 last time? Lets find out:</p>
<p>The old way (allies nested in enemies, walls nested in allies):</p>
<p>2*1*20=40</p>
<p>The new way(allies nested in enemies, walls nested in allies, walls nested in enemies)</p>
<p>2*1=2</p>
<p>2*20=40</p>
<p>1*20=20</p>
<p>2+40+20= 62 </p>
<p>What? The old way was better this time. I guess this goes to show that you really need to pay attention to how many loops you have, and how many checks are going through with your current setup. If anyone has a more efficient way of doing this, please let me know.  </p>
<p>Any questions?</p>
<img src="http://feeds.feedburner.com/~r/AvoiderGame/~4/C_B3ATKIg6s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://avoidergame.com/2009/07/23/nested-arrays-performance/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://avoidergame.com/2009/07/23/nested-arrays-performance/</feedburner:origLink></item>
		<item>
		<title>Avoider game tutorial – Moving with mouse and using speed</title>
		<link>http://feedproxy.google.com/~r/AvoiderGame/~3/KtVMEAt1ntE/</link>
		<comments>http://avoidergame.com/2009/06/29/as3-mouse-follow-constant-speed/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 18:52:38 +0000</pubDate>
		<dc:creator>DanielSidhion</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[AvoiderGame.com]]></category>
		<category><![CDATA[User Contributions]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[AvoiderGame]]></category>
		<category><![CDATA[constant speed]]></category>
		<category><![CDATA[DanielSidhion]]></category>
		<category><![CDATA[mouse]]></category>
		<category><![CDATA[mouse follow]]></category>
		<category><![CDATA[movement]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://avoidergame.com/?p=366</guid>
		<description><![CDATA[<script type="text/javascript" src="http://avoidergame.com/wp-includes/js/jquery/jquery.js"></script><script type="text/javascript" src="http://avoidergame.com/wp-content/plugins/pb-embedflash/js/sbadapter/shadowbox-jquery.js"></script><script type="text/javascript" src="http://avoidergame.com/wp-content/plugins/pb-embedflash/js/shadowbox.js"></script><script type="text/javascript"><!--
window.onload = function() {var options ={assetURL:'',loadingImage:'http://avoidergame.com/wp-content/plugins/pb-embedflash/css/images/loading.gif',flvPlayer:'http://avoidergame.com/wp-content/plugins/pb-embedflash/swf/mediaplayer.swf',animate:true,animSequence:'wh',overlayColor:'#000',overlayOpacity:0.85,overlayBgImage:'http://avoidergame.com/wp-content/plugins/pb-embedflash/css/images/overlay-85.png',listenOverlay:true,autoplayMovies:true,showMovieControls:true,resizeDuration:0.35,fadeDuration:0.35,displayNav:true,continuous:false,displayCounter:true,counterType:'default',viewportPadding:20,handleLgImages:'resize',initialHeight:160,initialWidth:320,enableKeys:true,keysClose:['c', 'q', 27],keysPrev:['p', 37],keysNext:['n', 39],handleUnsupported:'',text: {cancel:'Cancel',loading: 'loading',close:'<span class="shortcut">C</span>lose',next:'<span class="shortcut">N</span>ext',prev:'<span class="shortcut">P</span>revious',errors:{single: 'You must install the <a href="{0}">{1}</a> browser plugin to view this content.',shared: 'You must install both the <a href="{0}">{1}</a> and <a href="{2}">{3}</a> browser plugins to view this content.',either: 'You must install either the <a href="{0}">{1}</a> or the <a href="{2}">{3}</a> browser plugin to view this content.'}}};Shadowbox.init(options);}
--></script>In a previous tutorial from Michael James Williams (MJW), you could move the skull with the mouse and aim with the keyboard. In this tutorial we will make the mouse movement a bit complex, but you will not be able to shoot. (Please open the article to see the flash file or player.) I am [...]]]></description>
			<content:encoded><![CDATA[<p>In a <a href="http://gamedev.michaeljameswilliams.com/2009/05/28/move-with-the-mouse-aim-with-the-keyboard/" target="_blank">previous tutorial from Michael James Williams</a> (MJW), you could move the skull with the mouse and aim with the keyboard. In this tutorial we will make the mouse movement a bit complex, but you will not be able to shoot.</p>
<p><small>(Please open the article to see the flash file or player.)</small></p>
<p><span id="more-366"></span></p>
<p>I am using the files from <a href="http://gamedev.michaeljameswilliams.com/2009/03/25/avoider-game-tutorial-12/" target="_blank">MJW&#8217;s final part of AS3 conversion of Frozen Haddock&#8217;s avoider game tutorial</a>. If you do not have the files to follow the tutorial, you can grab them <a href="http://gamedev.michaeljameswilliams.com/downloads/tutorials/AvoiderGame/part12/AvoiderGame-part12.zip" target="_blank">here</a>.</p>
<h2><strong>Move with the mouse</strong></h2>
<p>Since we will start using the mouse, we do not need the keyboard verification functions and variables. I would comment all lines, but MJW made it simple with the <strong>useMouseControl</strong> variable. All we need to do is set it to true. Open AvoiderGame.as:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p366code17'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36617"><td class="code" id="p366code17"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> AvoiderGame<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	currentLevelData = <span style="color: #0033ff; font-weight: bold;">new</span> LevelData<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	setBackgroundImage<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	backgroundMusic = <span style="color: #0033ff; font-weight: bold;">new</span> BackgroundMusic<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	bgmSoundChannel = backgroundMusic<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">play</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	bgmSoundChannel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">SOUND_COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> onBackgroundMusicFinished<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	enemyAppearSound = <span style="color: #0033ff; font-weight: bold;">new</span> EnemyAppearSound<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	downKeyIsBeingPressed = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
	upKeyIsBeingPressed = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
	leftKeyIsBeingPressed = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
	rightKeyIsBeingPressed = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	useMouseControl = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
	<a href="http://www.google.com/search?q=mouse%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:mouse.html"><span style="color: #004993;">Mouse</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">hide</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	army = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	avatar = <span style="color: #0033ff; font-weight: bold;">new</span> Avatar<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span> avatar <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> useMouseControl <span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #004993;">mouseX</span><span style="color: #000066; font-weight: bold;">;</span>
		avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #004993;">mouseY</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0033ff; font-weight: bold;">else</span>
	<span style="color: #000000;">&#123;</span>
		avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">;</span>
		avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">250</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	gameTimer = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=timer%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:timer.html"><span style="color: #004993;">Timer</span></a><span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">25</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	gameTimer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <a href="http://www.google.com/search?q=timerevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:timerevent.html"><span style="color: #004993;">TimerEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TIMER</span><span style="color: #000066; font-weight: bold;">,</span> onTick<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	gameTimer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ADDED_TO_STAGE</span><span style="color: #000066; font-weight: bold;">,</span> onAddToStage<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>I changed <strong>useMouseControl</strong> to true. Now we have the mouse movement working! Check it:</p>
<p><small>(Please open the article to see the flash file or player.)</small></p>
<h2>Adding speed</h2>
<p>When you play the game, you may find it easy, since the skull is placed where your mouse is, every frame. We need a harder game, so let&#8217;s put a fixed speed to the skull!</p>
<p>If we check the <strong>onTick</strong> function of AvoiderGame.as, we can see why the skull moves so fast:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p366code18'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36618"><td class="code" id="p366code18"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> useMouseControl <span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #004993;">mouseX</span><span style="color: #000066; font-weight: bold;">;</span>
	avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #004993;">mouseY</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>This code only places the skull where our mouse is located, so we have to modify it.</p>
<p>Our skull needs to move in the horizontal and in the vertical, using a fixed speed. To do it, we need to know where our mouse is located and what is the angle between them. The reason for the angle will be explained later.</p>
<p>If we take a look into Avatar.as file, we can see only the <strong>moveABit</strong> function. We could change it to meet our needs, but instead of that, we will create a new function. Now, <strong>moveABit</strong> can still be used with the keyboard movement, in case you want to switch from mouse to keyboard and vice versa.</p>
<p>Let&#8217;s create the <strong>moveWithMouse</strong> function:</p>
<p>Avatar.as file:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p366code19'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36619"><td class="code" id="p366code19"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=movieclip%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:movieclip.html"><span style="color: #004993;">MovieClip</span></a><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Avatar <span style="color: #0033ff; font-weight: bold;">extends</span> <a href="http://www.google.com/search?q=movieclip%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:movieclip.html"><span style="color: #004993;">MovieClip</span></a>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Avatar<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> moveABit<span style="color: #000000;">&#40;</span> xDistance<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000066; font-weight: bold;">,</span> yDistance<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> baseSpeed<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> = <span style="color: #000000; font-weight:bold;">3</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #000000;">&#40;</span> xDistance <span style="color: #000066; font-weight: bold;">*</span> baseSpeed <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #000000;">&#40;</span> yDistance <span style="color: #000066; font-weight: bold;">*</span> baseSpeed <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> moveWithMouse<span style="color: #000000;">&#40;</span> angleBetween<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>We need a speed variable to control our movement. Instead of creating one, I will turn the <strong>baseSpeed</strong> variable from <strong>moveABit</strong> into a class-level variable. Here is how I did it:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p366code20'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36620"><td class="code" id="p366code20"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=movieclip%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:movieclip.html"><span style="color: #004993;">MovieClip</span></a><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Avatar <span style="color: #0033ff; font-weight: bold;">extends</span> <a href="http://www.google.com/search?q=movieclip%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:movieclip.html"><span style="color: #004993;">MovieClip</span></a>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> baseSpeed<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Avatar<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			baseSpeed = <span style="color: #000000; font-weight:bold;">3</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> moveABit<span style="color: #000000;">&#40;</span> xDistance<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000066; font-weight: bold;">,</span> yDistance<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #000000;">&#40;</span> xDistance <span style="color: #000066; font-weight: bold;">*</span> baseSpeed <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #000000;">&#40;</span> yDistance <span style="color: #000066; font-weight: bold;">*</span> baseSpeed <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> moveWithMouse<span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>The line 13 was removed, and <strong>baseSpeed</strong> is now a private variable.</p>
<p>As I said before, we need the angle between the skull and the mouse. We will calculate it into AvoiderGame.as and pass it as a parameter with a call to <strong>moveWithMouse</strong>. So let&#8217;s go back to <strong>onTick</strong> function of AvoiderGame.as.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p366code21'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36621"><td class="code" id="p366code21"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> useMouseControl <span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #004993;">mouseX</span><span style="color: #000066; font-weight: bold;">;</span>
	avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #004993;">mouseY</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>I am removing the code inside that <strong>if</strong> statement, because we don&#8217;t need it.</p>
<p>Before writing any code, I am going to introduce you to <strong>Math.atan2</strong> function. <strong>Math.atan2</strong> computes the angle of a given point (in radians), measured counterclockwise from a circle&#8217;s x axis. The image below contributes to the understanding of the function:</p>
<p><a href="http://avoidergame.com/wp-content/uploads/2009/06/image09.jpg"><img src="http://avoidergame.com/wp-content/uploads/2009/06/image09.jpg" alt="Mathatan2" width="448" height="397" /></a></p>
<p>Now we can start coding the <strong>if</strong> statement:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p366code22'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36622"><td class="code" id="p366code22"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> useMouseControl <span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">angle</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> = <a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">atan2</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">mouseY</span> <span style="color: #000066; font-weight: bold;">-</span> avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">mouseX</span> <span style="color: #000066; font-weight: bold;">-</span> avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	avatar<span style="color: #000066; font-weight: bold;">.</span>moveWithMouse<span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Be careful when using <strong>Math.atan2</strong>: you have to pass first the Y variable, then the X variable. The angle is measured in radians. We do not need to convert it to degrees &#8211; when we use it later, we need the angle in radians.</p>
<p>The reason for why I wrote <strong>(mouseY &#8211; avatar.y)</strong> and <strong>(mouseX &#8211; avatar.x)</strong> is because we are using <strong>avatar.x</strong> and <strong>avatar.y</strong> as the center of our reference circle. We have to decrease <strong>avatar.x</strong> and <strong>avatar.y</strong> of the values to make sure the center of the circle is the (0, 0) point.</p>
<p>We added a parameter to avatar&#8217;s <strong>moveWithMouse</strong> function, so let&#8217;s change it and work on the movement. Switch back to Avatar.as.</p>
<p>I&#8217;m adding the parameter to <strong>moveWithMouse</strong>:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p366code23'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36623"><td class="code" id="p366code23"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> moveWithMouse<span style="color: #000000;">&#40;</span> angleBetween<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Before continuing, I have to talk about the uniform movement. Many of you will remember the physics classes. When something is moving, it has a x position modifier and a y position modifier. The vector resulting from the sum of these two other vectors is the final speed. Look at the image:</p>
<p><a href="http://avoidergame.com/wp-content/uploads/2009/06/image08.jpg"><img src="http://avoidergame.com/wp-content/uploads/2009/06/image08.jpg" alt="VectorSum" width="196" height="129" /></a></p>
<p>Guess what is the angle in the image? Exactly! The angle passed to moveWithMouse function. The Y speed and X speed vectors form an angle of 90º, so you can use sine and cosine to calculate them. The sine of the angle is (Y speed / Final speed), and cosine is (X speed / Final speed). In a better way, <strong>Y speed = Final speed * sine of angle</strong> and <strong>X speed = Final speed * cosine of angle</strong>.</p>
<p>Now, back to <strong>moveWithMouse</strong> function, we will use the two last formulas to make our skull move!</p>
<p>I will create an <strong>xSpeed</strong> and <strong>ySpeed</strong> variable, so you can easily work with them later.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p366code24'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36624"><td class="code" id="p366code24"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=movieclip%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:movieclip.html"><span style="color: #004993;">MovieClip</span></a><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Avatar <span style="color: #0033ff; font-weight: bold;">extends</span> <a href="http://www.google.com/search?q=movieclip%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:movieclip.html"><span style="color: #004993;">MovieClip</span></a>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> baseSpeed<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> xSpeed<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> ySpeed<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Avatar<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			baseSpeed = <span style="color: #000000; font-weight:bold;">3</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> moveABit<span style="color: #000000;">&#40;</span> xDistance<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000066; font-weight: bold;">,</span> yDistance<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #000000;">&#40;</span> xDistance <span style="color: #000066; font-weight: bold;">*</span> baseSpeed <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #000000;">&#40;</span> yDistance <span style="color: #000066; font-weight: bold;">*</span> baseSpeed <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> moveWithMouse<span style="color: #000000;">&#40;</span> angleBetween<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			xSpeed = <a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span>angleBetween<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> baseSpeed<span style="color: #000066; font-weight: bold;">;</span>
			ySpeed = <a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span>angleBetween<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> baseSpeed<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span>= xSpeed<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">+</span>= ySpeed<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Here is how our game is looking.</p>
<p><small>(Please open the article to see the flash file or player.)</small></p>
<p>If you test the game, we can see it worked, but our mouse is not visible, making the game very hard! Also, when the skull reaches your mouse, it gets shaked. To fix the mouse issue, just change AvoiderGame.as:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p366code25'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36625"><td class="code" id="p366code25"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> AvoiderGame<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	currentLevelData = <span style="color: #0033ff; font-weight: bold;">new</span> LevelData<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	setBackgroundImage<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	backgroundMusic = <span style="color: #0033ff; font-weight: bold;">new</span> BackgroundMusic<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	bgmSoundChannel = backgroundMusic<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">play</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	bgmSoundChannel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">SOUND_COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> onBackgroundMusicFinished<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	enemyAppearSound = <span style="color: #0033ff; font-weight: bold;">new</span> EnemyAppearSound<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	downKeyIsBeingPressed = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
	upKeyIsBeingPressed = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
	leftKeyIsBeingPressed = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
	rightKeyIsBeingPressed = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	useMouseControl = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #009900; font-style: italic;">// Mouse.hide();</span>
	army = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	avatar = <span style="color: #0033ff; font-weight: bold;">new</span> Avatar<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span> avatar <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> useMouseControl <span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #004993;">mouseX</span><span style="color: #000066; font-weight: bold;">;</span>
		avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #004993;">mouseY</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0033ff; font-weight: bold;">else</span>
	<span style="color: #000000;">&#123;</span>
		avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">;</span>
		avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">250</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	gameTimer = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=timer%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:timer.html"><span style="color: #004993;">Timer</span></a><span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">25</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	gameTimer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <a href="http://www.google.com/search?q=timerevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:timerevent.html"><span style="color: #004993;">TimerEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TIMER</span><span style="color: #000066; font-weight: bold;">,</span> onTick<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	gameTimer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ADDED_TO_STAGE</span><span style="color: #000066; font-weight: bold;">,</span> onAddToStage<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>I commented <strong>Mouse.hide()</strong> to make our mouse visible. Now you can see where you are moving.</p>
<p>For the shaking problem, we need to go to the <strong>onTick</strong> function of AvoiderGame.as. It is caused by the delay of the tick. It only asks our avatar to move to a position every tick. Sometimes our avatar exceeds the necessary distance to reach the mouse, and in the next tick it needs to go back, exceeding again the distance. This causes the shaking of our avatar.</p>
<p>Do you remember <a href="http://gamedev.michaeljameswilliams.com/2009/05/08/pythagorean-distance-between-two-points/" target="_blank">this post</a> from MJW? We will use it now to calculate the distance between our mouse and our avatar. If the distance is less than or equal to 3 px, we only place the avatar in the mouse position.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p366code26'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36626"><td class="code" id="p366code26"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> onTick<span style="color: #000000;">&#40;</span> timerEvent<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=timerevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:timerevent.html"><span style="color: #004993;">TimerEvent</span></a> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	gameClock<span style="color: #000066; font-weight: bold;">.</span>addToValue<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">25</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> <a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">&lt;</span> currentLevelData<span style="color: #000066; font-weight: bold;">.</span>enemySpawnRate <span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> randomX<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> = <a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">400</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> newEnemy<span style="color: #000066; font-weight: bold;">:</span>Enemy = <span style="color: #0033ff; font-weight: bold;">new</span> Enemy<span style="color: #000000;">&#40;</span> randomX<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">15</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		army<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span> newEnemy <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span> newEnemy <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		gameScore<span style="color: #000066; font-weight: bold;">.</span>addToValue<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">10</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		sfxSoundChannel = enemyAppearSound<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">play</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> useMouseControl <span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">distance</span> = <a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sqrt</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">mouseX</span> <span style="color: #000066; font-weight: bold;">-</span> avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">mouseX</span> <span style="color: #000066; font-weight: bold;">-</span> avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">mouseY</span> <span style="color: #000066; font-weight: bold;">-</span> avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">mouseY</span> <span style="color: #000066; font-weight: bold;">-</span> avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">distance</span> <span style="color: #000066; font-weight: bold;">&lt;</span>= <span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #004993;">mouseX</span><span style="color: #000066; font-weight: bold;">;</span>
			avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #004993;">mouseY</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">else</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">angle</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> = <a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html"><span style="color: #004993;">Math</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">atan2</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">mouseY</span> <span style="color: #000066; font-weight: bold;">-</span> avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">mouseX</span> <span style="color: #000066; font-weight: bold;">-</span> avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			avatar<span style="color: #000066; font-weight: bold;">.</span>moveWithMouse<span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0033ff; font-weight: bold;">else</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> downKeyIsBeingPressed <span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			avatar<span style="color: #000066; font-weight: bold;">.</span>moveABit<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> upKeyIsBeingPressed <span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			avatar<span style="color: #000066; font-weight: bold;">.</span>moveABit<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> leftKeyIsBeingPressed <span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			avatar<span style="color: #000066; font-weight: bold;">.</span>moveABit<span style="color: #000000;">&#40;</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> rightKeyIsBeingPressed <span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			avatar<span style="color: #000066; font-weight: bold;">.</span>moveABit<span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000000;">&#40;</span> avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight:bold;">400</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000;">&#40;</span> avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">400</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000;">&#40;</span> avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000000;">&#40;</span> avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight:bold;">300</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000;">&#40;</span> avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">300</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000;">&#40;</span> avatar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #6699cc; font-weight: bold;">var</span> avatarHasBeenHit<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> = army<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> enemy<span style="color: #000066; font-weight: bold;">:</span>Enemy<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span> i <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		enemy = army<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
		enemy<span style="color: #000066; font-weight: bold;">.</span>moveABit<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> PixelPerfectCollisionDetection<span style="color: #000066; font-weight: bold;">.</span>isColliding<span style="color: #000000;">&#40;</span> avatar<span style="color: #000066; font-weight: bold;">,</span> enemy<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			gameTimer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			avatarHasBeenHit = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> enemy<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight:bold;">350</span> <span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span> enemy <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			army<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">splice</span><span style="color: #000000;">&#40;</span> i<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		i = i <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> avatarHasBeenHit <span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		bgmSoundChannel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> AvatarEvent<span style="color: #000000;">&#40;</span> AvatarEvent<span style="color: #000066; font-weight: bold;">.</span>DEAD <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> gameScore<span style="color: #000066; font-weight: bold;">.</span>currentValue <span style="color: #000066; font-weight: bold;">&gt;</span>= currentLevelData<span style="color: #000066; font-weight: bold;">.</span>pointsToReachNextLevel <span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		currentLevelData = <span style="color: #0033ff; font-weight: bold;">new</span> LevelData<span style="color: #000000;">&#40;</span> currentLevelData<span style="color: #000066; font-weight: bold;">.</span>levelNum <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		setBackgroundImage<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>I created the variable <strong>distance</strong> and calculated it, checking if it was less than or equal to 3. If true, we placed the avatar in the mouse&#8217;s position. If not, we just asked the avatar to move in the mouse&#8217;s direction. You can see the game now:</p>
<p><small>(Please open the article to see the flash file or player.)</small></p>
<h2>Conclusion</h2>
<p>This was just an introduction to our movement with the mouse. You can make it a lot better, adding acceleration and friction, for example.</p>
<p>You can work with the speed of our avatar, increasing it every level, or create a custom cursor. I will not tell you how to do it &#8211; go try it!</p>
<p>You can grab the final files of the tutorial <a href="http://avoidergame.com/wp-content/uploads/2009/06/avoidergame-with-speed-danielsidhion.zip">here</a>.</p>
<p>Thank you</p>
<img src="http://feeds.feedburner.com/~r/AvoiderGame/~4/KtVMEAt1ntE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://avoidergame.com/2009/06/29/as3-mouse-follow-constant-speed/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://avoidergame.com/2009/06/29/as3-mouse-follow-constant-speed/</feedburner:origLink></item>
		<item>
		<title>AS3: Keyboard Movement, Mouse Shooting</title>
		<link>http://feedproxy.google.com/~r/AvoiderGame/~3/fUHuEcwvs5A/</link>
		<comments>http://avoidergame.com/2009/06/25/as3-mouse-shooting/#comments</comments>
		<pubDate>Thu, 25 Jun 2009 02:05:53 +0000</pubDate>
		<dc:creator>MichaelJW</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[avoider game]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[bullets]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[mouse movement]]></category>
		<category><![CDATA[MouseEvent]]></category>
		<category><![CDATA[pythagorean distance]]></category>
		<category><![CDATA[pythagorus]]></category>
		<category><![CDATA[shmup]]></category>
		<category><![CDATA[shoot-'em-up]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://avoidergame.com/?p=363</guid>
		<description><![CDATA[Learn how to move the avatar with the keyboard while shooting in any direction with the mouse.]]></description>
			<content:encoded><![CDATA[<p><small>(Please open the article to see the flash file or player.)</small> </p>
<p>This tutorial builds on <a href="http://avoidergame.com/2009/05/28/as3-wsad-shooting/">Mouse Movement, Keyboard Shooting</a> &#8212; only this time, you&#8217;ll learn how to do the opposite!</p>
<p><a href="http://gamedev.michaeljameswilliams.com/2009/06/25/move-keyboard-aim-mouse/">Click here</a> to read on&#8230;</p>
<img src="http://feeds.feedburner.com/~r/AvoiderGame/~4/fUHuEcwvs5A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://avoidergame.com/2009/06/25/as3-mouse-shooting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://avoidergame.com/2009/06/25/as3-mouse-shooting/</feedburner:origLink></item>
		<item>
		<title>DinoScape: A Game Based on the AS3 Tutorial</title>
		<link>http://feedproxy.google.com/~r/AvoiderGame/~3/Hx-occ9G8aA/</link>
		<comments>http://avoidergame.com/2009/06/19/dinoscape-by-animassauro/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 18:34:19 +0000</pubDate>
		<dc:creator>MichaelJW</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[User Contributions]]></category>
		<category><![CDATA[animassauro]]></category>
		<category><![CDATA[dinoscape]]></category>
		<category><![CDATA[Game]]></category>

		<guid isPermaLink="false">http://avoidergame.com/?p=359</guid>
		<description><![CDATA[Fabio from Animassauro has put together this awesome game based on the AS3 Avoider Game Tutorial. It&#8217;s called DinoScape; you play as a little green dinosaur trying to fight off eyeless monsters so that you can build a spaceship. Also, your main weapon is a giant HB pencil. Click here to play it. It&#8217;s really [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.animassauro.com/jogo/"><img src="http://avoidergame.com/structure/DinoScape/images/DinoScapeLogo.jpg" alt="DinoScape logo" /></a></p>
<p>Fabio from <a href="http://animassauro.com/">Animassauro</a> has put together this awesome game based on the AS3 Avoider Game Tutorial.</p>
<p>It&#8217;s called DinoScape; you play as a little green dinosaur trying to fight off eyeless monsters so that you can build a spaceship. Also, your main weapon is a giant HB pencil.</p>
<p><a href="http://www.animassauro.com/jogo/">Click here</a> to play it. It&#8217;s really awesome! Not only are the graphics amazing (check out the Animassauro <a href="http://animassauro.com/">showreel</a> for more of this), but the gameplay is very different to the basic avoider game.</p>
<p>Fabio comments that &#8220;it&#8217;s a little game, but for myself, it was a great experience to learn more about game programming and actionscript.&#8221;</p>
<p>Thanks Fabio <img src='http://avoidergame.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/AvoiderGame/~4/Hx-occ9G8aA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://avoidergame.com/2009/06/19/dinoscape-by-animassauro/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://avoidergame.com/2009/06/19/dinoscape-by-animassauro/</feedburner:origLink></item>
		<item>
		<title>AS3: Basic Character Animation, the State MovieClips Approach</title>
		<link>http://feedproxy.google.com/~r/AvoiderGame/~3/mTY3LD5IBXA/</link>
		<comments>http://avoidergame.com/2009/06/18/as3-basic-character-animation-the-state-movieclips-approach/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 03:22:22 +0000</pubDate>
		<dc:creator>MichaelJW</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[avoider game]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[state movieclips]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://avoidergame.com/?p=354</guid>
		<description><![CDATA[(Please open the article to see the flash file or player.) Learn how animate your game&#8217;s characters with the &#8220;divided timeline&#8221; approach. First part of a mini-series. Click here to read on!]]></description>
			<content:encoded><![CDATA[<p><small>(Please open the article to see the flash file or player.)</small></p>
<p>Learn how animate your game&#8217;s characters with the &#8220;divided timeline&#8221; approach. First part of a mini-series.</p>
<p><a href="http://gamedev.michaeljameswilliams.com/2009/06/18/basic-animation-as3-state-movieclips/">Click here</a> to read on!</p>
<img src="http://feeds.feedburner.com/~r/AvoiderGame/~4/mTY3LD5IBXA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://avoidergame.com/2009/06/18/as3-basic-character-animation-the-state-movieclips-approach/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://avoidergame.com/2009/06/18/as3-basic-character-animation-the-state-movieclips-approach/</feedburner:origLink></item>
	</channel>
</rss>
