<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MochiLand &#187; Flash Development</title>
	<atom:link href="http://mochiland.com/category/mochiland/flash/feed" rel="self" type="application/rss+xml" />
	<link>http://mochiland.com</link>
	<description>for(developer in flash_games){ this.mochiland = _root }</description>
	<lastBuildDate>Fri, 18 May 2012 19:04:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Tutorial: Custom Leaderboards With Mochi API (AS3)</title>
		<link>http://mochiland.com/articles/tutorial-custom-leaderboards-with-mochi-api-as3</link>
		<comments>http://mochiland.com/articles/tutorial-custom-leaderboards-with-mochi-api-as3#comments</comments>
		<pubDate>Thu, 29 Mar 2012 17:44:58 +0000</pubDate>
		<dc:creator>uNik</dc:creator>
				<category><![CDATA[Developer Feed]]></category>
		<category><![CDATA[Flash Development]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[MochiLand Topics]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[creation]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[leaderboard]]></category>
		<category><![CDATA[Mochi Scores]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://mochiland.com/?p=6242</guid>
		<description><![CDATA[Hi everyone, I haven&#8217;t found any example how to create a custom leaderboard, so I&#8217;ve decided to create one. I&#8217;m sure that it can be useful for you :) To follow this tutorial, you should be familiar with the information in the Mochi Media docs. With just a little bit of time, we will create [...]]]></description>
			<content:encoded><![CDATA[ <p>Hi everyone,<br />
I haven&#8217;t found any example how to create a custom leaderboard, so I&#8217;ve decided to create one. I&#8217;m sure that it can be useful for you :)<br />
To follow this tutorial, you should be familiar with the information in the <a href="https://www.mochimedia.com/support/dev_docs#The_MochiScores_API">Mochi Media docs</a>.</p>
<p>With just a little bit of time, we will create something like this:</p>
<p><a href="http://mochiland.com/wp-content/uploads/2012/03/pic-1.jpg"><img class="alignleft size-full wp-image-6252" title="Custome Leaderboard" style="border: 0px" src="http://mochiland.com/wp-content/uploads/2012/03/pic-1.jpg" alt="" width="640" height="480" /></a></p>
<p>Let&#8217;s go!</p>
<p><strong>We need 6 buttons:</strong> 2 function buttons (Load &#8211; to load our leaderboard, Send &#8211; to send the score)and 4 buttons to filter the score: daily/weekly/monthly/all</p>
<p>We also need 3 columns (Text fields) to output name/score/date of players.</p>
<h2>Main code:</h2>
<ol>
<li>initialization function

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">initBoardfunction 
initBoard<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>
	MochiServices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">connect</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;MochiGameID&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">root</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><span style="color: #009900; font-style: italic;">// connecting to MochiServices</span>
	MochiScores<span style="color: #000066; font-weight: bold;">.</span>setBoardID<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;LeaderboardID&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// set the board ID to the leaderboard you wish to work</span>
withbtnDaily<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> showLeaderboard_d<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
btnWeekly<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> showLeaderboard_w<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
btnMonthly<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> showLeaderboard_m<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
btnAll<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> showLeaderboard_a<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> 
&nbsp;
btnLoad<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> loadLeaderboard<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
btnSend<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> sendScore<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><span style="color: #000000;">&#125;</span></pre></div></div>

</li>
<li>request is a list of score: onScoresReceived &#8211; callback function that gets the scoresfunction

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">loadLeaderboard<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
&nbsp;
<span style="color: #000000;">&#123;</span>
MochiScores<span style="color: #000066; font-weight: bold;">.</span>requestList<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">,</span> onScoresReceived<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><span style="color: #009900; font-style: italic;">// request the scores and send them to the onScoresReceived method in this object or class}</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//description onScoresReceived functionfunction onScoresReceived (args:Object):void{</span>
<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>args<span style="color: #000066; font-weight: bold;">.</span>scores <span style="color: #000066; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
allScores = MochiScores<span style="color: #000066; font-weight: bold;">.</span>scoresArrayToObjects<span style="color: #000000;">&#40;</span>args<span style="color: #000066; font-weight: bold;">.</span>scores<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
showScore<span style="color: #000000;">&#40;</span>allScores<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: #000000; font-weight:bold;">15</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #3f5fbf;">/*
* showScore(scores:Object, typeTop:int = 0, countPlaces:int = 10):void
* @scores - array of objects whose keys are derived from cols
* @typeTop - values:
* 		0 : alltime score
* 		1 : monthly score
* 		2 : weekly score
* 		3 : daily score
* @countPlaces - number of scores. show top 15 players for example
*/</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>args<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">error</span><span style="color: #000000;">&#41;</span> <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Error: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> args<span style="color: #000066; font-weight: bold;">.</span>errorCode<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></div></div>

</li>
<li>implementation of the showScore function:

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #339966; font-weight: bold;">function</span> showScore<span style="color: #000000;">&#40;</span>scores<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000066; font-weight: bold;">,</span> typeTop<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> countPlaces<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">10</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: #6699cc; font-weight: bold;">var</span> scoresOb<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> place<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
txt_name<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
txt_score<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
txt_date<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span> countPlaces<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
<span style="color: #0033ff; font-weight: bold;">switch</span><span style="color: #000000;">&#40;</span>typeTop<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">:</span> scoresOb = scores<span style="color: #000066; font-weight: bold;">.</span>alltime<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">:</span> scoresOb = scores<span style="color: #000066; font-weight: bold;">.</span>monthly<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">:</span> scoresOb = scores<span style="color: #000066; font-weight: bold;">.</span>weekly<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">3</span><span style="color: #000066; font-weight: bold;">:</span> scoresOb = scores<span style="color: #000066; font-weight: bold;">.</span>daily<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #0033ff; font-weight: bold;">break</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>scoresOb<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
txt_name<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span>place<span style="color: #000066; font-weight: bold;">++</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot; &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> scoresOb<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">'<span style="">\n</span>'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
txt_score<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span>scoresOb<span style="color: #000066; font-weight: bold;">.</span>score <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">'<span style="">\n</span>'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
txt_date<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span>showDate<span style="color: #000000;">&#40;</span>scoresOb<span style="color: #000066; font-weight: bold;">.</span>timestamp<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">'<span style="">\n</span>'</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: #000000;">&#125;</span></pre></div></div>

</li>
<li>function to display the correct date, for users :)

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #339966; font-weight: bold;">function</span> showDate<span style="color: #000000;">&#40;</span><span style="color: #004993;">date</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> myDate<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Date</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">date</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> arMonths<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;January&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;February&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;March&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;April&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;May&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;June&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;July&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;August&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;September&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;October&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;November&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;December&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #000000;">&#40;</span>arMonths<span style="color: #000000;">&#91;</span>myDate<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getMonth</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot; &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> myDate<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getDate</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;, &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> myDate<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getFullYear</span><span style="color: #000000;">&#40;</span><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></pre></div></div>

</li>
<li>to send the score

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #339966; font-weight: bold;">function</span> sendScore<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</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: #6699cc; font-weight: bold;">var</span> score<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">300</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;Typenamehere&quot;</span>
MochiScores<span style="color: #000066; font-weight: bold;">.</span>submit<span style="color: #000000;">&#40;</span>score<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">name</span><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> SubmitComplete<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #339966; font-weight: bold;">function</span> SubmitComplete<span style="color: #000000;">&#40;</span>ok<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</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: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>ok<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Scores submitted!&quot;</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: #000000;">&#123;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Error&quot;</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></div></div>

</li>
</ol>
<p>That&#8217;s it. Here, I&#8217;ve described how to create a simple leaderboard. With this is simple leaderboard we can also add the current rank of the player, country flags, and a scroll bar&#8230;but I&#8217;ll save that for another tutorial :)</p>
<p><a href="http://nsbrotherhood.com/download/LeaderBoard.rar"> Download the source here</a></p>
 <div class='series_toc'></div>	<p></p>
	<hr noshade style="margin:0;height:1px" />
	<p>&copy; uNik for <a href="http://mochiland.com">MochiLand</a>, 2012. |
	  <a href="http://mochiland.com/articles/tutorial-custom-leaderboards-with-mochi-api-as3">Permalink</a> |
	  <a href="http://mochiland.com/articles/tutorial-custom-leaderboards-with-mochi-api-as3#comments">One comment</a></p>
	<p>Add to <a href="http://del.icio.us/post?url=http://mochiland.com/articles/tutorial-custom-leaderboards-with-mochi-api-as3&amp;title=Tutorial: Custom Leaderboards With Mochi API (AS3)">del.icio.us</a></p>
	<p>Search blogs linking this post with <a href="http://www.technorati.com/search/http://mochiland.com/articles/tutorial-custom-leaderboards-with-mochi-api-as3" title="Search on Technorati">Technorati</a></p>
	<p>Want more on these topics ? Browse the archive of posts filed under <a href="http://mochiland.com/category/mochiland/developer-feed" title="View all posts in Developer Feed" rel="category tag">Developer Feed</a>, <a href="http://mochiland.com/category/mochiland/flash" title="View all posts in Flash Development" rel="category tag">Flash Development</a>, <a href="http://mochiland.com/category/mochiland/front-page" title="View all posts in Front Page" rel="category tag">Front Page</a>, <a href="http://mochiland.com/category/mochiland" title="View all posts in MochiLand Topics" rel="category tag">MochiLand Topics</a>, <a href="http://mochiland.com/category/mochiland/random" title="View all posts in Random" rel="category tag">Random</a>, <a href="http://mochiland.com/category/mochiland/tutorials" title="View all posts in Tutorials" rel="category tag">Tutorials</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://mochiland.com/articles/tutorial-custom-leaderboards-with-mochi-api-as3/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>FGS 2012 Advisory Board Series: Simon Lachance</title>
		<link>http://mochiland.com/articles/fgs-2012-advisory-board-series-simon-lachance</link>
		<comments>http://mochiland.com/articles/fgs-2012-advisory-board-series-simon-lachance#comments</comments>
		<pubDate>Wed, 07 Dec 2011 06:14:22 +0000</pubDate>
		<dc:creator>Colin Cupp</dc:creator>
				<category><![CDATA[Developer Feed]]></category>
		<category><![CDATA[Flash Development]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Games Industry]]></category>
		<category><![CDATA[Industry News]]></category>
		<category><![CDATA[Mochi Media Announcements]]></category>
		<category><![CDATA[MochiLand Topics]]></category>
		<category><![CDATA[Publisher Feed]]></category>
		<category><![CDATA[Berzerk Studio]]></category>
		<category><![CDATA[FGS 2012]]></category>
		<category><![CDATA[flash gaming summit]]></category>
		<category><![CDATA[Mochi Media]]></category>

		<guid isPermaLink="false">http://mochiland.com/?p=5958</guid>
		<description><![CDATA[FGS 2012 Advisory Board Interview Series This is part four in a series of interviews of the Flash Gaming Summit 2012 Advisory Board. This is your chance to get to know the folks who determine the content of Flash Gaming Summit, getting their thoughts on both the conference and the games industry in general. This week&#8217;s [...]]]></description>
			<content:encoded><![CDATA[ <p><a href="http://www.flashgamingsummit.com"><img class="alignleft size-full wp-image-5984" style="border: 0px;" title="fgs2012_interview_series_banner" src="http://mochiland.com/wp-content/uploads/2011/11/fgs2012_interview_series_banner.jpg" alt="" width="650" height="100" /></a></p>
<h1>FGS 2012 Advisory Board Interview Series</h1>
<p>This is part four in a series of interviews of the <a href="http://www.flashgamingsummit.com">Flash Gaming Summit 2012</a> Advisory Board. This is your chance to get to know the folks who determine the content of Flash Gaming Summit, getting their thoughts on both the conference and the games industry in general. This week&#8217;s Advisory Board interview features Simon Lachance, co-founder of <a href="http://www.berzerk-land.com/">Berzerk Studio</a>. Berzerk Studio is a highly successful game studio creating games for both online and mobile platforms.</p>
<p>For more information on Flash Gaming Summit, including passes, speaking, or award show nomination information <a href="http://www.flashgamingsummit.com">please visit the conference website</a>.</p>
<p><a href="http://www.berzerk-land.com/"><img class="alignleft size-full wp-image-6045" style="border: 0px;" title="Simon_logo" src="http://mochiland.com/wp-content/uploads/2011/12/Simon_logo.png" alt="" width="400" height="125" /></a></p>
<h2>Introduce yourself- who are you, how big is your team, and how do you participate in the Flash games industry?</h2>
<p>I&#8217;m Simon Lachance, co-founder of Berzerk Studio.  We&#8217;re a team of 7, (3 coders, 3 artists, 1 Game designer/Artist) making Flash games since the end of 2008. We have made over ten games up to this point, and recently launched our own Flash games portal.</p>
<h2>What did you do before?</h2>
<p>We, the 3 co-founders of Berzerk Studio, were working at the same Flash game company.  We always had the dream to start on our own, make games that we like and create a cool brand.  So we decided to quit our jobs and go full indie.</p>
<h2>How did you first get into the Flash games industry? Tell us about your path.</h2>
<p>As mentioned above, we were already working for another Flash Games company before Berzerk Studio.  That&#8217;s where we learned how to make a game from scratch.  After we founded Berzerk Studio, I was looking up &#8220;how to sell games&#8221; on the Internet (how to make a living out of it).  Our very first idea was to make a game on XNA and publish it on Xbox.  We had done a prototype of a Flash game ported on XNA that worked very well,  but we decided that it would have been too risky to start among the big ones.  Our strength was Flash games, and the XNA prototype would have taken too much time to make.</p>
<p>So back then, we did something hard but necessary-  we threw the 6-months-production-XNA-prototype in the garbage, and started another smaller game for the Flash market.  Our strategy was to create small but high quality games for the Flash market, build a reputation, a fanbase, and a brand to be able to sell on future console games.   That&#8217;s when we found Flash Game License (FGL).  Chris Hughes saw our prototype and contacted us, since then they really helped us monetize our games. You should really go see these guys if you want to know more on how to sell games and live from it.</p>
<h2>What has been your proudest moment since joining the Flash gaming community?</h2>
<p>It was when I went to <a href="http://www.flashgamingsummit.com/past-events/2011/">Flash Gaming Summit (FGS) 2011</a>. I&#8217;ve met a lot of cool people there- developers, publishers, portal owner etc. We exchanged a lot of great information on the games business. But the proudest moment was when I discovered that half of the people I&#8217;ve met knew Berzerk Studio and the Berzerk brand. There were literally people making the Berzerker&#8217;s scream from our intro in front of me saying &#8220;That&#8217;s the best intro ever!&#8221; I have never been so proud of our team.</p>
<h2>What was the biggest challenge for Berzerk Studio in the early going? How does that compare to the challenges you face today?</h2>
<p>I&#8217;d say the biggest challenge is monetizing your games. We knew how to make games, but to monetize them was something we had to learn. You have to make decisions when producing the games to make sure they sell well. The biggest challenge when you&#8217;re alone with no money to make a living, is time. You always have to scope small to make more games instead of risking to make a big game that won&#8217;t sell. Sometimes you have a really cool idea, but the time needed to create it is too long so you just have to leave it or save it for the sequel.</p>
<h2>Describe the climate as a game developer today in terms of technology and monetization opportunity. How does it compare to being a game developer 2-3 years ago?</h2>
<p>The biggest difference now is that you can think of porting your games on the mobile market.  The mobile market is way bigger than it was 2-3 years ago,  so it&#8217;s always best to think of a game that can be ported on the mobile market if the game does well on the web.  We chose Unity to port our games on iPhone and Android, which is a very strong technology that allows us now to port any of our games in 4 days.</p>
<h2>What is it that you love the MOST about the Flash games industry?</h2>
<p>It&#8217;s a very fast market.  You need to pump out games quickly, and it&#8217;s fairly easy to make a game that&#8217;ll be played millions of times all around the world.  It&#8217;s a very strong distribution tool for your brand.  An average Berzerk game gets 8-12 million plays,  sometimes 25 million.  That&#8217;s a lot of people that are exposed to your brand.</p>
<h2>What do you like the least?</h2>
<p>I&#8217;d say that it&#8217;s hard to make everybody happy.  Some players will want to tear it down, saying bad things about it. If your game is good,  people will ask for a sequel, NOW. If it&#8217;s bad, you&#8217;ll get tons of angry emails telling you what you did wrong.</p>
<h2>How has the industry changed since you fist joined?</h2>
<p>It&#8217;s pretty much the same.  You need a sponsor to distribute your games, it goes on thousands of portals and you start again. As said earlier, the biggest difference now for us is that we try to reach the mobile games market for games that worked well on web.</p>
<h2>The theme for FGS 2012 is &#8220;Maximize Your Game&#8221;. How do you think Flash game developers are maximizing their games today? What could they be doing better / differently?</h2>
<p>There&#8217;s a lot of ways to monetize your games.  Micro-transactions are one of them,  but knowing what and when to sell is a science. It&#8217;s important not to piss people off before they even play the game.  We have also found that translating our games in many languages is a really good thing to do, so you can reach new local markets.</p>
<h2>Where do you see the Flash games industry going? What&#8217;s in store for the future?</h2>
<p>Free small games will always be there.  It&#8217;s a great distribution tool for ads or showcasing your brand. I can&#8217;t see it going away anytime soon. Although, with Stage3D and the mobile market growing up, Flash games might finally have an impact on the mobile market.</p>
<h2>What part of Flash Gaming Summit do you enjoy or look forward to the most?</h2>
<p>Meeting people! Shaking hands and discussing business is my #1 plan at FGS.  If I have time, I&#8217;d also want to hop on stage to share my experiences, but there&#8217;s so many things going on here at Berzerk that I may not be able to!</p>
<h2>In your opinion, why should people come out to FGS 2012? What should they expect?</h2>
<p>&#8220;Maximize your games&#8221; pretty much sums it up.  Increasing revenue for each of your games is what you want, if you want to make games full-time and continue improving your games.</p>
<p><em><strong>Thanks Simon, see you at FGS 2012!</strong></em></p>
 <div class='series_toc'></div>	<p></p>
	<hr noshade style="margin:0;height:1px" />
	<p>&copy; Colin Cupp for <a href="http://mochiland.com">MochiLand</a>, 2011. |
	  <a href="http://mochiland.com/articles/fgs-2012-advisory-board-series-simon-lachance">Permalink</a> |
	  <a href="http://mochiland.com/articles/fgs-2012-advisory-board-series-simon-lachance#comments">No comment</a></p>
	<p>Add to <a href="http://del.icio.us/post?url=http://mochiland.com/articles/fgs-2012-advisory-board-series-simon-lachance&amp;title=FGS 2012 Advisory Board Series: Simon Lachance">del.icio.us</a></p>
	<p>Search blogs linking this post with <a href="http://www.technorati.com/search/http://mochiland.com/articles/fgs-2012-advisory-board-series-simon-lachance" title="Search on Technorati">Technorati</a></p>
	<p>Want more on these topics ? Browse the archive of posts filed under <a href="http://mochiland.com/category/mochiland/developer-feed" title="View all posts in Developer Feed" rel="category tag">Developer Feed</a>, <a href="http://mochiland.com/category/mochiland/flash" title="View all posts in Flash Development" rel="category tag">Flash Development</a>, <a href="http://mochiland.com/category/mochiland/front-page" title="View all posts in Front Page" rel="category tag">Front Page</a>, <a href="http://mochiland.com/category/mochiland/games-industry" title="View all posts in Games Industry" rel="category tag">Games Industry</a>, <a href="http://mochiland.com/category/mochiland/gaming-news" title="View all posts in Industry News" rel="category tag">Industry News</a>, <a href="http://mochiland.com/category/mochiland/mochi-media-announcements" title="View all posts in Mochi Media Announcements" rel="category tag">Mochi Media Announcements</a>, <a href="http://mochiland.com/category/mochiland" title="View all posts in MochiLand Topics" rel="category tag">MochiLand Topics</a>, <a href="http://mochiland.com/category/mochiland/publisher-feed" title="View all posts in Publisher Feed" rel="category tag">Publisher Feed</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://mochiland.com/articles/fgs-2012-advisory-board-series-simon-lachance/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mochi Community Contribution: Creating Ally AI by Danny Buoncore</title>
		<link>http://mochiland.com/articles/mochi-community-contribution-creating-ally-ai-by-danny-buoncore</link>
		<comments>http://mochiland.com/articles/mochi-community-contribution-creating-ally-ai-by-danny-buoncore#comments</comments>
		<pubDate>Tue, 06 Dec 2011 00:55:01 +0000</pubDate>
		<dc:creator>dannybuoncore</dc:creator>
				<category><![CDATA[Developer Feed]]></category>
		<category><![CDATA[Developer Spotlight]]></category>
		<category><![CDATA[Flash Development]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Game Design]]></category>
		<category><![CDATA[MochiLand Topics]]></category>
		<category><![CDATA[artificial intelligence]]></category>
		<category><![CDATA[Danny Buonocore]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Mochi Media]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://mochiland.com/?p=5916</guid>
		<description><![CDATA[Creating Ally AI That Locates Nearest Enemy and Attacks In this tutorial, you will learn: Basic for loop usage Basic array usage How to find the distance between two points How to use Math.atan2() to have MovieClips follow each other How to fire projectiles How to split a velocity vector into two perpendicular lines using [...]]]></description>
			<content:encoded><![CDATA[ <h1 class="post-title">Creating Ally AI That Locates Nearest Enemy and Attacks</h1>
<h2>In this tutorial, you will learn:</h2>
<ul>
<li>Basic for loop usage</li>
<li>Basic array usage</li>
<li>How to find the distance between two points</li>
<li>How to use Math.atan2() to have MovieClips follow each other</li>
<li>How to fire projectiles</li>
<li>How to split a velocity vector into two perpendicular lines using sine and cosine</li>
<li>How to create objects from custom classes</li>
</ul>
<h4>Introduction</h4>
<p>When learning Actionscript, or any programming language for that matter, I find it best to create specific engines that employ a variety of techniques and functions.  This way, you are not only learning how to use these features, but you are also experiencing a pragmatic use for them.  In this tutorial we will be creating a class for an ally AI that will locate the enemy nearest it, chase it, and shoot it.  This is used in just about any game where there are characters not controlled by the player.  Take, for example, a tower defense game.  The towers created do not simply attack any enemy they want.  They usually attack the closest.  However, there are some games where you can choose to have them attack the quickest enemy, or the one with the most health, or whatever it may be.  But for now let&#8217;s concentrate on distance.</p>
<p>Now, what if there are three allies (let&#8217;s call them followers for now) and two enemies, one of which is really far away?  The tutorial you are about to read is designed so that rather than all three followers clustering up on the closest enemy, two will attack it and the third will set off for the far one.  Furthermore, what happens when a third enemy is spawned when all this is going on?  Well, rather than the follower by itself (which may be closer) going out to attack it, one of the two that are attacking the same enemy will leave and target the newfound enemy.  This optimizes the strategy of the followers so no enemy is left alone while there is a surplus of followers elsewhere.</p>
<p>Rather than just talking about what we&#8217;re going to do, let&#8217;s actually do it.  Sometimes I prefer to just see the source code and play around with it rather than just following a tutorial.  If you want, you may download a heavily-commented copy of all the code down below.  Without further ado, let&#8217;s begin the tutorial.</p>
<p><a href="http://www.mediafire.com/?xhhbm1ovehio8ag">Download Source</a></p>
<h4>Step 1: Setting Up the MovieClips</h4>
<p>There are three MovieClips essential to this tutorial.  First, we need the followers and the enemies.  We also need some sort of projectile or bullet for the followers to shoot.  For the sake of example, I am programming this tutorial in a way that the user can create followers and enemies by clicking buttons at the bottom of the stage.  So now we&#8217;re up to five MovieClips.  Name them Bee, EnemyBee, Ball, BeeButton, and EnemyButton.  Below are my five MovieClips in their respective order:</p>
<p><img src="http://img337.imageshack.us/img337/6232/movieclips.jpg" alt="MovieClips" /></p>
<p>When saving each as a symbol, be sure to check the &#8220;Export for Actionscript&#8221; box and keep the class name the same.</p>
<h4>Step 2: The Arrays</h4>
<p>Now that we have our MovieClips, we need a place to store them.  Open up the Main Timeline&#8217;s Actions Panel (F9) and input the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> beeArray=<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> eArray=<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> ballArray=<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>What&#8217;s happening here is we are creating three arrays to store our objects: one for all the bees (followers), one for all the enemies, and one for all the balls being shot.  These arrays are going to be accessed a ton of times throughout the tutorial, so if you need to brush up on any of the arrays basics be sure to check out this <a href="http://active.tutsplus.com/tutorials/actionscript/as3-101-arrays/">tutorial</a></p>
<h4>Step 3: The Enemies</h4>
<p>The enemies are much easier to program, so we&#8217;ll start with them first.  Create a new custom class called EnemyBee (or whatever necessary to match the name of your enemy MovieClip) and start off with the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MovieClip</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><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> EnemyBee <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">MovieClip</span> <span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> r<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">angle</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> rot<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> health<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> speedX<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> speedY<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> dist<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> reload<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//reload timer for shooting (don't worry about this for now)</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> isTarget<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><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> EnemyBee<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ADDED_TO_STAGE</span><span style="color: #000066; font-weight: bold;">,</span> beginClass<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> beginClass<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</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;
r=<span style="color: #004993;">MovieClip</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">root</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><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> eFrame<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
r<span style="color: #000066; font-weight: bold;">.</span>eArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span>=<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageWidth</span><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: #004993;">width</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span>=<span style="color: #004993;">Math</span><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: #000000; font-weight:bold;">20</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> h<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #004993;">Math</span><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: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageHeight</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #004993;">angle</span>=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">atan2</span><span style="color: #000000;">&#40;</span>h<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: #004993;">y</span><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: #004993;">x</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>speedX=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><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; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>speedY=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><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; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">rotation</span>=<span style="color: #004993;">angle</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
rot=<span style="color: #004993;">Math</span><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;">4</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> eFrame<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</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>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Now this is a lot of code all at once so let&#8217;s go through it line by line.  Lines 6-13 declare variables which are more or less self-explanatory.  The main one to note here is the public variable isTarget.  This variable isn&#8217;t accessed at all by EnemyBee, but from the followers.  It is used to tell how many bees are following the EnemyBee.  But let&#8217;s move on for now.</p>
<p>In the beginClass function, line 20 places EnemyBee inside eArray (on the Main Timeline) through the use of r (the root of the MovieClip).  Below, the initial x and y coordinates are set to be just off the right side of the stage anywhere from the top to the bottom.  Variable h is the destination of EnemyBee and, using Math.random(), is different every time.  The next line uses a function called Math.atan2().  Most of you trigonometry aficionados know that the atan2 function, being a variant of the arctangent function, returns the angle (in radians) between the positive x axis of a plane and the point constructed by the given coordinates.  For now, all you need to know are the parameters.  They are as follows:</p>
<p><span> Math.atan2(destinationY-this.y , destinationX-this.x);</span></p>
<p>It seems strange, but just remember the y comes first.  By using the atan2 function we now know the angle between the point EnemyBee is going for (in this case h) and itself.  But how do we make it so that our object moves towards it?  That&#8217;s where the sine and cosine lines come in.  By taking the cosine of the angle we can find the horizontal speed the object must take.  Similarly, we can use sine to find the vertical speed.  You can replace the 2 at the end of each line with a larger or smaller number to increase or decrease the speed (respectively).  Finally, we rotate the object to face its target once again using angle, and then assign rot (the rotational speed) a random number from 0-3.99999 (this is used later on).</p>
<p>Now we can edit the eFrame function.  So within the brackets, place this code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">this</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: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>speedX<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: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>health<span style="color: #000066; font-weight: bold;">&amp;</span>gt<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: #000000;">&#123;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">this</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: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>speedY<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: #0033ff; font-weight: bold;">this</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: #0033ff; font-weight: bold;">this</span><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;">&amp;</span>lt<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: #000000;">&#123;</span>
&nbsp;
r<span style="color: #000066; font-weight: bold;">.</span>eArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">splice</span><span style="color: #000000;">&#40;</span>r<span style="color: #000066; font-weight: bold;">.</span>eArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</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>
&nbsp;
removeMe<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>
&nbsp;
<span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>r<span style="color: #000066; font-weight: bold;">.</span>eArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&amp;</span>gt<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: #000000;">&#123;</span>
&nbsp;
r<span style="color: #000066; font-weight: bold;">.</span>eArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">splice</span><span style="color: #000000;">&#40;</span>r<span style="color: #000066; font-weight: bold;">.</span>eArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</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>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">rotation</span><span style="color: #000066; font-weight: bold;">+</span>=<span style="color: #000000; font-weight:bold;">5</span><span style="color: #000066; font-weight: bold;">+</span>rot<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">this</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; font-weight:bold;">3</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000066; font-weight: bold;">-</span>rot<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>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>y<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>width<span style="color: #000066; font-weight: bold;">&amp;</span>gt<span style="color: #000066; font-weight: bold;">;;</span>stage<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageHeight</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
removeMe<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>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>First, the object moves horizontally.  Next, if its health is greater than zero (meaning it is not dead) it will also move vertically and if it manages to survive the followers and go offstage to the left, remove itself from eArray, and then call the removeMe() function which we will declare in a little bit.  In case EnemyBee IS defeated, however, it will first check to see if its index in eArray is at least 0.  A useful fact about arrays is that &#8220;if&#8221; an object isn&#8217;t in the array at all, its index is -1.  Through this &#8220;if statement&#8221; we are effectively checking to see if EnemyBee is in eArray so we don&#8217;t accidentally remove it twice (that would result in an error).  The next few lines are pretty much self-explanatory.</p>
<p>The last piece of code for EnemyBee is the removeMe() function.  Here it is:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> removeMe<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: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> eFrame<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
r<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>This last part is easy.  First the event listener is removed, and then the object itself is deleted.  That&#8217;s all we need for EnemyBee.  Now we can start the hard stuff! (:</p>
<h4>Step 4: The Followers</h4>
<p>Now it&#8217;s time to get to the heart of the tutorial: creating the followers.  Create a new custom class for your followers (in this case it&#8217;s called Bee), and input this code:</p>

<div class="wp_syntax"><div class="code"><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><span style="color: #004993;">MovieClip</span><span style="color: #000066; font-weight: bold;">;</span>
 	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><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> Bee <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">MovieClip</span> <span style="color: #000000;">&#123;</span>
  	<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> r<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span><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> <span style="color: #004993;">c</span><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> <span style="color: #004993;">max</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MAX_VALUE</span><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> speedX<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><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> speedY<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><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> speed<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">2</span><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> <span style="color: #004993;">angle</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><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> reload<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">50</span><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> Bee<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
   	<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ADDED_TO_STAGE</span><span style="color: #000066; font-weight: bold;">,</span> beginClass<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;">private</span> <span style="color: #339966; font-weight: bold;">function</span> beginClass<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</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>
   	r=<span style="color: #004993;">MovieClip</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">root</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   	<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> eFrame<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   	r<span style="color: #000066; font-weight: bold;">.</span>beeArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   	<span style="color: #004993;">x</span>=<span style="color: #000000; font-weight:bold;">275</span><span style="color: #000066; font-weight: bold;">;</span>
   	<span style="color: #004993;">y</span>=<span style="color: #000000; font-weight:bold;">245</span><span style="color: #000066; font-weight: bold;">;</span>
  	<span style="color: #000000;">&#125;</span>
  	<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> eFrame<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</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>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>You&#8217;ve seen all this code already in EnemyBee so I&#8217;m not going to explain it all again.  The only exceptions are c (which will be explained in a bit) and Number.MAX_VALUE, which can simply be thought of as infinity.</p>
<p>There&#8217;s a lot of code in the eFrame event, so let&#8217;s do it all in pieces.  First, we need this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>r<span style="color: #000066; font-weight: bold;">.</span>eArray<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;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//paste all the following code here</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>This line of code tells us if there are any enemies on stage or not.  Without it, we would get errors.  Within the brackets, place this first bunch of code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>r<span style="color: #000066; font-weight: bold;">.</span>eArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">c</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&amp;</span>lt<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: #000000;">&#123;</span> <span style="color: #009900; font-style: italic;">//if c is NOT in eArray...</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;;</span>r<span style="color: #000066; font-weight: bold;">.</span>eArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #009900; font-style: italic;">//for every object in eArray...</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> obj=r<span style="color: #000066; font-weight: bold;">.</span>eArray<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//assign address of object to obj</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> distX<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>x<span style="color: #000066; font-weight: bold;">-</span>obj<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: #009900; font-style: italic;">//horizontal distance between self and obj (the enemy)</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> distY<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>y<span style="color: #000066; font-weight: bold;">-</span>obj<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: #009900; font-style: italic;">//vertical distance between self and obj (the enemy)</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> dist<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000;">&#40;</span>distX<span style="color: #000066; font-weight: bold;">*</span>distX<span style="color: #000066; font-weight: bold;">+</span>distY<span style="color: #000066; font-weight: bold;">*</span>distY<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//overall distance using distance formula</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>dist<span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span>max<span style="color: #000066; font-weight: bold;">&amp;</span>amp<span style="color: #000066; font-weight: bold;">;&amp;</span>amp<span style="color: #000066; font-weight: bold;">;</span>obj<span style="color: #000066; font-weight: bold;">.</span>isTarget==<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #009900; font-style: italic;">//if distance &amp;lt; max and obj has no followers...</span>
&nbsp;
<span style="color: #004993;">max</span>=dist<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//assign distance to max (the new shorst distance)</span>
&nbsp;
<span style="color: #004993;">c</span>=obj<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//assign address of object currently being tested in c</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>r<span style="color: #000066; font-weight: bold;">.</span>eArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">c</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&amp;</span>gt<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: #000000;">&#123;</span> <span style="color: #009900; font-style: italic;">//if c is in eArray...</span>
&nbsp;
<span style="color: #004993;">c</span><span style="color: #000066; font-weight: bold;">.</span>isTarget<span style="color: #000066; font-weight: bold;">++;</span> <span style="color: #009900; font-style: italic;">//tell c (EnemyBee) that one more bee is following it</span>
&nbsp;
<span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span> <span style="color: #009900; font-style: italic;">//if c is NOT in eArray...</span>
&nbsp;
<span style="color: #004993;">max</span>=<span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MAX_VALUE</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//reset max to maximum value</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> j<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span>r<span style="color: #000066; font-weight: bold;">.</span>eArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #009900; font-style: italic;">//for every object in eArray...</span>
&nbsp;
obj=r<span style="color: #000066; font-weight: bold;">.</span>eArray<span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//assign address of object to obj</span>
&nbsp;
distX=<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>x<span style="color: #000066; font-weight: bold;">-</span>obj<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: #009900; font-style: italic;">//horizontal distance between self and obj (the enemy)</span>
&nbsp;
distY=<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>y<span style="color: #000066; font-weight: bold;">-</span>obj<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: #009900; font-style: italic;">//vertical distance between self and obj (the enemy)</span>
&nbsp;
dist=<span style="color: #000000;">&#40;</span>distX<span style="color: #000066; font-weight: bold;">*</span>distX<span style="color: #000066; font-weight: bold;">+</span>distY<span style="color: #000066; font-weight: bold;">*</span>distY<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//overall distance using distance formuala</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>dist<span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span>max<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #009900; font-style: italic;">//if distance is closer than max...</span>
&nbsp;
<span style="color: #004993;">max</span>=dist<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//assign distance to max (the new shortest distance)</span>
&nbsp;
<span style="color: #004993;">c</span>=obj<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//assign address of object currently being tested in c</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #004993;">c</span><span style="color: #000066; font-weight: bold;">.</span>isTarget<span style="color: #000066; font-weight: bold;">++;</span> <span style="color: #009900; font-style: italic;">//tell c (EnemyBee) that one more bee is following it</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>It can get a little confusing at this point, so I included plenty of comments.  The variable c is used to hold the address of the closest enemy (hence it&#8217;s name).  First we check to see if it is not in the array (meaning the closest enemy has not been determined).  We use a for loop to iterate through all the enemies in eArray.  If you&#8217;re new to loops, you can read up on them <a href="http://active.tutsplus.com/tutorials/actionscript/as3-101-loops/">here</a>.</p>
<p>Next we instantiate four variables:  a placeholder for the object being tested, the horizontal distance, the vertical distance, and the total distance.  Just in case you are wondering, the distance formula is as follows:</p>
<p><img src="http://upload.wikimedia.org/wikipedia/en/math/f/0/a/f0a4a3d633ef96d31f068e387cd91fc2.png" alt="Distance Formula" /></p>
<p>Now that we know the distance of the object being checked, we must see if it is closer than the previous.  Recall that max was equal to Number.MAX_VALUE, so it is greater than anything we could compare it to.  So the first instance to be checked will definitely be closer, and the if statement will be true.  Therefore, max is set to the distance between itself and the enemy being tested (the new shortest distance), and obj is stored in c.  All that happened for the first enemy in eArray.  Now go through it again for the second enemy.  The second enemy is stored in obj, just like the first, and the distance is established.  However, instead of max being equal to the highest value, it is equal to the distance of the previous enemy.  If the distance between the bee and the enemy being tested is shorter than that of the first enemy, max is lowered again to match the distance and the enemy is stored in c.  If not, the loop skips over this and goes on to test the next enemy.  This process continues for every enemy in the array.  Logically, the value of max by the time all of the enemies are done being tested will be equal to the shortest distance, and c will hold the address for the corresponding enemy.</p>
<p>Note that with the if statement, Bee only looks for enemies that have isTarget==0.  In plain English, that means it only takes enemies that are not being followed into consideration.  This way we don&#8217;t have that surplus of followers in one section and a non-followed enemy elsewhere like we previously discussed.  However, there is the case that every enemy is already being followed.  The if statement right after the for loop checks to see if a closest enemy (with no followers) has been found.  If so, it increases the value of isTarget on the enemy (amount of followers).  If not, another for loop extremely similar to the previous is carried out.  The only difference is the if statement:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>dist<span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span>max<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span></pre></div></div>

<p>Instead of checking to be sure the enemy being tested has no followers, it just looks for the closest.  I found this to be the best design, but you might have another use for it.  This code is very easy to customize.  Say you wanted locate the enemy with the least amount of followers.  You could simply substitute the if statement for this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>obj<span style="color: #000066; font-weight: bold;">.</span>isTarget<span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span>max<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #004993;">max</span>=obj<span style="color: #000066; font-weight: bold;">.</span>isTarget<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #004993;">c</span>=obj<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>All right we&#8217;re getting closer to finishing this up.  One more loop:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #004993;">max</span>=<span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MAX_VALUE</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//reset max to maximum value</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>r<span style="color: #000066; font-weight: bold;">.</span>eArray<span style="color: #000066; font-weight: bold;">.</span>length<span style="color: #000066; font-weight: bold;">&amp;</span>gt<span style="color: #000066; font-weight: bold;">;</span>=r<span style="color: #000066; font-weight: bold;">.</span>beeArray<span style="color: #000066; font-weight: bold;">.</span>length<span style="color: #000066; font-weight: bold;">&amp;</span>amp<span style="color: #000066; font-weight: bold;">;&amp;</span>amp<span style="color: #000066; font-weight: bold;">;</span>c<span style="color: #000066; font-weight: bold;">.</span>isTarget<span style="color: #000066; font-weight: bold;">&amp;</span>gt<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> <span style="color: #009900; font-style: italic;">//if c has other followers...</span>
&nbsp;
<span style="color: #004993;">c</span><span style="color: #000066; font-weight: bold;">.</span>isTarget<span style="color: #000066; font-weight: bold;">--;</span> <span style="color: #009900; font-style: italic;">//tell c it has one fewer follower</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> l<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> l<span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span>r<span style="color: #000066; font-weight: bold;">.</span>eArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span> l<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #009900; font-style: italic;">//for every object in eArray...</span>
&nbsp;
obj=r<span style="color: #000066; font-weight: bold;">.</span>eArray<span style="color: #000000;">&#91;</span>l<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//assign address of object to obj</span>
&nbsp;
distX=<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>x<span style="color: #000066; font-weight: bold;">-</span>obj<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: #009900; font-style: italic;">//horizontal distance between self and obj (the enemy)</span>
&nbsp;
distY=<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>y<span style="color: #000066; font-weight: bold;">-</span>obj<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: #009900; font-style: italic;">//vertical distance between self and obj (the enemy)</span>
&nbsp;
dist=<span style="color: #000000;">&#40;</span>distX<span style="color: #000066; font-weight: bold;">*</span>distX<span style="color: #000066; font-weight: bold;">+</span>distY<span style="color: #000066; font-weight: bold;">*</span>distY<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//overall distance using distance formula</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>dist<span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span>max<span style="color: #000066; font-weight: bold;">&amp;</span>amp<span style="color: #000066; font-weight: bold;">;&amp;</span>amp<span style="color: #000066; font-weight: bold;">;</span>obj<span style="color: #000066; font-weight: bold;">.</span>isTarget==<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #009900; font-style: italic;">//if distance &amp;lt; max and obj has no followers...</span>
&nbsp;
<span style="color: #004993;">max</span>=dist<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//assign distance to max (the new shortest distance)</span>
&nbsp;
<span style="color: #004993;">c</span>=obj<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//assign address of object currently being tested in c</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #004993;">c</span><span style="color: #000066; font-weight: bold;">.</span>isTarget<span style="color: #000066; font-weight: bold;">++;</span> <span style="color: #009900; font-style: italic;">//tell c (EnemyBee) that one more bee is following it</span>
&nbsp;
<span style="color: #004993;">max</span>=<span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MAX_VALUE</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//reset max to maximum value</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Okay so after doing two loops almost exactly like this one, no explanation should be necessary.  However, a brief discourse on the logic behind it should help.  The only thing different here than the first loop is that it is only executed when there are more enemies than followers and the enemy the bee is following has at least one other follower.  You may be asking yourself why I chose to create three loops that are almost identical instead of simply making a function called several times with slightly different arguments.  Well, I think it&#8217;s easier to retain the information if you see it several times.  Plus, a tutorial is never complete unless something is left up to you to figure out yourself.</p>
<p>All right, now that the difficult part is out of the way, we can move on to actually moving the bee.  The code below immediately follows the if statement above:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #004993;">angle</span>=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">atan2</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">c</span><span style="color: #000066; font-weight: bold;">.</span>y<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: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">c</span><span style="color: #000066; font-weight: bold;">.</span>x<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: #004993;">x</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//angle between self and closest enemy</span>
&nbsp;
speedX=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><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>speed<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//find horizontal speed according to angle</span>
&nbsp;
speedY=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><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>speed<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//find vertical speed according to angle</span>
&nbsp;
<span style="color: #004993;">rotation</span>=<span style="color: #004993;">angle</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//rotate to face enemy</span>
&nbsp;
distX=<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>x<span style="color: #000066; font-weight: bold;">-</span><span style="color: #004993;">c</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: #009900; font-style: italic;">//horizontal distance between self and closest enemy</span>
&nbsp;
distY=<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>y<span style="color: #000066; font-weight: bold;">-</span><span style="color: #004993;">c</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: #009900; font-style: italic;">//vertical distance between self and closest enemy</span>
&nbsp;
dist=<span style="color: #000000;">&#40;</span>distX<span style="color: #000066; font-weight: bold;">*</span>distX<span style="color: #000066; font-weight: bold;">+</span>distY<span style="color: #000066; font-weight: bold;">*</span>distY<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//overall distance using distance formula</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>dist<span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</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;">//if distance is less than or equal to 100...</span>
&nbsp;
speed=<span style="color: #000066; font-weight: bold;">-.</span>1<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//slow down</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>speed<span style="color: #000066; font-weight: bold;">&amp;</span>lt<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: #000000;">&#123;</span> <span style="color: #009900; font-style: italic;">//if speed is less than 0...</span>
&nbsp;
speed=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//keep speed at 0</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span> <span style="color: #009900; font-style: italic;">//if distance is greater than 100...</span>
&nbsp;
speed<span style="color: #000066; font-weight: bold;">+</span>=<span style="color: #000066; font-weight: bold;">.</span>1<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//speed up</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>speed<span style="color: #000066; font-weight: bold;">&amp;</span>gt<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;">&#123;</span> <span style="color: #009900; font-style: italic;">//if speed is greater than 2...</span>
&nbsp;
speed=<span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//keep speed at 2</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">+</span>=speedX<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//move horizontally</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">+</span>=speedY<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//move vertically</span></pre></div></div>

<p>This is very similar to the motion employed in the EnemyBee class and shouldn&#8217;t be too difficult at all.  The if and else statements are purely for aesthetic purposes so that the bee doesn&#8217;t sit directly on the enemy.</p>
<p>That concludes the code for the followers.  Now all we need is a means to create the followers and enemies.  I&#8217;m sure you will come up with plenty of ways that pertain to your game, but for the sake of convenience I just created two buttons that allow the user to spawn them.  If you&#8217;d like to see the Actionscript for this, download the source code files from above.</p>
<h4>Step 5: Shooting</h4>
<p>Run your .swf.  If you did it right, you should get something like this:</p>
<p>The bees follow the enemies just like we programmed them to, but they do not attack.  Remember that Ball Movieclip we make at the beginning of the tutorial?  Well we&#8217;re finally going to use it.  Open up the custom class for Ball and type this in:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MovieClip</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><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> Ball <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">MovieClip</span> <span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> r<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">c</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">15</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> id2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">angle</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> speedX<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> speedY<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> speed<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">8</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> mc<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span><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> Ball<span style="color: #000000;">&#40;</span>id<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ADDED_TO_STAGE</span><span style="color: #000066; font-weight: bold;">,</span> beginClass<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
id2=id<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> beginClass<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</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;
r=<span style="color: #004993;">MovieClip</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">root</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><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> eFrame<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
mc=r<span style="color: #000066; font-weight: bold;">.</span>beeArray<span style="color: #000000;">&#91;</span>id2<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//find which object created it</span>
&nbsp;
<span style="color: #004993;">angle</span>=mc<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">rotation</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span>=mc<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: #009900; font-style: italic;">//set x coordinate to that of bee's</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span>=mc<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: #009900; font-style: italic;">//set y coordinate to that of bee's</span>
&nbsp;
speedX=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><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>speed<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
speedY=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><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>speed<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
r<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setChildIndex</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">,</span>r<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildIndex</span><span style="color: #000000;">&#40;</span>mc<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> eFrame<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</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: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">+</span>=speedX<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">+</span>=speedY<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>c<span style="color: #000066; font-weight: bold;">&amp;</span>gt<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: #000000;">&#123;</span>
&nbsp;
c<span style="color: #000066; font-weight: bold;">--;</span>
&nbsp;
<span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>alpha<span style="color: #000066; font-weight: bold;">-</span>=<span style="color: #000066; font-weight: bold;">.</span>1<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>alpha<span style="color: #000066; font-weight: bold;">&amp;</span>lt<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: #000000;">&#123;</span>
&nbsp;
removeBall<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>
&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> removeBall<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: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> eFrame<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
r<span style="color: #000066; font-weight: bold;">.</span>ballArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">splice</span><span style="color: #000000;">&#40;</span>r<span style="color: #000066; font-weight: bold;">.</span>ballArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</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>
&nbsp;
r<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Basically we&#8217;re just creating an object that follows a straight line path using the rotation of the bee it&#8217;s coming from.  The address of the bee is determined by the parameter id2, which we will explain it a bit.  Now we have to program Bee to actually shoot the balls.  In the eFrame event of Bee, right after the speedX and speedY are used, place the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">reload<span style="color: #000066; font-weight: bold;">--;</span> <span style="color: #009900; font-style: italic;">//lower reload timer</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>reload==<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #009900; font-style: italic;">//if reload is complete...</span>
&nbsp;
reload=<span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//reset reload timer to 50</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> newBall<span style="color: #000066; font-weight: bold;">:</span>Ball=<span style="color: #0033ff; font-weight: bold;">new</span> Ball<span style="color: #000000;">&#40;</span>r<span style="color: #000066; font-weight: bold;">.</span>beeArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//create new ball</span>
&nbsp;
r<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>newBall<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//add ball to stage</span>
&nbsp;
r<span style="color: #000066; font-weight: bold;">.</span>ballArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>newBall<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//put ball in ballArray</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>This creates a new instance of the Ball class and places it in the corresponding array on the Main Timeline.  As you can see, the argument incorporated while instantiating the new ball is the index of the bee in its array.  This is then later accessed by the ball in its class to find where it should be placed on the stage and the angle it should follow:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">mc=r<span style="color: #000066; font-weight: bold;">.</span>beeArray<span style="color: #000000;">&#91;</span>id2<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//find which object created it</span>
&nbsp;
<span style="color: #004993;">angle</span>=mc<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">rotation</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span>=mc<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: #009900; font-style: italic;">//set x coordinate to that of bee's</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span>=mc<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: #009900; font-style: italic;">//set y coordinate to that of bee's</span>
&nbsp;
speedX=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><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>speed<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
speedY=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><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>speed<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
r<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setChildIndex</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">,</span>r<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildIndex</span><span style="color: #000000;">&#40;</span>mc<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>The address of the bee is found using id2 (which is equal to the argument we just mentioned) and stored in mc, which is used to set all that good stuff above.  The setChildIndex() statement is used so that the ball appears below the bee, giving the illusion that it&#8217;s being shot by the bee, and not appearing right on top of it.</p>
<p>Okay so run your .swf again and you should see this:</p>
<p>Pretty good, huh?  Now we just have more step: the collisions.</p>
<h4>Step 6: The Collisions</h4>
<p>This part is easy.  Simply open up the class file for EnemyBee and, in the first line of the eFrame event, put in the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span>r<span style="color: #000066; font-weight: bold;">.</span>ballArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> mc<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span>=r<span style="color: #000066; font-weight: bold;">.</span>ballArray<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
dist=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">abs</span><span style="color: #000000;">&#40;</span>mc<span style="color: #000066; font-weight: bold;">.</span>x<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: #004993;">x</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">abs</span><span style="color: #000000;">&#40;</span>mc<span style="color: #000066; font-weight: bold;">.</span>y<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: #004993;">y</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>dist<span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;;</span>this<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>mc<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;">&#123;</span> <span style="color: #009900; font-style: italic;">//if they touch...</span>
&nbsp;
health<span style="color: #000066; font-weight: bold;">--;</span>
&nbsp;
mc<span style="color: #000066; font-weight: bold;">.</span>removeBall<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>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>It&#8217;s just a for loop that iterates over every instance in the ball array and tests for a collision.  You can use whatever collision-detection technique you want, but for this example the best choice is a simple circle-to-circle test.  Upon each collision, the health of the bee is lowered, and the ball is removed through the function removeBall().</p>
<p>Well, that&#8217;s about it.  Test your .swf and it should work just as my example up above did.  This technique is very useful and I&#8217;m sure you&#8217;ll find plenty of ways to use it in your games.  If you make something cool, I&#8217;d love to see it (: Thanks for reading!</p>
 <div class='series_toc'></div>	<p></p>
	<hr noshade style="margin:0;height:1px" />
	<p>&copy; dannybuoncore for <a href="http://mochiland.com">MochiLand</a>, 2011. |
	  <a href="http://mochiland.com/articles/mochi-community-contribution-creating-ally-ai-by-danny-buoncore">Permalink</a> |
	  <a href="http://mochiland.com/articles/mochi-community-contribution-creating-ally-ai-by-danny-buoncore#comments">No comment</a></p>
	<p>Add to <a href="http://del.icio.us/post?url=http://mochiland.com/articles/mochi-community-contribution-creating-ally-ai-by-danny-buoncore&amp;title=Mochi Community Contribution: Creating Ally AI by Danny Buoncore">del.icio.us</a></p>
	<p>Search blogs linking this post with <a href="http://www.technorati.com/search/http://mochiland.com/articles/mochi-community-contribution-creating-ally-ai-by-danny-buoncore" title="Search on Technorati">Technorati</a></p>
	<p>Want more on these topics ? Browse the archive of posts filed under <a href="http://mochiland.com/category/mochiland/developer-feed" title="View all posts in Developer Feed" rel="category tag">Developer Feed</a>, <a href="http://mochiland.com/category/mochiland/developer-spotlight" title="View all posts in Developer Spotlight" rel="category tag">Developer Spotlight</a>, <a href="http://mochiland.com/category/mochiland/flash" title="View all posts in Flash Development" rel="category tag">Flash Development</a>, <a href="http://mochiland.com/category/mochiland/front-page" title="View all posts in Front Page" rel="category tag">Front Page</a>, <a href="http://mochiland.com/category/mochiland/game-design" title="View all posts in Game Design" rel="category tag">Game Design</a>, <a href="http://mochiland.com/category/mochiland" title="View all posts in MochiLand Topics" rel="category tag">MochiLand Topics</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://mochiland.com/articles/mochi-community-contribution-creating-ally-ai-by-danny-buoncore/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Mochi Ads &amp; Scores to a Stencyl Game</title>
		<link>http://mochiland.com/articles/adding-mochi-ads-scores-to-a-stencyl-game</link>
		<comments>http://mochiland.com/articles/adding-mochi-ads-scores-to-a-stencyl-game#comments</comments>
		<pubDate>Mon, 28 Nov 2011 16:00:20 +0000</pubDate>
		<dc:creator>JonathanChung</dc:creator>
				<category><![CDATA[Developer Feed]]></category>
		<category><![CDATA[Flash Development]]></category>
		<category><![CDATA[Game Design]]></category>
		<category><![CDATA[MochiLand Topics]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[Mochi Media]]></category>
		<category><![CDATA[Stencyl]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://mochiland.com/?p=5755</guid>
		<description><![CDATA[Mochi Media is one of the most popular ways for Flash game developers to make money with their games using  their in-game ads product Mochi Ads. Mochi is also a one-stop solution for game analytics, achievements, leaderboards, and virtual currency. StencylWorks is an easy way to visually create Flash and iOS games for non-coders and [...]]]></description>
			<content:encoded><![CDATA[ <p>Mochi Media is one of the most popular ways for Flash game developers to make money with their games using  their in-game ads product <strong>Mochi Ads</strong>. Mochi is also a one-stop solution for game analytics, achievements, leaderboards, and virtual currency.</p>
<div class="entry-content">
<p><strong>StencylWorks</strong> is an easy way to visually create Flash and iOS games for non-coders and programmers alike. Starting with StencylWorks 1.2, developers can add Mochi Ads and scores to their games in just a few minutes!</p>
<h3 style="text-align: center;"><strong><a href="http://static.stencyl.com/content/Balloons.zip">Download the Sample Game</a></strong>&nbsp;</p>
<p><em>(Unzip and place “Balloons” folder under the StencylWorks “games” directory.)</em></h3>
<p>This balloon-popping game records how long it took for you to beat the (only) level. We’ll use Mochi to record the score on a leaderboard and show an ad after clicking the reset button.</p>
<h3>Sign up on Mochi’s Site</h3>
<p><a href="https://www.mochimedia.com/register/">Sign up on Mochi’s site</a> if you haven’t done so already.</p>
<h3>Add a Game on Mochi’s Site</h3>
<p>Each game you wish to support you must add to Mochi’s site.</p>
<p>1) Click the “Add Game” tab</p>
<p><a href="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-28-at-10.31.30-PM.png"><img class="alignnone size-full wp-image-382" style="border: 0px;" src="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-28-at-10.31.30-PM.png" alt="" width="103" height="46" /></a></p>
<p>2) Fill in the page as shown below and submit.</p>
<p><a href="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-28-at-10.32.58-PM.png"><img class="alignnone size-full wp-image-383" style="border: 0px;" src="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-28-at-10.32.58-PM.png" alt="" width="230" height="245" /></a></p>
<p>Stencyl games don’t function with Live Updates at this time.</p>
<p>&nbsp;</p>
<h3>Locate the game’s Mochi Game ID</h3>
<p>Every game has a unique game ID, so Mochi can identify it and store all of its data in one place. You can find the Game ID box on the game’s page.</p>
<p><a href="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-28-at-10.35.02-PM.png"><img class="alignnone size-full wp-image-384" style="border: 0px;" src="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-28-at-10.35.02-PM.png" alt="" width="165" height="94" /></a></p>
<p>To reach a game’s page, visit the Dashboard and click on the game’s name.</p>
<p>&nbsp;</p>
<h3>Enter the Mochi Game ID in to your game</h3>
<p>Now that you’ve set your game up on Mochi’s site, you need to enter in the game’s ID so it can establish a connection with Mochi’s servers to present ads and scores.</p>
<p>1) Open your game in StencylWorks.</p>
<p>2) Click on Advanced Settings under the Game Center tab. Enter the game’s Mochi Game ID.</p>
<p><a href="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-28-at-10.38.16-PM.png"><img class="alignnone size-medium wp-image-385" style="border: 0px;" src="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-28-at-10.38.16-PM-300x211.png" alt="" width="300" height="211" /></a></p>
<p>3) Save your game.</p>
<p>&nbsp;</p>
<h3>How to Display a Mochi Ad</h3>
<p>Displaying an ad is simple. Add the “show Mochi ad” block precisely at the time you wish to show the ad.</p>
<p><a href="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-31-at-8.40.19-PM.png"><img class="aligncenter size-full wp-image-402" style="border: 0px;" src="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-31-at-8.40.19-PM.png" alt="" width="262" height="36" /></a></p>
<p>For our Balloon game, we want to <strong>show an ad after clicking the reset button</strong>.</p>
<p>1) Open up the “MochiAd” behavior under Game Center &gt; Logic &gt; Scene Behaviors</p>
<p><a href="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-31-at-8.45.18-PM.png"><img class="aligncenter size-medium wp-image-405" style="border: 0px;" src="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-31-at-8.45.18-PM-300x109.png" alt="" width="300" height="109" /></a></p>
<p>This behavior instructs the game to display the ad right away. Our approach in this game is to set up a separate scene exclusively for displaying the ad, so that the ad doesn’t disrupt regular gameplay.</p>
<p><a href="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-31-at-8.38.02-PM.png"><img class="aligncenter size-medium wp-image-401" style="border: 0px;" src="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-31-at-8.38.02-PM-300x70.png" alt="" width="300" height="70" /></a></p>
<p>2) To make this behavior work, we need to attach it to a scene. Click “Attach to Scene” and choose “Ad Scene.”</p>
<p><a href="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-31-at-8.37.18-PM.png"><img class="aligncenter size-medium wp-image-400" style="border: 0px;" src="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-31-at-8.37.18-PM-300x219.png" alt="" width="300" height="219" /></a></p>
<p>3) Save and run the game. Notice the ad now appears after you click the Reset Button.</p>
<p><a href="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-31-at-8.36.02-PM.png"><img class="aligncenter size-medium wp-image-399" style="border: 0px;" src="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-31-at-8.36.02-PM-300x188.png" alt="" width="300" height="188" /></a></p>
<p>(Get an error? Jump to the bottom. Ad is a little slow in showing up? That’s normal when testing offline.)</p>
<p>&nbsp;</p>
<h3>How to Submit a Score and Display a Leaderboard</h3>
<p>Displaying a leaderboard requires setting up the leaderboard first on Mochi’s site.</p>
<p>1) Visit the Scores page for your game by clicking “Scores” in the sidebar.</p>
<p>2) Click “Add Leaderboard” – it’s a small button on the right-hand side of the page.</p>
<p><a href="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-28-at-10.45.39-PM.png"><img class="alignnone size-full wp-image-386" style="border: 0px;" src="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-28-at-10.45.39-PM.png" alt="" width="120" height="29" /></a></p>
<p>3) Fill in an appropriate title. Leave the rest of the fields as-is and submit.</p>
<p>4) Click on the “actionscript code” link on the next page.</p>
<p>5) Look for “Leaderboard Id” and copy it to your clipboard – this is what you’ll enter in to StencylWorks.</p>
<p>6) Now, open up the “MochiScores” behavior under Game Center &gt; Logic &gt; Scene Behaviors.</p>
<p><a href="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-31-at-8.46.44-PM.png"><img class="aligncenter size-medium wp-image-406" style="border: 0px;" src="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-31-at-8.46.44-PM-300x85.png" alt="" width="300" height="85" /></a></p>
<p>7) Locate the “submit score” block that’s already placed. Provide the Leaderboard Id you found in Step 5. For this game, we are recording how many seconds it took for you to pop all 40 balloons.</p>
<p><a href="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-31-at-8.41.48-PM.png"><img class="aligncenter size-full wp-image-403" style="border: 0px;" src="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-31-at-8.41.48-PM.png" alt="" width="484" height="75" /></a></p>
<p>8) To make this behavior work, we need to attach it to a scene. Click “Attach to Scene” and choose “First”</p>
<p><a href="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-31-at-8.51.47-PM.png"><img class="aligncenter size-medium wp-image-407" style="border: 0px;" src="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-31-at-8.51.47-PM-300x219.png" alt="" width="300" height="219" /></a></p>
<p>9) Save and run the game. The game will now show the leaderboard after finishing the level.</p>
<p><a href="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-31-at-8.43.23-PM.png"><img class="aligncenter size-medium wp-image-404" style="border: 0px;" src="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-31-at-8.43.23-PM-300x188.png" alt="" width="300" height="188" /></a></p>
<p>(Get an error? Jump to the bottom.)</p>
<h3>&nbsp;</p>
<p>What’s Next?</h3>
<p>Now that you’ve learned how to add scores and ads to your games, what’s next?</p>
<p><strong>Get Your Game Approved by Mochi</strong></p>
<p>You won’t start making money off those ads until your game’s been approved by Mochi. To get approval, you need to test game locally to present an ad and fill out your game profile on Mochi’s site. Mochi approves most games within 24 hours.</p>
<p><strong>Let Mochi Distribute Your Game</strong></p>
<p>Mochi not only maintains an ad network and APIs for its games, it also maintains a distribution network for Flash games, so your game can reach more players. It does this by offering feeds and embeddable “arcade” widgets that website owners can embed in their sites to present games relevant to their site.</p>
<p>To participate in this program, visit your game through the Dashboard and locate this box.</p>
<p style="text-align: center;"><a href="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-31-at-9.06.07-AM.png"><img class="size-full wp-image-395 aligncenter" style="border: 0px;" src="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-31-at-9.06.07-AM.png" alt="" width="394" height="107" /></a></p>
<h3>Troubleshooting: What to do if ads and scores do not show up, or if you receive an error.</h3>
<p>If you are testing locally, and want to be able to see ads or scores, you may need to do the following.</p>
<p>Add the location of your development files to your global security settings in the <a href="http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html" target="_blank">Adobe Flash Player Settings Manager</a>. This way, you can give all SWF files in this location <em>local-trusted</em> access, allowing access to both local and remote data.</p>
<p>The folder you want to add is the entire StencylWorks folder. This will catch everything underneath it, including the game itself. If you’ve chosen a custom workspace, you also need to add the folder for that.</p>
<p style="text-align: center;"><a href="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-31-at-9.21.22-AM.png"><img class="aligncenter size-full wp-image-396" style="border: 0px;" src="http://blog.stencyl.com/wp-content/uploads/2011/10/Screen-shot-2011-10-31-at-9.21.22-AM.png" alt="" width="405" height="279" /></a></p>
<p>&nbsp;</p>
<h2 style="text-align: center;"><a href="http://community.stencyl.com/index.php/topic,4308.0.html"></a><strong><a href="http://community.stencyl.com/index.php/topic,4308.0.html">Discuss this Article on our Forums!</a></strong></h2>
</div>
 <div class='series_toc'></div>	<p></p>
	<hr noshade style="margin:0;height:1px" />
	<p>&copy; JonathanChung for <a href="http://mochiland.com">MochiLand</a>, 2011. |
	  <a href="http://mochiland.com/articles/adding-mochi-ads-scores-to-a-stencyl-game">Permalink</a> |
	  <a href="http://mochiland.com/articles/adding-mochi-ads-scores-to-a-stencyl-game#comments">No comment</a></p>
	<p>Add to <a href="http://del.icio.us/post?url=http://mochiland.com/articles/adding-mochi-ads-scores-to-a-stencyl-game&amp;title=Adding Mochi Ads &amp; Scores to a Stencyl Game">del.icio.us</a></p>
	<p>Search blogs linking this post with <a href="http://www.technorati.com/search/http://mochiland.com/articles/adding-mochi-ads-scores-to-a-stencyl-game" title="Search on Technorati">Technorati</a></p>
	<p>Want more on these topics ? Browse the archive of posts filed under <a href="http://mochiland.com/category/mochiland/developer-feed" title="View all posts in Developer Feed" rel="category tag">Developer Feed</a>, <a href="http://mochiland.com/category/mochiland/flash" title="View all posts in Flash Development" rel="category tag">Flash Development</a>, <a href="http://mochiland.com/category/mochiland/game-design" title="View all posts in Game Design" rel="category tag">Game Design</a>, <a href="http://mochiland.com/category/mochiland" title="View all posts in MochiLand Topics" rel="category tag">MochiLand Topics</a>, <a href="http://mochiland.com/category/mochiland/tutorials" title="View all posts in Tutorials" rel="category tag">Tutorials</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://mochiland.com/articles/adding-mochi-ads-scores-to-a-stencyl-game/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building A Retro Platform Game In Flixel, Pt. 1</title>
		<link>http://mochiland.com/articles/building-a-retro-platform-game-in-flixel-pt-1</link>
		<comments>http://mochiland.com/articles/building-a-retro-platform-game-in-flixel-pt-1#comments</comments>
		<pubDate>Thu, 03 Nov 2011 20:26:24 +0000</pubDate>
		<dc:creator>Photon Storm</dc:creator>
				<category><![CDATA[Developer Feed]]></category>
		<category><![CDATA[Developer Spotlight]]></category>
		<category><![CDATA[Flash Development]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Game Design]]></category>
		<category><![CDATA[MochiLand Topics]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Flixel]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[Mochi Media]]></category>
		<category><![CDATA[Photon Storm]]></category>

		<guid isPermaLink="false">http://mochiland.com/?p=5618</guid>
		<description><![CDATA[Building a retro platform game in Flixel, Part 1 Note: This tutorial was originally written for .net magazine. I&#8217;m now allowed to publish it here, so read on and enjoy! Grab the files for download before starting! Retro style games are becoming more popular than ever online. Commonly referred to as &#8220;8-bit&#8221; these games have [...]]]></description>
			<content:encoded><![CDATA[ <p><strong>Building a retro platform game in Flixel, Part 1</strong></p>
<p>Note: This tutorial was <a title="My .net magazine " href="http://www.photonstorm.com/archives/1436/my-net-magazine-build-a-retro-game-in-flixel-article-is-now-out">originally written</a> for .net magazine. I&#8217;m now allowed to publish it here, so read on and enjoy! Grab the files for <a href="http://www.photonstorm.com/archives/2247/flash-game-dev-tip-12-building-a-retro-platform-game-in-flixel-part-1">download</a> before starting!</p>
<p>Retro style games are becoming more popular than ever online. Commonly referred to as &#8220;8-bit&#8221; these games have pixel-art graphics and &#8220;chip tune&#8221; music that apes the consoles of old, but often have surprisingly innovative gameplay mechanics. And Flash has turned out to be the perfect tool for creating them, as hit titles like <a href="http://adamatomic.com/canabalt/">Canabalt</a> and <a href="http://adamatomic.com/fathom" target="_blank">Fathom</a> demonstrate.</p>
<div id="attachment_2248" class="wp-caption alignnone" style="width: 417px"><img src="http://c251763.r63.cf3.rackcdn.com/wp-content/uploads/2011/09/Image-Fathom.png" alt="" /><p class="wp-caption-text">Fathom was one of the first games built with Flixel and is a good example of what it can do.</p></div>
<p>This may seem at odds with a technology known for its vector graphics and timeline animation. But under the hood Flash is perfectly capable of pushing around large volumes of pixels which is exactly what is required. Flixel is a game framework born from a desire to create 8-bit style games. But it has evolved into a powerful way to rapidly create games in Flash. With a strong community and plug-ins available it&#8217;s the perfect choice to create our game with. In this two part series we&#8217;ll explore how Flixel works and build a retro-styled platform game in the process.</p>
<p><a href="http://sandbox.photonstorm.com/netmag/Building%20a%20retro%20Flash%20game%20in%20Flixel%20Part%201.zip">Download the tutorial files</a> and look through the source code alongside reading the article, because for the sake of space not all of it can be included here and we&#8217;ve got a lot of ground to cover.</p>
<h2>Getting started</h2>
<p>For Windows users there is a guide on <a href="http://www.photonstorm.com/archives/1200/flash-game-dev-tip-6-setting-up-flashdevelop-and-flixel-for-the-first-time" target="_blank">installing FlashDevelop with Flixel</a>. On Mac OS X you can use Adobe Flash Builder. <a href="http://flashgamedojo.com/wiki/index.php?title=Hello_World_-_Flash_Builder_(Flixel)" target="_blank">FlashGameDojo has a tutorial</a> for this. Or run <a href="http://www.flashdevelop.org/community/viewtopic.php?f=9&amp;t=2463" target="_blank">FlashDevelop under Parallels</a>.</p>
<p>Even if you use FlashDevelop / Flash Builder already I&#8217;d still recommend following the guides so you become familiar with the Flixel package structure.</p>
<h2>Game Design Brief</h2>
<p>It helps to have a plan of your game <em>before</em> you start on it. While the plan should never restrict you from iterating your game during development, it will set a base ground on which to build. Here is a concise brief for our game:</p>
<p>&#8220;Player controls a chick who can run left/right and jump on platforms across a horizontally scrolling level. The environment is a lush green jungle with trees, grass, flowers and ruins to explore. There will be static and moving platforms and stars to collect. Collect enough stars and the level exit opens. Player cannot die by falling unless he hits the water. Animal baddies move around the platforms and are fatal to touch.&#8221;</p>
<p>From this brief we can instantly visualise how the game will look and play. This allows us to break the code structure into logical objects such as Player, Map, Star and Enemy. The artist can also create concept sketches to set the style of the game, and provide a point of reference for the pixel art.</p>
<div id="attachment_2249" class="wp-caption alignnone" style="width: 443px"><a href="http://c251763.r63.cf3.rackcdn.com/wp-content/uploads/2011/09/Image-Nutmeg-Concept-Sketches-433x480.jpg"><img class="size-medium wp-image-2249" style="border: 0px;" src="http://c251763.r63.cf3.rackcdn.com/wp-content/uploads/2011/09/Image-Nutmeg-Concept-Sketches-433x480.jpg" alt="" width="433" height="480" /></a><p class="wp-caption-text">Concept Sketches These help set a visual style for the game, introduce main characters and act as a reference for the pixel art.</p></div>
<h2>It starts with FlxGame</h2>
<p>Open <em>Main.as</em> from the &#8220;Part 1&#8243; source folder:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main <span style="color: #0033ff; font-weight: bold;">extends</span> FlxGame
<span style="color: #000000;">&#123;</span>
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">320</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">240</span><span style="color: #000066; font-weight: bold;">,</span> PlayState<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; font-weight:bold;">60</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
forceDebugger = <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: #000000;">&#125;</span></pre></div></div>

<p>FlxGame is the wrapper for your whole game, setting up Flixel in the process. The call to <em>super</em> sets the resolution of our game (320 x 240), the initial State (PlayState), the zoom level (2) and the frame rates (60 fps).</p>
<p>While 320 x 240 may seem small at a zoom level of 2 it will display at 640 x 480. The up-scaling of retro games is a common trait that helps show-off the detailed pixel art. <em>forceDebugger</em> enables the built-in debugger which is activated by pressing the &#8216; key. This lets you view bounding boxes, collision, paths, variables, logs and save out game replays.</p>
<p>Your game can have only one FlxGame class, but it can have many State<em>s</em>. States are a way to split your game into logical sections. For example a <em>MainMenuState</em>, a <em>PlayState</em> with the guts of the game and a <em>GameOverState</em>. Only one State can be active at a time.</p>
<h2>Getting into a right State</h2>
<p>States in Flixel extend FlxState and they are the guts of your game. When the State is initialised it calls the function <em>create</em>. This is used to construct any assets or variables the game needs. Once your game is running Flixel calls the <em>update</em> function every frame. In Flash terms it&#8217;s the equivalent of an Enter Frame event. Here is where you handle anything that needs to happen continuously. We&#8217;ll use it to detect collision between game objects.</p>
<p>Inside the <em>create</em> function we make two types of object: the Player sprite and some platforms.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">player = <span style="color: #0033ff; font-weight: bold;">new</span> Player<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">32</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">floor</span> = <span style="color: #0033ff; font-weight: bold;">new</span> FlxTileblock<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;">208</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">320</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">32</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">floor</span><span style="color: #000066; font-weight: bold;">.</span>makeGraphic<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">320</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">32</span><span style="color: #000066; font-weight: bold;">,</span> 0xff689c16<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span>player<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">floor</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>The <em>floor</em> variable is one such platform. Although we&#8217;ll replace it in the final game it&#8217;s a great rapid way to provide objects the player can jump on to test the physics. The objects are then added to the State, allowing Flixel to draw them when it renders the scene. It&#8217;s similar to <em>addChild</em> in native Flash and the order in which you add defines how they are drawn.</p>
<p>All player specific code is held in the Player class, represented here through the <em>player</em> variable. This keeps it organised and easy to re-use. Before we start that however we need to give our player some wings &#8211; quite literally &#8211; by preparing the sprite sheet.</p>
<div id="attachment_2250" class="wp-caption alignnone" style="width: 650px"><a href="http://c251763.r63.cf3.rackcdn.com/wp-content/uploads/2011/09/Image-Player-Sprite-Sheet-640x182.png"><img class="size-medium wp-image-2250" style="border: 0px;" src="http://c251763.r63.cf3.rackcdn.com/wp-content/uploads/2011/09/Image-Player-Sprite-Sheet-640x182.png" alt="" width="640" height="182" /></a><p class="wp-caption-text">Nutmeg The sprite sheet for the pixel hero of our game, drawn in 16 x 18 sized frames.</p></div>
<p>Flixel can automatically create reversed frames so we only draw him facing right. The first frame is an idle pose. Frames 2 and 3 are the walk cycle, and frame 4 is a hurt expression. If you are more comfortable animating inside of Flash Professional then you can create a timeline sequence as usual, export it to a SWF and use a tool such as Grant Skinner&#8217;s Zoe (<a href="http://easeljs.com/zoe.html">http://easeljs.com/zoe.html</a>) to convert it to a sprite sheet.</p>
<p>Sprites in Flixel are called FlxSprite which is what our Player extends. These differ from regular Flash Sprites in that as well as graphics data they contain extra values to allow you to easily control physics, animation, direction, collision and rotation. Inside Player.as we&#8217;ve embedded the sprite sheet:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span> = <span style="color: #990000;">'../assets/player.png'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> playerPNG<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Class</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>And then tell FlxSprite to use it:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">loadGraphic<span style="color: #000000;">&#40;</span>playerPNG<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">16</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">18</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></pre></div></div>

<p>This tells Flixel  to chop the sheet into 16&#215;18 frames and create reversed versions. Animation works in a similar way to Flash MovieClips.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">addAnimation<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;walk&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000;">&#91;</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: #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: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">10</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></pre></div></div>

<p>This creates a new animation sequence called &#8220;walk&#8221; which cycles through frames 0, 1, 0, 2 at a rate of 10 frames per second. The true parameter makes it loop. To play an animation you use its label:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #004993;">play</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;walk&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<h2>What goes up must come down</h2>
<p>Making the player sprite run and jump smoothly provides us with a great opportunity to explore ones of Flixel&#8217;s strengths: its plug-ins. Much like with WordPress and Drupal, the Flixel community release plug-ins which extend the framework further and ultimately save you time.</p>
<p>One such plug-in is FlxControl which is part of the Flixel Power Tools. They are included in the tutorial zips but are constantly updated, so check <a href="https://github.com/photonstorm/Flixel-Power-Tools" target="_blank">https://github.com/photonstorm/Flixel-Power-Tools</a> for updates. If downloading fresh there is a Getting Started guide in the Docs folder.</p>
<p>The plug-in needs to be activated and assigned to our player FlxSprite:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>FlxG<span style="color: #000066; font-weight: bold;">.</span>getPlugin<span style="color: #000000;">&#40;</span>FlxControl<span style="color: #000000;">&#41;</span> == <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
FlxG<span style="color: #000066; font-weight: bold;">.</span>addPlugin<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> FlxControl<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
FlxControl<span style="color: #000066; font-weight: bold;">.</span>create<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">,</span> FlxControlHandler<span style="color: #000066; font-weight: bold;">.</span>MOVEMENT_ACCELERATES<span style="color: #000066; font-weight: bold;">,</span> FlxControlHandler<span style="color: #000066; font-weight: bold;">.</span>STOPPING_DECELERATES<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: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>The parameters tell it that we want the sprite to accelerate and decelerate. If we didn&#8217;t pick this the sprite would start and stop immediately making the experience very abrupt.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">FlxControl<span style="color: #000066; font-weight: bold;">.</span>player1<span style="color: #000066; font-weight: bold;">.</span>setCursorControl<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">false</span><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: #0033ff; font-weight: bold;">true</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>
FlxControl<span style="color: #000066; font-weight: bold;">.</span>player1<span style="color: #000066; font-weight: bold;">.</span>setJumpButton<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;SPACE&quot;</span><span style="color: #000066; font-weight: bold;">,</span> FlxControlHandler<span style="color: #000066; font-weight: bold;">.</span>KEYMODE_PRESSED<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span> FlxObject<span style="color: #000066; font-weight: bold;">.</span>FLOOR<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">250</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
FlxControl<span style="color: #000066; font-weight: bold;">.</span>player1<span style="color: #000066; font-weight: bold;">.</span>setMovementSpeed<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">400</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: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">200</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: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
FlxControl<span style="color: #000066; font-weight: bold;">.</span>player1<span style="color: #000066; font-weight: bold;">.</span>setGravity<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;">400</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>This enables cursor control for the left and right keys, and sets SPACE BAR to be the jump button. The player can only jump if on the floor and will try to jump to a height of 200 pixels. setMovementSpeed allows the sprite to accelerate at 400px/sec up to top speed of 100px/sec. Modify these values to much lower or higher numbers to see the effect! Finally we set some gravity, pulling the player back down to earth. Try changing the gravity value to make the player float or drop like a lead balloon. The best thing you can do to learn about Flixel and its plug-ins is to mess around with them. You never know what might come out of it! I&#8217;ve seen whole game ideas born from what were code bugs, so it pays to experiment.</p>
<h2>Putting it all together</h2>
<p>Run the code at this point and you&#8217;ll see we have a cute little chick sprite who can run and leap around at will. It collides smoothly with the ground, and there&#8217;s even a platform to leap on. If you press the debug key (&#8216;) you can watch the physics values in real-time. Click the box icon in the top right to turn on the visual outlines.</p>
<div id="attachment_2251" class="wp-caption alignnone" style="width: 650px"><a href="http://c251763.r63.cf3.rackcdn.com/wp-content/uploads/2011/09/Image-Test-1.png"><img class="size-full wp-image-2251" style="border: 0px;" src="http://c251763.r63.cf3.rackcdn.com/wp-content/uploads/2011/09/Image-Test-1.png" alt="" width="640" height="480" /></a><p class="wp-caption-text">We have lift off! A running and jumping player with platforms to leap on</p></div>
<p>Granted it isn&#8217;t quite Mario, but we&#8217;re not finished just yet.</p>
<h2>Building a Level Map with DAME</h2>
<p>Green blocks are all well and good, but we need a proper level for the player to explore. Flixel has built-in support for Tile Maps which are an efficient and fast way to construct game levels. Tile Maps work by using Tile Set in a series of tiles aligned to a fixed-size grid. Here is the Tile Set created for our game:</p>
<div id="attachment_2252" class="wp-caption alignnone" style="width: 650px"><a href="http://c251763.r63.cf3.rackcdn.com/wp-content/uploads/2011/09/Image-Tileset-640x202.png"><img class="size-medium wp-image-2252" style="border: 0px;" src="http://c251763.r63.cf3.rackcdn.com/wp-content/uploads/2011/09/Image-Tileset-640x202.png" alt="" width="640" height="202" /></a><p class="wp-caption-text">The Tile Set used to draw the game map, complete with water, plants and platforms.</p></div>
<p>Each tile is 16&#215;16 pixels in size, and you can see that some of them join together to form game objects such as the platform in the bottom right. The organisation of the Tile Set is up to you (or your artist!), but it&#8217;s sensible to leave big chunks of empty tiles should you need to insert new tiles later on in development. Tiles are separated into two types: Tiles you can collide with, and tiles you never collide with. In Flixel this is determined by the tile number and is called the Collide Index. Every tile after the index is treated as a tile you collide with. In our Tile Set you&#8217;ll see on the top row items such as flowers, bushes and shrubs. These are all non-colliding tiles, as we don&#8217;t want our player getting stuck on flowers.</p>
<p>With our Tile Set created we now need to design the level. To do this we use a Tile Map Editor. For this tutorial we&#8217;ll use an editor called DAME. Although the interface takes some getting used-to, the actual map view in DAME is rendered directly with Flixel so you know for sure that what you see in the editor is how it appears in game.</p>
<p>DAME can be downloaded from <a href="http://dambots.com/dame-editor/" target="_blank">http://dambots.com/dame-editor/</a> and works on Windows, OS X and Linux. Create 3 map layers in DAME, one for the Sky background, one for the level itself and one for the stars which the player can collect. You can find our DAME maps by downloading the tutorial files and looking in &#8220;Nutmeg Part 2 &#8211; The Map&#8221;. With the Map Layer selected click on a tile in the Tile window and then paint with it, just like an art package:</p>
<div id="attachment_2253" class="wp-caption alignnone" style="width: 650px"><a href="http://c251763.r63.cf3.rackcdn.com/wp-content/uploads/2011/09/Map-Editing-with-Dame-640x360.png"><img class="size-medium wp-image-2253" style="border: 0px;" src="http://c251763.r63.cf3.rackcdn.com/wp-content/uploads/2011/09/Map-Editing-with-Dame-640x360.png" alt="" width="640" height="360" /></a><p class="wp-caption-text">Tile Map Editor DAME in action showing part of the level created for the game</p></div>
<p>Once you are happy with the design of your level you can export the map data to a CSV file from the File ñ Export menu.</p>
<h2>Lights, Camera, Action</h2>
<p>Add a new class to the project called Level1 that extends FlxGroup. This is Flixel&#8217;s way of grouping display objects together and keeps our code logical and structured. We can also check for collision against a whole group, which is significantly faster than checking every element individually. Our map is held in a local variable:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #004993;">map</span> = <span style="color: #0033ff; font-weight: bold;">new</span> FlxTilemap<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">map</span><span style="color: #000066; font-weight: bold;">.</span>loadMap<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> mapCSV<span style="color: #000066; font-weight: bold;">,</span> mapTilesPNG<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">16</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">16</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: #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: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">31</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">map</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>loadMap takes our CSV map data exported from DAME, and an embedded Tile Set png and creates a Tile Map object which is then added to the group. The same process is repeated for the Sky background.</p>
<p>Back in the PlayState we add the level to the display. But before we can unleash the player we tell Flixelís camera system to follow them around and restrict the camera to the map boundary:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">FlxG<span style="color: #000066; font-weight: bold;">.</span>camera<span style="color: #000066; font-weight: bold;">.</span>setBounds<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;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">level</span><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: #004993;">level</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
FlxG<span style="color: #000066; font-weight: bold;">.</span>camera<span style="color: #000066; font-weight: bold;">.</span>follow<span style="color: #000000;">&#40;</span>player<span style="color: #000066; font-weight: bold;">,</span> FlxCamera<span style="color: #000066; font-weight: bold;">.</span>STYLE_PLATFORMER<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>The last task is to add a collision check into the PlayState update function:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">FlxG<span style="color: #000066; font-weight: bold;">.</span>collide<span style="color: #000000;">&#40;</span>player<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">level</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>With the map loaded, the camera set and collision running we can now test the game. The chick now happily bounces around the level, landing on platforms and not colliding with flowers.</p>
<h2>Sprinkling a little stardust</h2>
<p>Now we&#8217;ve a pretty landscape to traverse we&#8217;ll add stars for the player to collect, and display the total collected as a score in the game. Flixel has a text function called FlxText which we use to display the score:</p>
<p>&gt;</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">score = <span style="color: #0033ff; font-weight: bold;">new</span> FlxText<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;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
score<span style="color: #000066; font-weight: bold;">.</span>scrollFactor<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
score<span style="color: #000066; font-weight: bold;">.</span>scrollFactor<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>The score is added at the top left of the screen and has a scrollFactor of zero. This means the text will be locked in place at the coordinates given, and not scroll around as the camera moves.</p>
<p>In the DAME map the Stars layer was exported to a CSV file and weíll use this map data to create Star sprites. The function parseStars in the Level1 class works by looping through the CSV map data, and for every tile it creates a new Star sprite at those coordinates. All of these sprites are added to an FlxGroup called stars. In the PlayState update function we check to see if the player is colliding with a star:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">FlxG<span style="color: #000066; font-weight: bold;">.</span>overlap<span style="color: #000000;">&#40;</span>player<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">level</span><span style="color: #000066; font-weight: bold;">.</span>stars<span style="color: #000066; font-weight: bold;">,</span> hitStar<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>If a collision occurs this will call the function hitStar, passing in the two objects that collided, in this case the player and the star he hit. The star is removed from the game and the score increased:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">star<span style="color: #000066; font-weight: bold;">.</span>kill<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
FlxG<span style="color: #000066; font-weight: bold;">.</span>score <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>
score<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = FlxG<span style="color: #000066; font-weight: bold;">.</span>score<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot; / &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">level</span><span style="color: #000066; font-weight: bold;">.</span>totalStars<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>Finally the score text is updated to show them how many stars they&#8217;ve collected, and how many are left. With this one small addition we&#8217;ve now got a real playable game with an objective to collect all stars:</p>
<div id="attachment_2254" class="wp-caption alignnone" style="width: 650px"><a href="http://c251763.r63.cf3.rackcdn.com/wp-content/uploads/2011/09/nutmeg_preview1.png"><img class="size-full wp-image-2254" style="border: 0px;" src="http://c251763.r63.cf3.rackcdn.com/wp-content/uploads/2011/09/nutmeg_preview1.png" alt="" width="640" height="480" /></a><p class="wp-caption-text">Reach for the stars With the stars in place our game now has a purpose - try to complete the level</p></div>
<p>In part 2 we will introduce baddies for you to avoid, sound effects, a user interface (HUD) and Game Over sequence. If you feel inspired to build your own games be sure to visit <a href="http://flixel.org" target="_blank">http://flixel.org</a> which is home to a vibrant developer community. You&#8217;ll also find stacks of Flixel related tutorials at <a href="http://www.photonstorm.com" target="_blank">http://www.photonstorm.com</a> along with the Flixel Power Tools plug-ins. Finally for reference to the classic games of old <a href="http://www.retrogamingtimes.com" target="_blank">http://www.retrogamingtimes.com</a> is well worth a visit.</p>
<p>The following 2 parts were the &#8220;box-outs&#8221; that appeared in the print article. I&#8217;ve included them here because they&#8217;re interesting :)</p>
<h2>Adam Saltsman talks about why he created Flixel</h2>
<p>I guess it was around 7 years ago that I tried to make a little &#8220;game engine&#8221;, something that would allow me to make Super NES style games. It just seemed like a fun thing to do. After a few abortive attempts in C++ / Python / Java I finally settled on AS3. It was the pixel-level stuff in it that really interested me. However I&#8217;d grown very cautious about &#8220;engine building&#8221; and not actually making any games. So I stuck with AS3 and created game after game, and noticed which patterns evolved. The games kept getting more complex, and re-used code from previous projects, and eventually those parts I was seeing in every project got moved to their own folder. I think a lot (if not most) developers have a similar folder somewhere, just a pile of &#8220;really handy&#8221; code.</p>
<p>Originally this was just for me, something I&#8217;d use to sketch new game designs in. But it wasn&#8217;t long before I thought that with a little polish here and there I might be able to release it publicly. Turns out it needed a lot of polish (and still does), but I really like where it&#8217;s going. Lately I have been thinking a lot about how to &#8220;make stuff that matters&#8221;, which is a very loose idea, but something I obsess over, for better or worse. I think Flixel is a cool thing. It&#8217;s not really &#8220;art&#8221; in and of itself, but it contributes to the cultural food chain, and that makes me feel like a hero.</p>
<p>Eventually it would be great to add official support for a physics engine like Nape, and port it over to Molehill, the hardware-accelerated Flash Player by the end of the year. I am very hesitant to ever add game-specific features to the framework, but these all seem like good general systems and will just make making games easier and more fun.</p>
<p>At the risk of leaving out something awesome I would say the following games are shining examples of Flixel in action:</p>
<p><a href="http://adamatomic.com/canabalt/" target="_blank">Canabalt</a><br />
<a href="http://patkemp.com/wp-gallery/games/Station38.html" target="_blank">Station 38</a><br />
<a href="http://www.newgrounds.com/portal/view/522276" target="_blank">Tuper Tario Tros</a><br />
<a href="http://www.newgrounds.com/portal/view/555641" target="_blank">Cat Astro Phi</a></p>
<div id="attachment_2255" class="wp-caption alignnone" style="width: 539px"><a href="http://c251763.r63.cf3.rackcdn.com/wp-content/uploads/2011/09/Image-Box-Out-1-Cat-Astro-Phi-529x480.png"><img class="size-medium wp-image-2255" style="border: 0px;" src="http://c251763.r63.cf3.rackcdn.com/wp-content/uploads/2011/09/Image-Box-Out-1-Cat-Astro-Phi-529x480.png" alt="" width="529" height="480" /></a><p class="wp-caption-text">Cat Astro Phi Designed to look, sound and feel like a Gameboy Classic title it&#39;s a good example of what Flixel is capable of.</p></div>
<h2>Pushing Pixels</h2>
<h3>Mastering the style of pixel art</h3>
<p>Professional pixel artist Ilija Melentijevic explains how he created the artwork for Nutmeg:</p>
<p>Pixel art is a time-consuming but rewarding approach to creating game graphics. If you have little screen space such as on a mobile device, or are simply looking for that charm and precision it offers, then itís worth making the extra effort. Also, it&#8217;s incredibly fun!</p>
<p>It&#8217;s a good idea to start from the big picture. First make a mock-up of a game scene, defining the style, colours, characters, etc. Once you have such solid foundation it&#8217;s easy to turn it into actual game assets. Your art must fit and enhance the game, not just look nice on its own, so make sure everything reads well and speaks to the player in a consistent way. In a busy shooter, use colours to separate bullets from power-ups, or to make the foreground objects pop out. Immersion is a priority in any game, and understanding what&#8217;s going on plays a big part in this. Fire up your favourite games and look how the pros do it.</p>
<p>There are a number of tools you can use and they vary widely. Some people even use Microsoft Paint! Many professionals use Photoshop and it certainly gets the job done, but I prefer a dedicated pixel-oriented program. Closest to the industry standard is <a href="http://cosmigo.com" target="_blank">Cosmigo Promotion</a> which boasts an impressive set of features and will look familiar to Photoshop users. My personal favourite is the 100% free <a href="http://code.google.com/p/grafx2" target="_blank">GraFX2</a>. Currently it lacks animation, but otherwise provides for an unparalleled workflow and ease of use.</p>
<p>Make sure you join an active pixel art community that will provide both feedback and motivation. <a href="http://www.pixeljoint.com" target="_blank">PixelJoint</a> lets you comment, rate and vote on other people&#8217;s work, submit your own, and even take part in weekly challenges, perhaps the best way to hone your skills.</p>
<p>For a less casual approach consider <a href="http://pixelation.wayofthepixel.net" target="_blank">Pixelation</a>, a community focused on pushing the medium forward. Here you&#8217;ll find discussions on theory, game art analysis, collaborations and more. Many masters of the form frequent the forum, so it&#8217;s a great place to post your work to get some constructive critique.</p>
<p>View Ilija&#8217;s artwork at <a href="http://www.photonstorm.com/topics/art" target="_blank">http://www.photonstorm.com/topics/art</a></p>
<div id="attachment_2256" class="wp-caption alignnone" style="width: 650px"><a href="http://c251763.r63.cf3.rackcdn.com/wp-content/uploads/2011/09/Box-Out-2-Grafx2-640x457.png"><img class="size-medium wp-image-2256" style="border: 0px;" src="http://c251763.r63.cf3.rackcdn.com/wp-content/uploads/2011/09/Box-Out-2-Grafx2-640x457.png" alt="" width="640" height="457" /></a><p class="wp-caption-text">GraFX2 A lightweight and free (as in free beer) pixel-pushing program for Windows, Mac and Linux</p></div>
 <div class='series_toc'></div>	<p></p>
	<hr noshade style="margin:0;height:1px" />
	<p>&copy; Photon Storm for <a href="http://mochiland.com">MochiLand</a>, 2011. |
	  <a href="http://mochiland.com/articles/building-a-retro-platform-game-in-flixel-pt-1">Permalink</a> |
	  <a href="http://mochiland.com/articles/building-a-retro-platform-game-in-flixel-pt-1#comments">6 comments</a></p>
	<p>Add to <a href="http://del.icio.us/post?url=http://mochiland.com/articles/building-a-retro-platform-game-in-flixel-pt-1&amp;title=Building A Retro Platform Game In Flixel, Pt. 1">del.icio.us</a></p>
	<p>Search blogs linking this post with <a href="http://www.technorati.com/search/http://mochiland.com/articles/building-a-retro-platform-game-in-flixel-pt-1" title="Search on Technorati">Technorati</a></p>
	<p>Want more on these topics ? Browse the archive of posts filed under <a href="http://mochiland.com/category/mochiland/developer-feed" title="View all posts in Developer Feed" rel="category tag">Developer Feed</a>, <a href="http://mochiland.com/category/mochiland/developer-spotlight" title="View all posts in Developer Spotlight" rel="category tag">Developer Spotlight</a>, <a href="http://mochiland.com/category/mochiland/flash" title="View all posts in Flash Development" rel="category tag">Flash Development</a>, <a href="http://mochiland.com/category/mochiland/front-page" title="View all posts in Front Page" rel="category tag">Front Page</a>, <a href="http://mochiland.com/category/mochiland/game-design" title="View all posts in Game Design" rel="category tag">Game Design</a>, <a href="http://mochiland.com/category/mochiland" title="View all posts in MochiLand Topics" rel="category tag">MochiLand Topics</a>, <a href="http://mochiland.com/category/mochiland/tutorials" title="View all posts in Tutorials" rel="category tag">Tutorials</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://mochiland.com/articles/building-a-retro-platform-game-in-flixel-pt-1/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Recap: Mochi London 2011</title>
		<link>http://mochiland.com/articles/recap-mochi-london-2011</link>
		<comments>http://mochiland.com/articles/recap-mochi-london-2011#comments</comments>
		<pubDate>Mon, 19 Sep 2011 20:43:17 +0000</pubDate>
		<dc:creator>ChrisJeff</dc:creator>
				<category><![CDATA[Developer Feed]]></category>
		<category><![CDATA[Flash Development]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Game Design]]></category>
		<category><![CDATA[Games Industry]]></category>
		<category><![CDATA[Mochi Media Announcements]]></category>
		<category><![CDATA[MochiLand Topics]]></category>
		<category><![CDATA[Publisher Feed]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[Mochi London]]></category>
		<category><![CDATA[Mochi Media]]></category>
		<category><![CDATA[portal]]></category>
		<category><![CDATA[publisher]]></category>

		<guid isPermaLink="false">http://mochiland.com/?p=5499</guid>
		<description><![CDATA[&#160; What Is Mochi London? Mochi London has been held for 3 consecutive years now as a community-driven Flash game developer meetup averaging 8-12 attendees, and has traditionally resulted in open conversations with regards to Flash game development. Ernesto Quezada and myself have been to every single one, with Ernesto serving as the organizer the [...]]]></description>
			<content:encoded><![CDATA[ <h1 style="text-align: left;"><a href="http://chris-jeff.com/wp-content/uploads/2011/07/mochilondon-logo_big.png"><img class="size-full wp-image-597 aligncenter" style="border: 0px;" title="mochilondon-logo_big" src="http://chris-jeff.com/wp-content/uploads/2011/07/mochilondon-logo_big.png" alt="mochilondon-logo_big" width="185" height="225" /></a></h1>
<p>&nbsp;</p>
<h1><span class="summary">What Is Mochi London?</span></h1>
<p>Mochi London has been held for 3 consecutive years now as a community-driven Flash game developer meetup averaging 8-12 attendees, and has traditionally resulted in open conversations with regards to Flash game development. Ernesto Quezada and myself have been to every single one, with Ernesto serving as the organizer the past two years. Well things changed in 2011 after Ernesto and I had a little conversation- we wanted this year to be bigger and better than before!</p>
<h2>Who Are We?</h2>
<p>I&#8217;ll start off with myself! My name is Chris Jeffrey, I&#8217;m a Games Developer based in the United Kingdom. I primarily develop on the Flash platform, however as of late I&#8217;ve also started porting games over to iOS &amp; Android platforms as well. I&#8217;ve been using Flash for around 5 years in total and developed games casually for approximately 3 of those years.</p>
<p>However! More recently I&#8217;ve actually made a bold move and actually left my job to go full-time indie, so I&#8217;m really looking forward to having the chance to devote all of my time to development. Apparently the content I throw out can be somewhat successful, ranging from 4-8m impressions in their life cycle, but if you want to know more and hear me blabber on, head over to <a href="http://www.chris-jeff.com" target="_blank">chris-jeff.com</a>, where I dribble in the form of blog posts! You can also find me on <a href="http://www.twitter.com/chrisjeffgames" target="_blank">Twitter</a>.</p>
<p>Ernesto Quezada is a Games Developer/Publisher from El Salvador. He started using Flash in version 4 back in the late 90&#8242;s. In 2002 he moved to London. After learning a bit of English, in 2005 he went on to get his Masters degree in Digital Media at the London Metropolitan University. Even though he&#8217;s been working professionally as a Flash developer since 2006, his graphic design background still stops him from moving completely to the dark side so he&#8217;s still a bit scared of the command line which, anyway, he uses at work on a daily basis. He&#8217;s created about 30 games in the past 10 years (and has drank a lot of tequila on the way&#8230;). Check out his portal over at <a href="http://games-garden.com" target="_blank">games-garden.com</a>.</p>
<div id="attachment_606" class="wp-caption alignleft" style="width: 590px"><a href="http://chris-jeff.com/wp-content/uploads/2011/09/pict0032.jpg"><img class="size-full wp-image-606         " style="border: 0px;" title="Mochi London 2008" src="http://chris-jeff.com/wp-content/uploads/2011/09/pict0032.jpg" alt="First meet up in 2008" width="580" height="436" /></a><p class="wp-caption-text">First meet up in 2008</p></div>
<h2>Why London?</h2>
<p>Exactly! It&#8217;s what I ask myself. Personally, Mochi Newcastle seemed much more appealing (I live in Newcastle). Honestly though London is a great place and we thought it would be a more convenient location for the majority of people, plus it has the added tourist incentive for people to see the sights and such. Previous Mochi London meetups have generally been with developers in and around the London area, so we didn&#8217;t feel a need for our 4th event to be anywhere else!</p>
<h2>The Venue</h2>
<p>Ernesto, the London local (and official Mochi London tour guide) received a really good tip on this one. After he checked it out and shared pictures of it with the rest of us, we knew right away that this was the right place. Plus, the venue itself was relatively close to a tube station and a pub. Perfect, right? The inside was just right for the crowd we&#8217;d anticipated, it seated everyone pretty comfortably without people being too cramped or too spread out. Kings College London also catered the event, which meant that we didn&#8217;t have to get catering from another vendor.</p>
<p><strong>So a big thanks to Mochi with helping us out with the venue, food, &amp; beverages for the event! :)<br />
</strong></p>
<div id="attachment_714" class="wp-caption aligncenter" style="width: 490px"><a href="http://chris-jeff.com/wp-content/uploads/2011/09/6107352518_ce3a6b2c1b_z.jpg"><img class="size-full wp-image-714" style="border: 0px;" title="Chowline" src="http://chris-jeff.com/wp-content/uploads/2011/09/6107352518_ce3a6b2c1b_z.jpg" alt="The line for lunch! Nom." width="480" height="640" /></a><p class="wp-caption-text">The line for lunch! Nom.</p></div>
<h2>First Steps</h2>
<p>We started to discuss potential ideas of ramping up the meetup and getting it to a level where we could potentially attract more attendees than just the regular handful. We toyed with the idea of getting sponsors and going down that route of making it more of an official conference than just a meet up, but that whole idea didn&#8217;t really appeal to us, we wanted a more official meet up, however still cater to the whole idea of it being by developers for developers. We settled on the idea that it would be best to get Mochi Media directly involved, especially since this was coming directly from their community! However, we still wanted to keep the whole conference style and not just sitting in a pub, so we threw ideas around about getting a venue and speakers and making a whole day out of it.<br />
We were moving in a different direction from the typical meetups, a direction that I was really excited about! That said, we still liked the <em>idea</em> of our pub meetup (Being from Newcastle I guess maybe?) So we ended up including the pub portion as well and made it a two day event to keep with Mochi London tradition.</p>
<div id="attachment_735" class="wp-caption aligncenter" style="width: 590px"><a href="http://chris-jeff.com/wp-content/uploads/2011/09/6107323626_9b837d414b_z.jpg"><img class="size-full wp-image-735 " style="border: 0px;" title="6107323626_9b837d414b_z" src="http://chris-jeff.com/wp-content/uploads/2011/09/6107323626_9b837d414b_z.jpg" alt="Merlin Gore - Importance of personal branding - As you can see, I'm all branded, Huzah!" width="580" height="436" /></a><p class="wp-caption-text">Merlin Gore - Importance of personal branding - As you can see, I&#39;m all branded, Huzah!</p></div>
<h2>Speakers</h2>
<p>Once we had the idea locked down, it was time to get the event pumped with solid content that would get the Flash games community excited about the event! For some, this can be a pretty daunting and time consuming experience- trying to get quality speakers with content people actually want is no easy task. My approach: I kept it real simple and just thought of what I&#8217;d want to hear! Sounds a little egocentric, but I&#8217;m an indie developer and I know exactly what I&#8217;d want to hear and from who- so why not get them to speak!? Makes sense, right?</p>
<div id="attachment_726" class="wp-caption aligncenter" style="width: 590px"><a href="http://chris-jeff.com/wp-content/uploads/2011/09/6107354042_dc2bc5fee9_o1.jpg"><img class="size-full wp-image-726 " style="border: 0px;" title="The day!" src="http://chris-jeff.com/wp-content/uploads/2011/09/6107354042_dc2bc5fee9_o1.jpg" alt="Day 1 schedule!" width="580" height="436" /></a><p class="wp-caption-text">Day 1 schedule! - Look how far we&#39;ve come!</p></div>
<p>We ended up with a pretty strong line up of speakers, with content that covers a wide variety of topics within the Flash games industry. Perfect in my eyes!</p>
<blockquote>
<ul>
<li>Iain Lobb (freelance Flash / ActionScript developer)</li>
<li>Stuart Allen (creator of Gravitee Wars)</li>
<li>Martine Spaans (Ubisoft, formerly of SPIL Games)</li>
<li>Michael Hudson &amp; Steven Gurevitz (CodeHeads / 2002 studios)</li>
<li>Merlin Gore (Flash developer, FlashGameLicense.com)</li>
<li>Mike Jones (Platform Evangelist, Adobe Systems)</li>
<li>Colin Cupp &amp; Ryan Nichols (Mochi Media)</li>
</ul>
</blockquote>
<h2>Day of the Event!</h2>
<p>A few of us kicked off the day a little earlier in order to get set up and also to ensure that everything was in proper working order. Registration opened at 9:00am and it wasn&#8217;t long after that when we started to see people arrive! Personally I felt really great when people started flooding in, as beating 8 attendees for a community event is a milestone for Mochi London ;). And they didn&#8217;t stop- we ended up with about 50+ people eager for the antics that the day would bring, in the form of presentations of course.</p>
<div id="attachment_639" class="wp-caption aligncenter" style="width: 590px"><a href="http://chris-jeff.com/wp-content/uploads/2011/09/6107323378_c4ed9bf6ea_o.jpg"><img class="size-full wp-image-639  " style="border: 0px;" title="6107323378_c4ed9bf6ea_o" src="http://chris-jeff.com/wp-content/uploads/2011/09/6107323378_c4ed9bf6ea_o.jpg" alt="Mochi London 2011" width="580" height="436" /></a><p class="wp-caption-text">Mochi London 2011 - All the happy faces :)</p></div>
<p>I honestly feel the day couldn&#8217;t have gone any better, unless we actually went to Nando&#8217;s afterwards (inside joke and my personal obsession)!! All the speakers were started on-time and covered their topics extremely well. Questions were asked by engaged attendees, and they received some really in-depth responses. There were moments when the conversation moved from the presenters out to the audience, which was exactly the type of attendee interaction we were hoping for. Overall, the whole day was really informative and went exactly to plan (minus Nando&#8217;s, not fair!).</p>
<h2>Day Two</h2>
<p>The day that consisted of drinks and random chats about Flash game development, experiences and stat sharing! Exactly what Mochi London started off as, so this couldn&#8217;t go wrong at all! We totally kept up with tradition and met up at the<span> <a href="http://www.jdwetherspoon.co.uk/home/pubs/the-montagu-pyke">Montagu Pyke pub</a> which is where the first meet up was held! It&#8217;s a nice, open venue with a solid Sunday roast&#8230;and it&#8217;s reasonably priced!</span></p>
<p>We met up at 8pm and finished at around 10:30pm, then  went on the hunt for food! Of course, I suggested Nando&#8217;s (As always!), however we missed it by around 5 minutes, I&#8217;m not sure what I&#8217;ve done, but karma wasn&#8217;t on my side for that day! Or the day before&#8230;</p>
<div class="mceTemp mceIEcenter">
<dl id="attachment_668" class="wp-caption aligncenter" style="width: 509px;">
<p class="wp-caption-dt" style="text-align: center;"><a href="http://chris-jeff.com/wp-content/uploads/2011/09/6106804911_1656b7a58a_o.jpg"><img class="size-full wp-image-668  " style="border: 0px;" title="6106804911_1656b7a58a_o" src="http://chris-jeff.com/wp-content/uploads/2011/09/6106804911_1656b7a58a_o.jpg" alt="Day one meal. Eating Ramen with a fork is how we do it up North!" width="499" height="374" /></a></p>
<dd class="wp-caption-dd">Day one meal. Eating Ramen with a fork is how we do it up North!</dd>
</dl>
</div>
<h2>Closing Thoughts</h2>
<p>I personally thought the whole event went to plan- in fact, it couldn&#8217;t have gone any better as far as I&#8217;m concerned! This was a great step for Mochi London. We&#8217;re definitely going to be preparing for Mochi London 2012 due to the popularity of this year&#8217;s event! My hope is to be able to take it up another notch with more quality speakers who have a strong presence in the Flash games industry, as well as keeping the event as fun and informative as possible. In the end, Mochi London is all about the community.</p>
<p>So on that note, Mochi London 2012 anyone?!</p>
<div id="attachment_723" class="wp-caption aligncenter" style="width: 590px"><a href="http://chris-jeff.com/wp-content/uploads/2011/09/6106804529_f0ea422f14_o.jpg"><img class="size-full wp-image-723" title="Robinson!" style="border: 0px" src="http://chris-jeff.com/wp-content/uploads/2011/09/6106804529_f0ea422f14_o.jpg" alt="6106804529_f0ea422f14_o" width="580" height="436" /></a><p class="wp-caption-text">Robinson and his heroic efforts at manning the reception booth, thanks Robinson!</p></div>
<p>I&#8217;d love to hear thoughts and ideas for next year, we want to make it even better! Feel free to <a href="http://chris-jeff.com/contact/" target="_blank">contact me!</a></p>
<p>I&#8217;d also like to thank everyone involved in making Mochi London 2011 what is was on the day! From the Mochi Media team, to the speakers, and most importantly to the attendees who turned up- thanks everyone!</p>
<p>&nbsp;</p>
<h2>Presentations? We Have Presentations!</h2>
<p>Check out the presentation slides from the speakers of Mochi London 2011</p>
<h4>
<div style="width:425px" id="__ss_9261072"> <strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/mochimedia/mobile-gaming-is-it-the-future-by-michael-hudson-and-steven-gurevitz" title="Mobile Gaming: Is It The Future? by Michael Hudson and Steven Gurevitz" target="_blank">Mobile Gaming: Is It The Future? by Michael Hudson and Steven Gurevitz</a></strong> <iframe src="http://www.slideshare.net/slideshow/embed_code/9261072" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<div style="padding:5px 0 12px"> View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/mochimedia" target="_blank">mochimedia</a> </div>
</p></div>
<div style="width:425px" id="__ss_9261055"> <strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/mochimedia/gravitee-wars-post-mortem-by-stuart-allen-of-funky-pear" title="Gravitee Wars Post Mortem by Stuart Allen of FunkyPear" target="_blank">Gravitee Wars Post Mortem by Stuart Allen of FunkyPear</a></strong> <iframe src="http://www.slideshare.net/slideshow/embed_code/9261055" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<div style="padding:5px 0 12px"> View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/mochimedia" target="_blank">mochimedia</a> </div>
</p></div>
<div style="width:425px" id="__ss_9261069"> <strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/mochimedia/martine-spaans" title="Player Behaviour by Martine Spaans" target="_blank">Player Behaviour by Martine Spaans</a></strong> <iframe src="http://www.slideshare.net/slideshow/embed_code/9261069" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<div style="padding:5px 0 12px"> View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/mochimedia" target="_blank">mochimedia</a> </div>
</p></div>
<div style="width:425px" id="__ss_9261067"> <strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/mochimedia/iain-lobb" title="Game Design for Game Developers by Iain Lobb" target="_blank">Game Design for Game Developers by Iain Lobb</a></strong> <iframe src="http://www.slideshare.net/slideshow/embed_code/9261067" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<div style="padding:5px 0 12px"> View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/mochimedia" target="_blank">mochimedia</a> </div>
</p></div>
<div style="width:425px" id="__ss_9261071"> <strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/mochimedia/the-importance-of-personal-branding-by-merlin-gore" title="The Importance of Personal Branding by Merlin Gore" target="_blank">The Importance of Personal Branding by Merlin Gore</a></strong> <iframe src="http://www.slideshare.net/slideshow/embed_code/9261071" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<div style="padding:5px 0 12px"> View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/mochimedia" target="_blank">mochimedia</a> </div>
</p></div>
<div style="width:425px" id="__ss_9261062"> <strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/mochimedia/colin-ryan" title="What&#39;s New At Mochi! by Colin Cupp and Ryan Nichols" target="_blank">What&#39;s New At Mochi! by Colin Cupp and Ryan Nichols</a></strong> <iframe src="http://www.slideshare.net/slideshow/embed_code/9261062" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<div style="padding:5px 0 12px"> View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/mochimedia" target="_blank">mochimedia</a> </div>
</p></div>
<div style="width:425px" id="__ss_9178678"> <strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/FlashGen/mochi-london-2011" title="Mochi London 2011" target="_blank">Mochi London 2011</a></strong> <iframe src="http://www.slideshare.net/slideshow/embed_code/9178678" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<div style="padding:5px 0 12px"> View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/FlashGen" target="_blank">Mike Jones</a> </div>
</p></div>
</h4>
<h3>Pictures!</h3>
<p>Check out the pictures on <a href="http://www.flickr.com/photos/mochimedia/sets/72157627454485113/" target="_blank">Mochi&#8217;s phototstream</a> to see pictures taken throughout the weekend!</p>
<h3>Videos</h3>
<p>I&#8217;ll be sharing the videos of the speakers in a later post as we&#8217;ve got to get all the footage in one place and edit a bit (as it&#8217;s recorded from a tablet). So keep an eye out! :)</p>
<p>&nbsp;<br />
<strong><em>Thanks for reading!</em><br />
</strong></p>
 <div class='series_toc'></div>	<p></p>
	<hr noshade style="margin:0;height:1px" />
	<p>&copy; ChrisJeff for <a href="http://mochiland.com">MochiLand</a>, 2011. |
	  <a href="http://mochiland.com/articles/recap-mochi-london-2011">Permalink</a> |
	  <a href="http://mochiland.com/articles/recap-mochi-london-2011#comments">3 comments</a></p>
	<p>Add to <a href="http://del.icio.us/post?url=http://mochiland.com/articles/recap-mochi-london-2011&amp;title=Recap: Mochi London 2011">del.icio.us</a></p>
	<p>Search blogs linking this post with <a href="http://www.technorati.com/search/http://mochiland.com/articles/recap-mochi-london-2011" title="Search on Technorati">Technorati</a></p>
	<p>Want more on these topics ? Browse the archive of posts filed under <a href="http://mochiland.com/category/mochiland/developer-feed" title="View all posts in Developer Feed" rel="category tag">Developer Feed</a>, <a href="http://mochiland.com/category/mochiland/flash" title="View all posts in Flash Development" rel="category tag">Flash Development</a>, <a href="http://mochiland.com/category/mochiland/front-page" title="View all posts in Front Page" rel="category tag">Front Page</a>, <a href="http://mochiland.com/category/mochiland/game-design" title="View all posts in Game Design" rel="category tag">Game Design</a>, <a href="http://mochiland.com/category/mochiland/games-industry" title="View all posts in Games Industry" rel="category tag">Games Industry</a>, <a href="http://mochiland.com/category/mochiland/mochi-media-announcements" title="View all posts in Mochi Media Announcements" rel="category tag">Mochi Media Announcements</a>, <a href="http://mochiland.com/category/mochiland" title="View all posts in MochiLand Topics" rel="category tag">MochiLand Topics</a>, <a href="http://mochiland.com/category/mochiland/publisher-feed" title="View all posts in Publisher Feed" rel="category tag">Publisher Feed</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://mochiland.com/articles/recap-mochi-london-2011/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Mochi Community Event Wrap-Up: All About Ads!</title>
		<link>http://mochiland.com/articles/mochi-community-event-wrap-up-all-about-ads</link>
		<comments>http://mochiland.com/articles/mochi-community-event-wrap-up-all-about-ads#comments</comments>
		<pubDate>Thu, 28 Jul 2011 07:59:56 +0000</pubDate>
		<dc:creator>Colin Cupp</dc:creator>
				<category><![CDATA[Developer Feed]]></category>
		<category><![CDATA[Flash Development]]></category>
		<category><![CDATA[Mochi Media Announcements]]></category>
		<category><![CDATA[MochiLand Topics]]></category>
		<category><![CDATA[ads]]></category>
		<category><![CDATA[advertising]]></category>
		<category><![CDATA[CPM]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[eCPM]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[Mochi Media]]></category>
		<category><![CDATA[monetization]]></category>
		<category><![CDATA[portal]]></category>
		<category><![CDATA[publisher]]></category>
		<category><![CDATA[revenue]]></category>

		<guid isPermaLink="false">http://mochiland.com/?p=5224</guid>
		<description><![CDATA[All About Ads The Mochi community event &#8220;All About Ads&#8221; has come and gone, thanks to everyone for stopping by! We hope it was informational, if not at least a little bit entertaining. If you missed it don&#8217;t worry- we have some wrap-up information for you! You can watch the recorded presentation, check out the [...]]]></description>
			<content:encoded><![CDATA[ <h1>All About Ads</h1>
<p>The Mochi community event &#8220;All About Ads&#8221; has come and gone, thanks to everyone for stopping by! We hope it was informational, if not at least a little bit entertaining. If you missed it don&#8217;t worry- we have some wrap-up information for you! You can watch the recorded presentation, check out the questions from attendees, and/or view the slides below. Enjoy!</p>
<h2>Watch The Recorded Event</h2>
<p><a href="http://www.anymeeting.com/mochimedia/E950D9898048">Click here to watch the recorded session!</a></p>
<h3>Supplemental Materials</h3>
<ul>
<li><a href="http://mochiland.com/wp-content/uploads/2011/07/Ad-terminology-definitions.pdf">Ad terminology definitions</a></li>
<li><a href="http://mochiland.com/wp-content/uploads/2011/07/Sales_process.pdf">Sales process chart</a></li>
</ul>
<h3>Post-Presentation Questions (answered in the recording)</h3>
<p>These questions were asked, and answered, at the end of the presentation:</p>
<ul>
<li> TV is separated in different segments in this chart as opposed to internet, doesn&#8217;t that create an unfair comparison?</li>
<li>How big was the impact of refusing low quality ads on revenue?</li>
<li>What about ad revenue in INDIA?</li>
<li>What is the minimum budget for advertising on the Mochi platform outside of the self-servce platform?  Is there a video ad requirement?</li>
<li>Is it possible to implement all Mochi ad products so that mochi can decide which one would be best for my game and disable some dynamically ?</li>
<li>Do you have information about games that switched the ad type and how it impacted the revenue / players opinions ?</li>
<li>Could you provide some information about AdBlock / NoScript and whether it makes sense to disable the game if the ad could not be displayed ? #2 Do you plan to allow LiveUpdates without Ad Integration ?</li>
<li>Is it possible for a developer to refuse a required time limit ad?</li>
<li>How can we take advantage of all Ad types?</li>
<li>You mention hacking quite often, could you provide more information about incidents ?</li>
<li>Any new formats planned for this year?</li>
<li>Could you discuss what the differences are in terms of displaying ads across multiple mochi ad formats (pre-roll, interlevel, clickaway) for direct buyers vs self-serve? Are there any differences? Are self-serve only displayed in certain places? Is it all 100% randomized based on bid/ad buyer rates? Etc.  If I&#8217;m currently running a campaign on self-serve, what is my benefit to moving to a direct buy campaign?</li>
</ul>
<h3>View The Slides</h3>
<div id="__ss_8699352" style="width: 425px;">
<p><strong style="display: block; margin: 12px 0 4px;"><a title="All About ads" href="http://www.slideshare.net/mochimedia/all-about-ads-8699352">All About ads</a></strong><object id="__sse8699352" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=allaboutads-110727010318-phpapp02&amp;stripped_title=all-about-ads-8699352&amp;userName=mochimedia" /><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><embed type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=allaboutads-110727010318-phpapp02&amp;stripped_title=all-about-ads-8699352&amp;userName=mochimedia" name="__sse8699352" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="padding: 5px 0 12px;">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/mochimedia">mochimedia</a>.</div>
</div>
<p>&nbsp;</p>
 <div class='series_toc'></div>	<p></p>
	<hr noshade style="margin:0;height:1px" />
	<p>&copy; Colin Cupp for <a href="http://mochiland.com">MochiLand</a>, 2011. |
	  <a href="http://mochiland.com/articles/mochi-community-event-wrap-up-all-about-ads">Permalink</a> |
	  <a href="http://mochiland.com/articles/mochi-community-event-wrap-up-all-about-ads#comments">2 comments</a></p>
	<p>Add to <a href="http://del.icio.us/post?url=http://mochiland.com/articles/mochi-community-event-wrap-up-all-about-ads&amp;title=Mochi Community Event Wrap-Up: All About Ads!">del.icio.us</a></p>
	<p>Search blogs linking this post with <a href="http://www.technorati.com/search/http://mochiland.com/articles/mochi-community-event-wrap-up-all-about-ads" title="Search on Technorati">Technorati</a></p>
	<p>Want more on these topics ? Browse the archive of posts filed under <a href="http://mochiland.com/category/mochiland/developer-feed" title="View all posts in Developer Feed" rel="category tag">Developer Feed</a>, <a href="http://mochiland.com/category/mochiland/flash" title="View all posts in Flash Development" rel="category tag">Flash Development</a>, <a href="http://mochiland.com/category/mochiland/mochi-media-announcements" title="View all posts in Mochi Media Announcements" rel="category tag">Mochi Media Announcements</a>, <a href="http://mochiland.com/category/mochiland" title="View all posts in MochiLand Topics" rel="category tag">MochiLand Topics</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://mochiland.com/articles/mochi-community-event-wrap-up-all-about-ads/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Announcing Mochi Achievements!</title>
		<link>http://mochiland.com/articles/announcing-mochi-achievements</link>
		<comments>http://mochiland.com/articles/announcing-mochi-achievements#comments</comments>
		<pubDate>Tue, 14 Jun 2011 13:00:08 +0000</pubDate>
		<dc:creator>Colin Cupp</dc:creator>
				<category><![CDATA[Developer Feed]]></category>
		<category><![CDATA[Flash Development]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Game Design]]></category>
		<category><![CDATA[Games Industry]]></category>
		<category><![CDATA[Industry News]]></category>
		<category><![CDATA[Mochi Media Announcements]]></category>
		<category><![CDATA[arcade]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[Mochi Media]]></category>
		<category><![CDATA[publisher]]></category>
		<category><![CDATA[service]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://mochiland.com/?p=5032</guid>
		<description><![CDATA[I am happy to announce the official release of the new Mochi Achievements API! Mochi Achievements API Summary Flash game developers can now implement a completely customizable achievements system in your games that is free, flexible, and easy to use. The Mochi Achievements API also gives developers the flexibility of 2 toaster sizes (toaster = [...]]]></description>
			<content:encoded><![CDATA[ <p><a href="http://www.mochimedia.com/developers/achievements.html"><img class="alignleft size-full wp-image-5086" style="border: 0px" title="achievement_API" src="http://mochiland.com/wp-content/uploads/2011/06/achievement_API.png" alt="" width="624" height="165" /></a></p>
<p><strong>I am happy to announce the official release of the new <a href="https://www.mochimedia.com/developers/achievements.html">Mochi Achievements API</a>!</strong></p>
<h1>Mochi Achievements API Summary</h1>
<p>Flash game developers can now implement a completely customizable achievements system in your games that is free, flexible, and easy to use. The Mochi Achievements API also gives developers the flexibility of 2 toaster sizes (toaster = achievements pop-up) and 9 toaster placement options so that your achievements system looks and feels the way you want it to.</p>
<p>Speaking of look and feel, there is no Mochi Media branding in the default UI, and we encourage developers to implement your own UI (using the Mochi Achievements calls) for a more seamless game integration. The default UI comes with an achievements list, toasters, and graphics for the locked and unlocked states of your achievements (but you can easily customize the &#8220;unlocked state&#8221; graphics in the default UI).</p>
<p>We have also included a points system (points related to the achievements, developer-determined) complete with progress bars. Your players can view their points and achievements progress as they&#8217;re earned/unlocked.</p>
<h2>Who Should Use Mochi Achievements?</h2>
<h4>Developers:</h4>
<ul>
<li>If you don’t have the time or desire to create your own achievements system, but would love to have a quality solution that gives you control.</li>
<li>If you are looking for a solution you can completely customize, either with your own branding or even a sponsor’s branding- you can be as creative as you want to be.</li>
</ul>
<h4>Publishers:</h4>
<ul>
<li>Take advantage of the <a href="https://www.mochimedia.com/publishers/custom-integration.html">Mochi Publisher Bridge</a> for site-specific achievements, getting more value out of your community and your players.</li>
<li>You can request that developers implement Mochi Achievements with your branding for sponsorships and site-locks.</li>
</ul>
<h2>Mochi Achievements Examples</h2>
<p><a href="http://www.mochimedia.com/games/play/flying-candy/">Flying Candy</a>, <a href="http://www.mochimedia.com/games/play/papas-taco-mia/">Papa&#8217;s Taco Mia!</a>, <a href="http://www.mochimedia.com/games/play/big-little-plagiary-3-made-in-china/">big LITTLE plagiary 3</a>, and <a href="http://www.mochimedia.com/games/play/flood-runner-3/">Flood Runner 3</a> are all examples of games that are using Mochi Achievements in different ways to &#8220;achieve&#8221; the same goal. Check out the two example games below to see the contrast between the default UI and what can be done with a custom UI.</p>
<p>The first example is <a href="http://www.mochimedia.com/games/play/big-little-plagiary-3-made-in-china/">big LITTLE plagiary 3</a>, which uses the default UI. The second game is <a href="http://www.mochigames.com/game/papas-taco-mia/" target="_blank">Papa&#8217;s Taco Mia</a>, which is using custom UI created by the developer along with the Mochi Achievements calls. Note that the default UI has no branding, while the customized UI can be made to look however you want it to (including sponsor branding).</p>
<h4>big LITTLE plagiary 3 Achievements List (default UI)</h4>
<p><img style="border: 0px;" title="big LITTLE plagiary Achievements List" src="http://i.imgur.com/d4pkq.png" alt="big LITTLE plagiary Achievements List" /></p>
<p>&nbsp;</p>
<h4>big LITTLE plagiary 3: Achievement Unlocked (default UI)</h4>
<p><img style="border: 0px;" title="big LITTLE plagiary Achievement Unlocked" src="http://i.imgur.com/SQSRo.png" alt="big LITTLE plagiary: Achievement Unlocked" /></p>
<p>&nbsp;</p>
<h4>Papa’s Taco Mia: Achievement Unlocked (developer customized UI)</h4>
<p><a href="https://www.mochimedia.com/developers/achievements.html"><img style="border: 0px;" title="Papa's Taco Mia Achievement: Tomato Time" src="http://i.imgur.com/d8lbN.jpg" alt="alt text" width="648" height="474" /></a></p>
<p>&nbsp;</p>
<h4>Papa&#8217;s Taco Mia: Achievements List (developer customized UI)</h4>
<p><a href="https://www.mochimedia.com/developers/achievements.html"><img style="border: 0px;" title="Papa's Taco Mia Achievements List" src="http://i.imgur.com/GJhqx.jpg" alt="alt text" width="644" height="384" /></a><br />
<strong> </strong></p>
<h2>What Makes A Good Achievement?</h2>
<p>Most game creators would agree that achievements make games more engaging and encourage players to stick around (increase replays). But how do you know if you are making a good achievements system? Here are a few resources we thought were interesting on the subject:</p>
<ul>
<li><a href="http://www.escapistmagazine.com/videos/view/extra-credits/2758-Achievements" target="_blank">Extra Credits</a></li>
<li><a href="http://www.gamasutra.com/view/feature/6360/the_cake_is_not_a_lie_how_to_.php" target="_blank">The Cake is not a lie, pt.1</a></li>
<li><a href="http://www.gamasutra.com/blogs/GregMcClanahan/20091202/3709/Achievement_Design_101.php">Achievements 101 by Greg McClanahan</a></li>
</ul>
<h2>Want to try it out? Here’s how!</h2>
<ol>
<li><a href="http://www.mochimedia.com/dl/MochiAPI_v3_9_3.zip" target="_blank">Download the latest version of the Mochi API</a></li>
<li>Once you have the latest API, log in to your developer dashboard</li>
<li>Select the game to which you would like to add achievements</li>
<li>Select “Achievements” in the left-hand menu</li>
<li>You should now see the information to create and edit achievements.</li>
</ol>
<p>This new tool is a direct result of the community giving us product feedback- you wanted it, we thought it made sense, so we made it. Let us know what other products and features you would like us to work on by visiting our <a href="http://mochimedia.uservoice.com/forums/86073-mochi-product-and-services-feedback*" target="_blank">product feedback forums</a>.</p>
<p><strong>Be sure to let us know what you think about Mochi Achievements- we want your feedback! :)</strong></p>
 <div class='series_toc'></div>	<p></p>
	<hr noshade style="margin:0;height:1px" />
	<p>&copy; Colin Cupp for <a href="http://mochiland.com">MochiLand</a>, 2011. |
	  <a href="http://mochiland.com/articles/announcing-mochi-achievements">Permalink</a> |
	  <a href="http://mochiland.com/articles/announcing-mochi-achievements#comments">3 comments</a></p>
	<p>Add to <a href="http://del.icio.us/post?url=http://mochiland.com/articles/announcing-mochi-achievements&amp;title=Announcing Mochi Achievements!">del.icio.us</a></p>
	<p>Search blogs linking this post with <a href="http://www.technorati.com/search/http://mochiland.com/articles/announcing-mochi-achievements" title="Search on Technorati">Technorati</a></p>
	<p>Want more on these topics ? Browse the archive of posts filed under <a href="http://mochiland.com/category/mochiland/developer-feed" title="View all posts in Developer Feed" rel="category tag">Developer Feed</a>, <a href="http://mochiland.com/category/mochiland/flash" title="View all posts in Flash Development" rel="category tag">Flash Development</a>, <a href="http://mochiland.com/category/mochiland/front-page" title="View all posts in Front Page" rel="category tag">Front Page</a>, <a href="http://mochiland.com/category/mochiland/game-design" title="View all posts in Game Design" rel="category tag">Game Design</a>, <a href="http://mochiland.com/category/mochiland/games-industry" title="View all posts in Games Industry" rel="category tag">Games Industry</a>, <a href="http://mochiland.com/category/mochiland/gaming-news" title="View all posts in Industry News" rel="category tag">Industry News</a>, <a href="http://mochiland.com/category/mochiland/mochi-media-announcements" title="View all posts in Mochi Media Announcements" rel="category tag">Mochi Media Announcements</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://mochiland.com/articles/announcing-mochi-achievements/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Post Mortem: Papa&#8217;s Taco Mia by Flipline Studios</title>
		<link>http://mochiland.com/articles/post-mortem-papas-taco-mia-by-flipline-studios</link>
		<comments>http://mochiland.com/articles/post-mortem-papas-taco-mia-by-flipline-studios#comments</comments>
		<pubDate>Thu, 09 Jun 2011 05:11:37 +0000</pubDate>
		<dc:creator>Flipline Studios</dc:creator>
				<category><![CDATA[Developer Feed]]></category>
		<category><![CDATA[Developer Spotlight]]></category>
		<category><![CDATA[Flash Development]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Game Design]]></category>
		<category><![CDATA[MochiLand Topics]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Flipline Studios]]></category>
		<category><![CDATA[Mochi Media]]></category>
		<category><![CDATA[Papa's Burgueria]]></category>
		<category><![CDATA[Papa's Pizzeria]]></category>
		<category><![CDATA[Papa's Taco Mia]]></category>
		<category><![CDATA[post-mortem]]></category>

		<guid isPermaLink="false">http://mochiland.com/?p=5000</guid>
		<description><![CDATA[Post Mortem: Papa&#8217;s Taco Mia! &#160; Introduction Papa’s Taco Mia! is the third game in our series of hands-on cooking sims, with Papa Louie expanding his restaurant empire and branching out into the taco business.  The original time-management game in the series launched way back in 2007, and since then we hadn’t seen very many [...]]]></description>
			<content:encoded><![CDATA[ <h1>Post Mortem: Papa&#8217;s Taco Mia!</h1>
<p>&nbsp;</p>
<h1>Introduction</h1>
<p>Papa’s Taco Mia! is the third game in our series of hands-on  cooking sims, with Papa Louie expanding his restaurant empire and branching out  into the taco business.  The original  time-management game in the series launched way back in 2007, and since then we  hadn’t seen very many restaurant-themed games, which had us wondering if there  was still an audience for the multitasking and hands-on gameplay found in the  original Papa’s Pizzeria.</p>
<p>When we decided to step back into the series and develop a  sequel, we wanted to add a number of additions that fans had requested over the  years, and to avoid making the game seem like only a “deluxe” version of the  original we branched out with a new food and new mechanics with 2010’s Papa’s  Burgeria.  There was a great response to  the new game and the fans were clearly still there, so soon after Papa’s  Burgeria had spread virally we started thinking of where else we could go with  the series.</p>
<p>We felt there were still a number of improvements we could  make to the overall structure for these types of games, and by switching to new  food items we could keep each game fresh and unique with brand-new mechanics,  without feeling like a recycled version of the previous game.</p>
<p>With Papa’s Taco Mia, we decided to focus on tacos as the  theme of the new game, which would bring a number of new cooking and building  mechanics that would be very different from the previous games.  During development, there were a number of  things that really helped shape the game into one that fits well with the  others in the series, and often times improve upon them.  We also had a number of struggles and  difficulties during development, though by pushing through these rough patches and  learning from them we were able to craft an even better experience for the  players.</p>
<p>&nbsp;</p>
<h1>What Went Right:</h1>
<h2>1. Checking the Suggestion Box</h2>
<p>Before starting on Papa’s Taco Mia, we spent a lot of time  reading up on players’ suggestions from playing the first two games.  We had a number of new ideas to spice up this  game, but we also wanted to address any popular requests that seemed to come up  a lot from the fans.  There were a few  key features that we implemented based on player suggestions which we feel  added a great extra layer to the game.</p>
<p>With Burgeria we finally added the much-requested feature of  spending tips to buy things in the game, but players then started to argue that  they shouldn’t have to spend THEIR hard-earned tips to make Papa Louie’s  restaurant run better!  With Papa’s Taco  Mia, we added a new weekly Pay Day where the player earns a sum of money to  spend towards upgrades, which also adds something more to look forward to over  the long term.  Some players had also  commented that earning new customers wasn’t quite enough of a reward for  leveling up in rank, so one of things we added to improve on this is a raise in  the player’s wages every time they level up, so they can earn more on each Pay Day  for doing so well.</p>
<p>Since Papa’s Pizzeria, we’ve received a lot of complaints about  the process of taking orders and giving orders taking too long.  We’ve always thought that time spent with the  customer is part of the whole multitasking challenge, but we wanted to address those  complaints by tying it in with the customers leveling up with stars and  Customer Awards.  Now when a customer  earns a bronze, silver, or gold Award, they’ll also place and receive orders  quicker than before, so you get an extra bonus for doing well with each  customer.</p>
<h2>2. Added Variety with Closers and Food Critic</h2>
<p>In previous games, there hadn’t been a lot of variety over  the course of a single day – different customers may come in, but serving the  last customer of the day is not that different from serving the first, aside from  it possibly being more hectic.  The  customers who arrive on a specific day also haven’t made much difference in the  gameplay, unless the player is trying to earn Customer Awards.  In Papa’s Taco Mia, we wanted to keep the  familiar aspect of serving a series of customers, but also to add a twist where  serving a certain customer might have higher stakes than the others.</p>
<p><a href="http://mochiland.com/wp-content/uploads/2011/06/postmortem_closers1.jpg"><img class="alignnone size-full wp-image-5005" style="border: 0px;" src="http://mochiland.com/wp-content/uploads/2011/06/postmortem_closers1.jpg" alt="" width="640" height="480" /></a></p>
<p>To change things up, each workday ends with the arrival of a  Closer – a sort of mini-boss for each day that is much harder to please, and  who uses a different grading scale when receiving their tacos.  These Closer customers also use a different  system for visiting the taco shop:  Each  of the Closers will only visit once a week, so it’s even more of a challenge to  earn stars and Awards for them, since players won’t see them as often.</p>
<p>To add even more variety (and a helpful tip bonus), we  introduced the Food Critic as a Closer customer, who orders something  completely different every time he visits.   If he’s happy with his taco, he awards the player with a Blue Ribbon,  which is displayed in the lobby for three days and prompts any other customers  to give higher tips.  These two changes  to the customer system add more variety to the gameplay throughout the day and  across multiple days, without straying too far from the familiar arrival of  customers.</p>
<h2>3. Solving the  Mechanic “Hooks” for the Game</h2>
<p>With each game in the series, we try to center the gameplay  on the type of food being served, and come up with ways to turn that food’s  preparation into enjoyable game mechanics.   There were a variety of challenges in coming up with both the cooking  and building phases for serving tacos, and lots of refining that went into  getting the mechanics just right to capture the feel of the series.</p>
<p>All of games in the series have a cooking phase in its  preparation, and up until now the way to add variation to orders was by cooking  food for different lengths – making a burger well-done in Burgeria, or cooking  a pizza for a brief time in the Pizzeria to lightly bake.  With tacos though, people don’t order their  ground beef well-done or rare, so we needed a different hook for the cooking  phase that made sense for preparing tacos.   We first decided that we would have multiple kinds of meats that would  form the basis of customers’ orders.  This  added variation to the preparation of an order, but wouldn’t make much  difference to the cooking phase if preparing beef was no different than  preparing chicken.  To capture that  aspect of cooking variation from the other games, we decided that the preparation  of each meat would be made of similar components (cutting and flipping), but  would require different timing for each meat type.</p>
<p><a href="http://mochiland.com/wp-content/uploads/2011/06/postmortem_pans.jpg"><img class="alignnone size-full wp-image-5007" style="border: 0px;" src="http://mochiland.com/wp-content/uploads/2011/06/postmortem_pans.jpg" alt="" width="640" height="261" /></a></p>
<p>We went through a wide variety of mechanics and visual cues  for this type of gameplay to work and make sense to the player.  Since we couldn’t rely on doing one “action”  in that station at the halfway point of preparing a meat (like flipping burgers  when half-finished), we realized we needed to prompt players on when to perform  certain actions based on the meat.  In our  early versions, the circular timer around each pan would complete an entire  circle before prompting to flip, and would then complete an entire circle again  before prompting to cut, which made it difficult to visually gauge how far  along an order was.  Instead, we changed  the pan timer to represent a full cooking time, and placed red and blue markers  along that timer as visual cues when an action would be required.  Since these actions were important to the  overall preparation, we also added bubbles prompting players on which action is  required at each point.  There were some  missteps along the way with cooking preparation (see our notes on this in the  “What Went Wrong” section), but we kept fine-tuning the process until it worked  well as a mechanic.</p>
<p>We knew from the start that we would have a lot of  challenges with adding toppings to tacos.   We needed a topping system that lent itself to the food, and in this  case it didn’t make sense to be placing individual tomatoes and pieces of  lettuce on a taco.  What we needed was something  closer to a particle system, which could pour bits of toppings onto a taco and  have those cascade and form mounds on top of one another.  There were also two other important facets to  dealing with dynamic, fluid toppings like these:  It would need to run fast without causing a  performance drain on the game, and we would also need to come up with a scoring  system that could make some sense out of all of the layers and mounds of food  particles.</p>
<p>We spent a lot of time on tech demos for the system, trying  to squeeze the best performance out of it so it didn’t bog down with hundreds  of chunks filling a taco.  Once the solid  foods were working, we spent time adapting the system for fluids like hot sauce  and sour cream, which needed a different rendering system so they didn’t look  like a bunch of separate blobs.  We  fine-tuned each topping type so guacamole would have different speeds and stickiness  than beans or rice, and so sauces like sour cream could look and act thicker  than others like mild sauce.  In the end,  we had a topping system that made sense for the food, and which felt like how  you naturally prepare a taco.</p>
<h2>4. Easter Eggs Turning into Strategy</h2>
<p>One of our minor goals was to improve the cosmetics in areas  like the “Start of the Day” scene.  While  we didn’t anticipate any effects on gameplay, we wanted to add a bit of life to  the outside shot of the shop that players see before each day.  To make things seem livelier, we added a few  customers walking up or passing by, and decided to use the first and second  customers who visit that day so it related to who walks in.</p>
<p>A happy accident occurred during playtesting when we noticed  we were actually using these “Easter Eggs” during the opening scene to our  advantage while playing the game.  Once  we had started learning all of the customers’ meat preferences, after we saw  the first or second customer in the opening scene we would quickly jump to the  Grill Station and get their meat cooking before they even arrived!  This was a great benefit to actually learning  customers’ orders, since it could give you that added advantage at the start of  the day.  It also helped us nail down the  most important aspect of a customer’s order, which we struggled with when  planning the unlockable topping system.</p>
<h2>5. Looking  forward to unlockable toppings and achievements</h2>
<p>In the earlier games, we struggled with the feeling of  monotony over the course of multiple days, and didn’t feel that unlocking new  customers was quite enough of a change in gameplay or a big enough reward for  sticking around.  With Papa’s Taco Mia,  we sought to remedy that with toppings and ingredients that would gradually  unlock while playing.  This was especially  helpful for this game, which may have felt overwhelming if all of the meats and  taco shells were present and being ordered from the start.  We also made sure that once a new topping or  ingredient was unlocked, someone would arrive within the next two customers to  order that new item, so it felt like the possibilities were expanding and that  the newly-acquired item would be useful.</p>
<p>On top of these unlockables near the start of the game, we  noticed that some players would play for long periods of time (racking up  hundreds of in-game days), and we wanted to add some long-term rewards for  these players as well.  An achievements  system was added to the game with 60 badges rewarding players for a variety of  accomplishments, including serving a number of tacos in hard shells, earning  blue ribbons from the Food Critic, getting 100% in certain stations, and buying  upgrades from the shop.  With unlockable  toppings, long-term achievements, new customers, and Customer Awards, players  now have a variety of short-term and long-term goals to work towards in the  game.</p>
<p>&nbsp;</p>
<h1>What Went Wrong:</h1>
<h2>1. Rethinking the Grill</h2>
<p>One of our biggest issues during development was the gameplay  surrounding the Grill Station.  In our  original plan, meats would be scooped and poured onto tacos just like every  other topping, except you wouldn’t have an unlimited supply of the meats.  Instead, you would cook up large batches of  beef and chicken early in the day, and you could get a few orders worth of meat  from each batch until the bin was empty and you needed to cook more.</p>
<p>&nbsp;</p>
<p><a href="http://mochiland.com/wp-content/uploads/2011/06/postmortem_meatbins.jpg"><img class="alignnone size-full wp-image-5008" style="border: 0px;" src="http://mochiland.com/wp-content/uploads/2011/06/postmortem_meatbins.jpg" alt="" width="640" height="480" /></a></p>
<p>It made sense on paper, especially since that’s how taco  shops often prep their meats, but after we built up the system and did some  playtesting we realized it was making the game feel off-balance.  While playing through a work day, we noticed  we could get our cooking out of the way early and rarely return to the Grilling  Station, so most of our time was spent taking orders and topping tacos.  Without needing much prep time for tacos, the  gameplay started feeling more like an assembly line and less about multitasking  and keeping track of multiple orders at once.   Even worse, you couldn’t really do anything until you cooked all of your  meats and filled the bins, so every day started with a couple minutes of  waiting around and orders piling up that you couldn’t start.</p>
<p>One of the main factors in the multitasking of our previous  games was a certain part of an order’s preparation that took a while to  complete – waiting for pizzas or burgers or cook – which would encourage players  to multitask and work on a different order while waiting for something to finish.  We had that with this cooking mechanic, but  the key difference was that the meats weren’t a part of a specific order – it  was just busy work before you could get on with the real gameplay.</p>
<p>To keep players coming back to grill, we tried making the  “batches” of meat fill fewer and fewer tacos, and it soon became clear that we needed  that one-to-one connection between an individual order and its  preparation.  We scrapped the original  idea of stocking bins with the cooked meats, and instead went with an entire  pan of meat going into each order.   Without a bin to pour the meat into, we were faced with new questions on  how to transfer the meat between stations, until we decided to put all of the  taco shells right on the stove and pour directly into them from the pans.</p>
<p>It caused a lot of hang-ups in our schedule and involved a  lot of rethinking and redesigning, but in the end we had captured that feel of  hectic multitasking again.  This design  change really helped the gameplay feel like it was constantly moving forward,  instead of starting each day with a long wait at the grill.</p>
<h2>2. How do you pronounce that?</h2>
<p>We’re notoriously bad at coming up with titles for our  games, but we thought we’d have an easy time with this one.  “Papa’s Pizzeria” was a natural choice for  the original game, and for the sequel we tried to build on that familiarity  with the somewhat-goofy “Papa’s Burgeria”.    For the new game we originally decided on “Papa’s Taqueria”, since taco  shops occasionally go by that name, and we had that matching “-ia” at the end  of the title.</p>
<p>The more we looked at the title though, the more we realized  how awkward it could be for players.  A  good amount of our regular fans are from Spanish-speaking countries, so we  liked having the authentic Spanish word “taqueria” in the title.  The problem is that the word is rarely used  in English (unlike the familiar “pizzeria”), and unless you frequent a lot of  taquerias you may not see the root word “taco” in the name, especially with the  spelling change adding a “Q” in the middle.</p>
<p>We were actually hung up on the title for a few weeks,  trying to find something similar to the earlier titles so it felt like it was  part of the series, without confusing a chunk of our fans with awkward  spellings.  We tried different suffixes  and even going with a phonetic spelling, though it was hard to guess how to  pronounce “Tacoria” when reading it out loud, and it sounded more like a  fantasy kingdom than a restaurant.</p>
<p>In the end, we came up with “Papa’s Taco Mia!” – making sure  “taco” was clear in the title, trying to evoke the feel of “Mama Mia!”, and  also getting it pretty close to matching with the other games’ titles.</p>
<h2>3. Customers and their Toppings</h2>
<p>When we decided to gradually unlock toppings as you play  through the game, we realized we’d have some issues with how customers ordered  their food.  In the previous games, the  customers always order the same thing every time they visit, to help players  become familiar with each customer’s individual order and feel that each customer  is unique.  In this case though, a  customer might normally want to order a steak taco with peppers before either of  those items is available, so we had to decide exactly how we’d handle  substitutions or missing toppings.</p>
<p>We first attempted to have the earlier customers always order  what would in theory by unlocked by the point they first visited.  This worked out fine at the start, but two  main problems came up with using this system:    First, when these customers show up again later in the game, we ended up  with a bunch of orders that were only variations of beef, lettuce, and  tomatoes, which got a little boring.   Second, when we finally unlock peppers as a topping, we don’t have  anyone who wants it on a taco!  We’d need  to quickly unlock more customers that would also want these newly-unlocked  toppings, and it also got a little boring with five new customers in a row all  wanting those new peppers and steak on their tacos.</p>
<p>To fix these issues, we created a more dynamic order system,  where customers would have a list of ideal toppings they wanted, and would only  ask for them if they were available.   This way, while a bunch of your customers might want onions, they’ll  skip that topping when placing orders until you have it unlocked – and then we  also have a larger pool of customers who can order newly-unlocked toppings.</p>
<p>Once we planned out this new system, we knew that we wanted  customers’ requests to always be additive instead of replacing things – for  example, Franco will originally order lettuce on his taco, then later add  onions to the lettuce, instead of outright replacing the lettuce with onions.  We had two challenges again with this plan –  how to handle meats and taco shells.  We  obviously couldn’t ignore the taco shell if the type they want isn’t unlocked,  and we didn’t want to serve meatless tacos which would cut an entire station  out of the preparation.  At the same  time, we knew we’d have some issues with mentally connecting a customer to  their usual order if that usual order keeps changing drastically.</p>
<p>After trying a handful of possible solutions, we realized  that the meat was the most important part of the taco that needed to relate to  each customer.  It’s the main ingredient  of the taco, and it’s the first thing you need to prep for an order.  It helped a lot to know that if you just took  Wally’s order, he’s always going to want chicken, so you can plan what to put  on the grill without having to pay too close of attention to the order ticket  yet – and this especially helps if you use the outdoor Easter Eggs to get a  jump-start on your day like we mentioned earlier.  To make sure customers didn’t change their  meat orders, we had to carefully plan the unlocking sequence so someone didn’t  visit before their meat was available (though we couldn’t get around this with  the Closers who visit on a set schedule).   We’d still be stuck with customers flip-flopping on what kind of taco  shell they want, but at least once their desired shell is available they’ll stick  with that from now on.</p>
<h2>4. Papa’s Coffee Shop</h2>
<p>We had no idea if people would still be interested in  cooking-sim games after Papa’s Pizzeria, so after we launched Papa’s Burgeria  and saw there was still a demand for games like these, we started thinking of  other directions to go with gameplay.   Before working on Papa’s Taco Mia, we had actually started making a very  different cooking-sim game:  Papa was  going to open his own coffee shop.</p>
<p>We didn’t get very far into development before we were faced  with a mountain of problems.  We had a  lot of trouble finding the right gameplay hook with coffee preparation, and it  was hard to distill coffee-making into a multitasking process instead of just  being a linear assembly line.  A lot of  the same problems we had with Taco Mia’s grill were present in the coffee shop  – how do we slow down the preparation to encourage multitasking, and keep it a  hands-off process so you have time to move to another station?  Should you really brew a fresh batch of  coffee for each cup?  Should you wait for  pots of coffee to brew each morning before doing anything?  Aside from gameplay challenges, the color  palette for ingredients was also pretty drab with browns and whites (coffee,  cocoa, caramel, foam…) so it didn’t look very fun or interesting either.</p>
<p>The deciding factor was when we noticed that we weren’t  getting the same vibe we got from the earlier games – there was never a moment  of “that looks so good, I could really go for a coffee right now”.  We ultimately decided to scrap the coffee  shop and switch gears to something else.   Tacos were on our earlier list of possibilities; though we had  originally put it aside because of the challenges with creating pourable  toppings and fluid sauces.  In the end,  it was much easier to visualize and plan out the gameplay with taco-building,  and despite the challenges it ended up being a much more enjoyable game to work  on.</p>
<h2>5. Struggle with Pouring Mechanics</h2>
<p>After we ironed out the technical issues with pourable  toppings and fluid sauces, we had some trouble deciding on the best way to  actually pour those toppings into the tacos.   The first method we tried was a “click-and-scribble” mechanic:  You would first click on a bin of toppings,  and the scooper would attach itself to the mouse as you moved around the  screen.  You would then hold down the  mouse button as you scribbled above the taco, pouring the bits out while you  were “pressing” and dragging the scooper.</p>
<p>It felt a little odd when the scooper would attach itself to  the mouse, as it wasn’t a mechanic we had used previously in the series – in  Papa’s Pizzeria, you had to click-and-drag a pepperoni from the bin and release  to place it on the pizza, and in Papa’s Burgeria you had to click-and-drag a  pickle from the shelf and release above the burger to drop it.  It also didn’t match the mechanics elsewhere  in Papa’s Taco Mia, where you use drag-and-release mechanic for moving pans,  tickets, and the grill utensils.</p>
<p>The method that we finally used in the game is instead a  “drag-then-wiggle” mechanic:  You click  and drag from a topping bin to above the taco (just like toppings in the other  games), and when you release the button you then move the mouse left and right  to pour that topping evenly across the taco.   We went back and forth between these two mechanics a lot during development  and had a rough time deciding on what felt the most natural.  There may still be a moment of confusion with  toppings pouring out seemingly uncontrollably when you release that mouse  button, but it stays closer in line with the rest of the mechanics of the game  and the series – and after your first try or two the pouring feels natural.</p>
<h1>Conclusion</h1>
<p>On top of a great new topping system (which opens up  possibilities for future games in the series), we were able to add many new  features to give the game even greater depth than the previous ones, and add  more variety and excitement for players.   Though we had a few difficulties during development, by looking at the  problems and discovering the core of each issue, we were able to really hone in  on what makes a game work within the “Papa’s” series.</p>
<p>&nbsp;</p>
 <div class='series_toc'></div>	<p></p>
	<hr noshade style="margin:0;height:1px" />
	<p>&copy; Flipline Studios for <a href="http://mochiland.com">MochiLand</a>, 2011. |
	  <a href="http://mochiland.com/articles/post-mortem-papas-taco-mia-by-flipline-studios">Permalink</a> |
	  <a href="http://mochiland.com/articles/post-mortem-papas-taco-mia-by-flipline-studios#comments">No comment</a></p>
	<p>Add to <a href="http://del.icio.us/post?url=http://mochiland.com/articles/post-mortem-papas-taco-mia-by-flipline-studios&amp;title=Post Mortem: Papa&#8217;s Taco Mia by Flipline Studios">del.icio.us</a></p>
	<p>Search blogs linking this post with <a href="http://www.technorati.com/search/http://mochiland.com/articles/post-mortem-papas-taco-mia-by-flipline-studios" title="Search on Technorati">Technorati</a></p>
	<p>Want more on these topics ? Browse the archive of posts filed under <a href="http://mochiland.com/category/mochiland/developer-feed" title="View all posts in Developer Feed" rel="category tag">Developer Feed</a>, <a href="http://mochiland.com/category/mochiland/developer-spotlight" title="View all posts in Developer Spotlight" rel="category tag">Developer Spotlight</a>, <a href="http://mochiland.com/category/mochiland/flash" title="View all posts in Flash Development" rel="category tag">Flash Development</a>, <a href="http://mochiland.com/category/mochiland/front-page" title="View all posts in Front Page" rel="category tag">Front Page</a>, <a href="http://mochiland.com/category/mochiland/game-design" title="View all posts in Game Design" rel="category tag">Game Design</a>, <a href="http://mochiland.com/category/mochiland" title="View all posts in MochiLand Topics" rel="category tag">MochiLand Topics</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://mochiland.com/articles/post-mortem-papas-taco-mia-by-flipline-studios/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tutorial: 3D Car With A Camera Following It</title>
		<link>http://mochiland.com/articles/tutorial-3d-car-with-a-camera-following-it</link>
		<comments>http://mochiland.com/articles/tutorial-3d-car-with-a-camera-following-it#comments</comments>
		<pubDate>Tue, 24 May 2011 19:00:46 +0000</pubDate>
		<dc:creator>TomKrcha</dc:creator>
				<category><![CDATA[Developer Feed]]></category>
		<category><![CDATA[Flash Development]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Game Design]]></category>
		<category><![CDATA[MochiLand Topics]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[Camera]]></category>
		<category><![CDATA[Car]]></category>
		<category><![CDATA[Mochi]]></category>
		<category><![CDATA[Tom Krcha]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://mochiland.com/?p=4886</guid>
		<description><![CDATA[Ever wondered how to build a simple 3D car movement with camera that follows the car? Let&#8217;s have a look at this tutorial, which uses Alternativa 3D 8 (Molehill). Download Alternativa 3D 8. This tutorial consist of these parts: - move the car with keyboard controls - follow the car with the camera The final [...]]]></description>
			<content:encoded><![CDATA[ <p>Ever wondered how to build a simple 3D car movement with camera that follows the car?<br />
Let&#8217;s have a look at this tutorial, which uses <a href="http://alternativaplatform.com/">Alternativa 3D</a> 8 (<a href="http://labs.adobe.com/downloads/flashplatformruntimes_incubator.html">Molehill</a>).</p>
<p>Download <a href="http://blog.alternativaplatform.com/en/2011/04/30/meet-early-build-of-alternativa3d-8/">Alternativa 3D 8</a>.</p>
<p>This tutorial consist of these parts:<br />
- move the car with keyboard controls<br />
- follow the car with the camera</p>
<p>The final app will look like this:<br />
<a href="http://flashrealtime.com/demos/carfollowcamera/CarWithFollowCamera.html"><img class="alignnone size-full wp-image-2292" style="border: 0px;" src="http://www.flashrealtime.com/wp-content/uploads/2011/05/CarAppScreenshot.png" alt="" width="480" height="339" /></a><br />
(*requires <a href="http://labs.adobe.com/downloads/flashplatformruntimes_incubator.html">Flash Player with Molehill</a>)</p>
<p><span id="more-4886"></span></p>
<p>To understand the car&#8217;s movement let&#8217;s do a little bit of math. I&#8217;ve got inspired by <a href="http://www.emanueleferonato.com/2010/06/16/create-a-flash-racing-game-tutorial-as3-version/">this tutorial</a> and <a href="http://www.actionscript.org/resources/articles/648/2/Car-Movement/Page2.html">this one</a>. But anyway, there is no rocket science involved. Just a simple trigonometric functions and that&#8217;s great, because anyone can do it easily.</p>
<h3>Speed / Acceleration</h3>
<p>When you press UP key, you add acceleration to the speed. When DOWN key, you subtract acceleration from the speed. When none of them is pressed, you slow down by multiplying actual speed by 0.96 &#8211; note it can be whatever, depends on how fast or slow you want to slow down.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">// don't allow to speed up more than maximum speed</span>
<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>accelerate <span style="color: #000066; font-weight: bold;">&amp;</span>amp<span style="color: #000066; font-weight: bold;">;&amp;</span>amp<span style="color: #000066; font-weight: bold;">;</span> speed0<span style="color: #000066; font-weight: bold;">.</span>3<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		speed<span style="color: #000066; font-weight: bold;">*</span>=<span style="color: #000000; font-weight:bold;">0.96</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>
		speed=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<h3>Steering / Rotation</h3>
<p>When we press LEFT or RIGHT key, we turn the car by Math.PI/40 radians (4.5 degrees). Again, pass number that fits you best.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>turn_left<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
	steering <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">40</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>turn_right<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
	steering <span style="color: #000066; font-weight: bold;">-</span>= <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">40</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>You will also find that the solution above is not exactly correct, because we can turn the car even when standing on place with zero speed. To fix that, we will multiply the angle by speed/speedMax (a number between 0-1). Now it will behave correctly</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>turn_left<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
	steering <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">40</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000;">&#40;</span>speed<span style="color: #000066; font-weight: bold;">/</span>speedMax<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>turn_right<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
	steering <span style="color: #000066; font-weight: bold;">-</span>= <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">40</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000;">&#40;</span>speed<span style="color: #000066; font-weight: bold;">/</span>speedMax<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>When we are done with speed and acceleration, we can apply it to our car. To calculate the real position of the car, we have to use a simple <a href="http://en.wikipedia.org/wiki/Trigonometric_functions#Sine.2C_cosine.2C_and_tangent">trigonometric functions</a> &#8211; sine and cosine. Note that we know only speed (vector magnitude) and steering (angle, rotation of the car).</p>
<p>By the definition of the sine and the cosine, we are able to calculate the position (X and Y) of the car from the angle and speed.<br />
<a href="http://www.flashrealtime.com/wp-content/uploads/2011/05/SpeedSinCosine.png"><img class="alignnone size-full wp-image-2282" style="border: 0px;" src="http://www.flashrealtime.com/wp-content/uploads/2011/05/SpeedSinCosine.png" alt="" width="480" height="283" /></a></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">car<span style="color: #000066; font-weight: bold;">.</span>rotationZ = <span style="color: #000066; font-weight: bold;">-</span>steering<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
car<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span>= speed<span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span>steering<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
car<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">+</span>= speed<span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span>steering<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>Let&#8217;s have a look what we have achieved so far:<br />
<a href="http://flashrealtime.com/demos/carfollowcamera/CarWithFollowCameraStep1.html"><img class="alignnone size-full wp-image-2293" style="border: 0px" src="http://www.flashrealtime.com/wp-content/uploads/2011/05/CarAppStep1Screenshot.png" alt="" width="480" height="341" /></a><br />
(<a href="http://flashrealtime.com/demos/carfollowcamera/CarWithFollowCameraStep1.as">source code here</a>)</p>
<h3>Camera that follows the car</h3>
<p>To add a so called &#8220;follow camera&#8221;, we have to do one simple thing &#8211; keep it behind the car in a specific distance, again by using trigonometric functions.</p>
<p><img class="alignnone size-full wp-image-2300" style="border: 0px;" src="http://www.flashrealtime.com/wp-content/uploads/2011/05/CameraDistanceAngle.png" alt="" width="324" height="329" /></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">camera<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = car<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: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span>car<span style="color: #000066; font-weight: bold;">.</span>rotationZ<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span>cameraDistance<span style="color: #000066; font-weight: bold;">;</span>
camera<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = car<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;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span>car<span style="color: #000066; font-weight: bold;">.</span>rotationZ<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span>cameraDistance<span style="color: #000066; font-weight: bold;">;</span>
camera<span style="color: #000066; font-weight: bold;">.</span>rotationZ = car<span style="color: #000066; font-weight: bold;">.</span>rotationZ<span style="color: #000066; font-weight: bold;">+</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// Math.PI = 180 deg</span></pre></div></div>

<p>Right now, we have a camera, that follows the car. Try the <a href="http://flashrealtime.com/demos/carfollowcamera/CarWithFollowCameraStep2.html">demo here</a> (<a href="http://flashrealtime.com/demos/carfollowcamera/CarWithFollowCameraStep2.as">source</a>). But as you see, it feels very hard to play. So we add a little bit of smoothing interpolation to make the game smoother to play.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> targetX<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = car<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: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span>car<span style="color: #000066; font-weight: bold;">.</span>rotationZ<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span>cameraDistance<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> targetY<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = car<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;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span>car<span style="color: #000066; font-weight: bold;">.</span>rotationZ<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span>cameraDistance<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> targetZRotation<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = car<span style="color: #000066; font-weight: bold;">.</span>rotationZ<span style="color: #000066; font-weight: bold;">+</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
camera<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>camera<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">-</span> targetX<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*.</span>2<span style="color: #000066; font-weight: bold;">;</span>
camera<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>camera<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">-</span> targetY<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*.</span>2<span style="color: #000066; font-weight: bold;">;</span>
camera<span style="color: #000066; font-weight: bold;">.</span>rotationZ <span style="color: #000066; font-weight: bold;">-</span>= <span style="color: #000000;">&#40;</span>camera<span style="color: #000066; font-weight: bold;">.</span>rotationZ <span style="color: #000066; font-weight: bold;">-</span> targetZRotation<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*.</span>2<span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>Now it feels much better. Try the <a href="http://flashrealtime.com/demos/carfollowcamera/CarWithFollowCamera.html">final app here</a>.</p>
<p>You will have also tons of questions, like adding slipping, physics, collisions, etc. Well &#8211; next time ;)</p>
<h3>Source</h3>
<p><a href="http://flashrealtime.com/demos/carfollowcamera/CarWithFollowCamera.as">Download the source code</a></p>
<p>The complete source code looks like this:</p>

<div class="wp_syntax"><div class="code"><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> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>Camera3D<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>Object3D<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>Resource<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>View<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>materials<span style="color: #000066; font-weight: bold;">.</span>FillMaterial<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>materials<span style="color: #000066; font-weight: bold;">.</span>TextureMaterial<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>primitives<span style="color: #000066; font-weight: bold;">.</span>Box<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>resources<span style="color: #000066; font-weight: bold;">.</span>TextureResource<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</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>Stage3D<span style="color: #000066; font-weight: bold;">;</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><span style="color: #004993;">StageAlign</span><span style="color: #000066; font-weight: bold;">;</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><span style="color: #004993;">StageScaleMode</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> flash<span style="color: #000066; font-weight: bold;">.</span>display3D<span style="color: #000066; font-weight: bold;">.</span>textures<span style="color: #000066; font-weight: bold;">.</span>Texture<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Point</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.ui</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Keyboard</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #000000;">&#91;</span>SWF<span style="color: #000000;">&#40;</span><span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;800&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;600&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">frameRate</span>=<span style="color: #990000;">&quot;30&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> CarWithFollowCamera <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> rootContainer<span style="color: #000066; font-weight: bold;">:</span>Object3D = <span style="color: #0033ff; font-weight: bold;">new</span> Object3D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> camera<span style="color: #000066; font-weight: bold;">:</span>Camera3D<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> stage3D<span style="color: #000066; font-weight: bold;">:</span>Stage3D<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> speed<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> steering<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> accelerate<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span><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> brake<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span><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> turn_left<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span><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> turn_right<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> cameraDistance<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">800</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;sand.jpg&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> texture<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Class</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> car<span style="color: #000066; font-weight: bold;">:</span>Object3D<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> carBody<span style="color: #000066; font-weight: bold;">:</span>Box<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> carFront<span style="color: #000066; font-weight: bold;">:</span>Box<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> CarWithFollowCamera<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">align</span> = <span style="color: #004993;">StageAlign</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TOP_LEFT</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">scaleMode</span> = <span style="color: #004993;">StageScaleMode</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NO_SCALE</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">// CAMERA</span>
			camera = <span style="color: #0033ff; font-weight: bold;">new</span> Camera3D<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0.1</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">10000</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			camera<span style="color: #000066; font-weight: bold;">.</span>view = <span style="color: #0033ff; font-weight: bold;">new</span> View<span style="color: #000000;">&#40;</span><span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageWidth</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageHeight</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>camera<span style="color: #000066; font-weight: bold;">.</span>view<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">// init camera settings</span>
			camera<span style="color: #000066; font-weight: bold;">.</span>rotationX = deg2rad<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">70</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">//camera.y = -300;</span>
			camera<span style="color: #000066; font-weight: bold;">.</span>rotationZ = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">;</span>
			camera<span style="color: #000066; font-weight: bold;">.</span>z = <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>
&nbsp;
			rootContainer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>camera<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">// CAR</span>
			car = <span style="color: #0033ff; font-weight: bold;">new</span> Object3D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// car body</span>
			carBody = <span style="color: #0033ff; font-weight: bold;">new</span> Box<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">300</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> material<span style="color: #000066; font-weight: bold;">:</span>FillMaterial = <span style="color: #0033ff; font-weight: bold;">new</span> FillMaterial<span style="color: #000000;">&#40;</span>0xFFFF00<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0.8</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			carBody<span style="color: #000066; font-weight: bold;">.</span>setMaterialToAllSurfaces<span style="color: #000000;">&#40;</span>material<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			carBody<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; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">;</span>
			car<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>carBody<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// car front</span>
			carFront = <span style="color: #0033ff; font-weight: bold;">new</span> Box<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			carFront<span style="color: #000066; font-weight: bold;">.</span>setMaterialToAllSurfaces<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> FillMaterial<span style="color: #000000;">&#40;</span>0xFFFF00<span style="color: #000066; font-weight: bold;">,.</span>9<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			car<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>carFront<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>		
&nbsp;
			car<span style="color: #000066; font-weight: bold;">.</span>z = <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span>
			rootContainer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>car<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">// MAP</span>
			generateRandomMapOfCubes<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">// INIT Stage3D</span>
			stage3D = <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span>stage3Ds<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
			stage3D<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span>CONTEXT3D_CREATE<span style="color: #000066; font-weight: bold;">,</span> onContextCreate<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			stage3D<span style="color: #000066; font-weight: bold;">.</span>requestContext3D<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>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> followCarWithCamera<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: #009900; font-style: italic;">// Simple smoothing</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> targetX<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = car<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: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span>car<span style="color: #000066; font-weight: bold;">.</span>rotationZ<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span>cameraDistance<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> targetY<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = car<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;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span>car<span style="color: #000066; font-weight: bold;">.</span>rotationZ<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span>cameraDistance<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> targetZRotation<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = car<span style="color: #000066; font-weight: bold;">.</span>rotationZ<span style="color: #000066; font-weight: bold;">+</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			camera<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>camera<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">-</span> targetX<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*.</span>2<span style="color: #000066; font-weight: bold;">;</span>
			camera<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>camera<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">-</span> targetY<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*.</span>2<span style="color: #000066; font-weight: bold;">;</span>
			camera<span style="color: #000066; font-weight: bold;">.</span>rotationZ <span style="color: #000066; font-weight: bold;">-</span>= <span style="color: #000000;">&#40;</span>camera<span style="color: #000066; font-weight: bold;">.</span>rotationZ <span style="color: #000066; font-weight: bold;">-</span> targetZRotation<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*.</span>2<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">loop</span><span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</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: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>accelerate <span style="color: #000066; font-weight: bold;">&amp;</span>amp<span style="color: #000066; font-weight: bold;">;&amp;</span>amp<span style="color: #000066; font-weight: bold;">;</span> speed<span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> 				speed<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;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>brake<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> 				speed<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;">else</span><span style="color: #000000;">&#123;</span> 				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">abs</span><span style="color: #000000;">&#40;</span>speed<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&amp;</span>gt<span style="color: #000066; font-weight: bold;">;</span><span style="color: #000000; font-weight:bold;">0.3</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					speed<span style="color: #000066; font-weight: bold;">*</span>=<span style="color: #000000; font-weight:bold;">0.96</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>
					speed=<span style="color: #000000; font-weight:bold;">0</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>turn_left<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				steering <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">40</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000;">&#40;</span>speed<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">100</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>turn_right<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				steering <span style="color: #000066; font-weight: bold;">-</span>= <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">40</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000;">&#40;</span>speed<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			car<span style="color: #000066; font-weight: bold;">.</span>rotationZ = <span style="color: #000066; font-weight: bold;">-</span>steering
&nbsp;
			car<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span>= speed<span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span>steering<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			car<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">+</span>= speed<span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span>steering<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			followCarWithCamera<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			camera<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">render</span><span style="color: #000000;">&#40;</span>stage3D<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> onKeyDown<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">KeyboardEvent</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: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">keyCode</span>==<span style="color: #000000; font-weight:bold;">38</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				accelerate=<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>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">keyCode</span>==<span style="color: #000000; font-weight:bold;">40</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				brake=<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>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">keyCode</span>==<span style="color: #000000; font-weight:bold;">37</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				turn_left=<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>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">keyCode</span>==<span style="color: #000000; font-weight:bold;">39</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				turn_right=<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: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> onKeyUp<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">KeyboardEvent</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: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">keyCode</span>==<span style="color: #000000; font-weight:bold;">38</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				accelerate=<span style="color: #0033ff; font-weight: bold;">false</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>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">keyCode</span>==<span style="color: #000000; font-weight:bold;">40</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				brake=<span style="color: #0033ff; font-weight: bold;">false</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>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">keyCode</span>==<span style="color: #000000; font-weight:bold;">37</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				turn_left=<span style="color: #0033ff; font-weight: bold;">false</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>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">keyCode</span>==<span style="color: #000000; font-weight:bold;">39</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				turn_right=<span style="color: #0033ff; font-weight: bold;">false</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: #009900; font-style: italic;">// HELPER METHODS // not important to study them</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> onContextCreate<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</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: #0033ff; font-weight: bold;">for</span> <span style="color: #0033ff; font-weight: bold;">each</span><span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> resource<span style="color: #000066; font-weight: bold;">:</span>Resource <span style="color: #0033ff; font-weight: bold;">in</span> rootContainer<span style="color: #000066; font-weight: bold;">.</span>getResources<span style="color: #000000;">&#40;</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>
				resource<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">upload</span><span style="color: #000000;">&#40;</span>stage3D<span style="color: #000066; font-weight: bold;">.</span>context3D<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">loop</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">KEY_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> onKeyDown<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">KEY_UP</span><span style="color: #000066; font-weight: bold;">,</span> onKeyUp<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</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> generateRandomMapOfCubes<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: #6699cc; font-weight: bold;">var</span> ground<span style="color: #000066; font-weight: bold;">:</span>Box = <span style="color: #0033ff; font-weight: bold;">new</span> Box<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10000</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">10000</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>
			ground<span style="color: #000066; font-weight: bold;">.</span>setMaterialToAllSurfaces<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> FillMaterial<span style="color: #000000;">&#40;</span>0xCCCCCC<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0.3</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			rootContainer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>ground<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>i<span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span><span style="color: #000000; font-weight:bold;">30</span><span style="color: #000066; font-weight: bold;">;</span>i<span style="color: #000066; font-weight: bold;">++</span><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;">height</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">Math</span><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;">700</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">:</span>Box = <span style="color: #0033ff; font-weight: bold;">new</span> Box<span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><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;">700</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">Math</span><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;">700</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">height</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span>setMaterialToAllSurfaces<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> FillMaterial<span style="color: #000000;">&#40;</span>0xCCCCCC<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0.5</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: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span>z = <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: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">5000</span><span style="color: #000066; font-weight: bold;">-</span><span style="color: #004993;">Math</span><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;">10000</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">5000</span><span style="color: #000066; font-weight: bold;">-</span><span style="color: #004993;">Math</span><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;">10000</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
				rootContainer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">b</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: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> rad2deg<span style="color: #000000;">&#40;</span>radnum<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> radnum<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</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> deg2rad<span style="color: #000000;">&#40;</span>degnum<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> degnum<span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">180</span><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></div></div>

 <div class='series_toc'></div>	<p></p>
	<hr noshade style="margin:0;height:1px" />
	<p>&copy; TomKrcha for <a href="http://mochiland.com">MochiLand</a>, 2011. |
	  <a href="http://mochiland.com/articles/tutorial-3d-car-with-a-camera-following-it">Permalink</a> |
	  <a href="http://mochiland.com/articles/tutorial-3d-car-with-a-camera-following-it#comments">5 comments</a></p>
	<p>Add to <a href="http://del.icio.us/post?url=http://mochiland.com/articles/tutorial-3d-car-with-a-camera-following-it&amp;title=Tutorial: 3D Car With A Camera Following It">del.icio.us</a></p>
	<p>Search blogs linking this post with <a href="http://www.technorati.com/search/http://mochiland.com/articles/tutorial-3d-car-with-a-camera-following-it" title="Search on Technorati">Technorati</a></p>
	<p>Want more on these topics ? Browse the archive of posts filed under <a href="http://mochiland.com/category/mochiland/developer-feed" title="View all posts in Developer Feed" rel="category tag">Developer Feed</a>, <a href="http://mochiland.com/category/mochiland/flash" title="View all posts in Flash Development" rel="category tag">Flash Development</a>, <a href="http://mochiland.com/category/mochiland/front-page" title="View all posts in Front Page" rel="category tag">Front Page</a>, <a href="http://mochiland.com/category/mochiland/game-design" title="View all posts in Game Design" rel="category tag">Game Design</a>, <a href="http://mochiland.com/category/mochiland" title="View all posts in MochiLand Topics" rel="category tag">MochiLand Topics</a>, <a href="http://mochiland.com/category/mochiland/tutorials" title="View all posts in Tutorials" rel="category tag">Tutorials</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://mochiland.com/articles/tutorial-3d-car-with-a-camera-following-it/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

