<?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>Emanuele Feronato &#187; Flex</title>
	<atom:link href="http://www.emanueleferonato.com/category/flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.emanueleferonato.com</link>
	<description>italian geek and PROgrammer</description>
	<lastBuildDate>Wed, 10 Mar 2010 17:35:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>flixel for absolute beginners &#8211; part 2</title>
		<link>http://www.emanueleferonato.com/2009/09/02/flixel-for-absolute-beginners-part-2/</link>
		<comments>http://www.emanueleferonato.com/2009/09/02/flixel-for-absolute-beginners-part-2/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 09:59:40 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Game design]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=1609</guid>
		<description><![CDATA[In flixel for absolute beginners I showed you how to complile a flixel project with Flex Builder 3.
I was ready to make an &#8220;hello world&#8221; but I received some emails from people asking for a FlashDevelop step by step installation.
It seems FlashDevelop is more popular than FlexBuilder 3&#8230; anyway here it is:
First, you need to [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.emanueleferonato.com/2009/09/02/flixel-for-absolute-beginners/">flixel for absolute beginners</a> I showed you how to complile a flixel project with Flex Builder 3.</p>
<p>I was ready to make an &#8220;hello world&#8221; but I received some emails from people asking for a FlashDevelop step by step installation.</p>
<p>It seems FlashDevelop is more popular than FlexBuilder 3&#8230; anyway here it is:</p>
<p>First, you need to download the free <a target = "_blank" href="http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+3">Flex 3 SDK</a> and unzip it anywhere in your hard disk.</p>
<p>Then, open FlashDevelop and follow these steps:</p>
<p><img src="/images/flixel21.jpg" alt="" /></p>
<p>Select <code>Project</code> -> <code>New Project</code><span id="more-1609"></span></p>
<p><img src="/images/flixel22.jpg" alt="" /></p>
<p>Select <code>AS3 Project</code>, give your project a name and a path</p>
<p><img src="/images/flixel23.jpg" alt="" /></p>
<p>Copy the entire content of the flixel package into the <code>src</code> folder FlashDevelop just created</p>
<p><img src="/images/flixel24.jpg" alt="" /></p>
<p>In the <code>Project</code> window, delete <code>Main.as</code></p>
<p><img src="/images/flixel25.jpg" alt="" /></p>
<p>Set the <code>Always Compile</code> property of <code>Mode.as</code></p>
<p><img src="/images/flixel26.jpg" alt="" /></p>
<p>Test the project</p>
<p><img src="/images/flixel27.jpg" alt="" /></p>
<p>If it&#8217;s you first time running the project, set the <code>Flex SDK Location</code> attribute according to the path of your SDK, then test the project again, and you&#8217;ll see the demo platformer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/09/02/flixel-for-absolute-beginners-part-2/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>flixel for absolute beginners</title>
		<link>http://www.emanueleferonato.com/2009/09/02/flixel-for-absolute-beginners/</link>
		<comments>http://www.emanueleferonato.com/2009/09/02/flixel-for-absolute-beginners/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 23:53:30 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Game design]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=1599</guid>
		<description><![CDATA[flixel (with no uppercase) is Adam &#8220;Atomic&#8221; Saltsman free collection of Actionscript 3 files that helps organize, automate, and optimize Flash 2D raster based game development.

You can download it at the official flixel webiste.
The library is not that hard to use, but browsing the web I did not find any basic tutorial for absolute beginners, [...]]]></description>
			<content:encoded><![CDATA[<p><strong>flixel</strong> (with no uppercase) is <strong>Adam &#8220;Atomic&#8221; Saltsman</strong> free collection of Actionscript 3 files that helps organize, automate, and optimize Flash 2D raster based game development.</p>
<p><a href="http://flixel.org/" target = "_blank"><img src="/images/flixel[1].png" alt="flixel" /></a></p>
<p>You can download it at the <a href="http://flixel.org/" target = "_blank">official flixel webiste</a>.</p>
<p>The library is not that hard to use, but browsing the web I did not find any basic tutorial for absolute beginners, so it&#8217;s time to introduce you to this package.</p>
<p>flixel is not intended to be used with the Flash IDE, since it is a pure Actionscript library, so you will need <strong><a href="http://www.adobe.com/products/flex/" target = "_blank">Adobe Flex Builder 3</a></strong> you can try for free for 60 days at <a href="http://www.adobe.com/cfusion/entitlement/index.cfm?e=flexbuilder3">this link</a> or <strong><a href="http://www.flashdevelop.org/" target = "_blank">FlashDevelop</a></strong> you can freely download at <a href="http://www.flashdevelop.org/community/viewtopic.php?f=11&#038;t=5339">this link</a>.</p>
<p>This time I&#8217;ll show you how to launch the demo game, called Mode, with Adobe Flex Builder&#8230; something very easy but maybe new for some of you&#8230; later we&#8217;ll create an &#8220;Hello World&#8221;.<span id="more-1599"></span></p>
<p><img src="/images/flixel01.jpg" alt="" /></p>
<p>Select <code>File</code> -> <code>Import</code> -> <code>Other</code></p>
<p><img src="/images/flixel02.jpg" alt="" /></p>
<p>From the dialog, select <code>General</code> -> <code>Existing Projects into Workspace</code>, then click <code>Next</code></p>
<p><img src="/images/flixel03.jpg" alt="" /></p>
<p>Check <code>Select root directory</code> then click <code>Browse</code> and select your flixel folder</p>
<p><img src="/images/flixel04.jpg" alt="" /></p>
<p>At this time check <code>Mode</code> is checked and click on <code>Finish</code></p>
<p><img src="/images/flixel05.jpg" alt="" /></p>
<p>You&#8217;ll notice an error in the lower part of the work area, right click on it and select <code>Recreate HTML Templates</code></p>
<p><img src="/images/flixel06.jpg" alt="" /></p>
<p>Finally, run the project.</p>
<p>This is what you&#8217;ll get&#8230;</p>
<p><embed src="/downloads/Mode.swf" menu="false" quality="high" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="520" height="480"></p>
<p>Next, time, as said, an Hello World.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/09/02/flixel-for-absolute-beginners/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Official Facebook Actionscript API released!</title>
		<link>http://www.emanueleferonato.com/2009/04/09/official-facebook-actionscript-api-released/</link>
		<comments>http://www.emanueleferonato.com/2009/04/09/official-facebook-actionscript-api-released/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 09:43:48 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=1120</guid>
		<description><![CDATA[On March 31 Facebook developers announced that Adobe and Facebook are working together to provide official support for building rich social applications in Flash.

You can read the full Josh Elman&#8217;s announcement at this link.
The new ActionScript 3.0 Client Library for Facebook Platform API, fully supported by Facebook and Adobe, makes it easy to build applications [...]]]></description>
			<content:encoded><![CDATA[<p>On March 31 Facebook developers announced that <strong>Adobe and Facebook are working together</strong> to provide official support for building rich social applications in Flash.</p>
<p><img src="/images/flash_facebook[1].jpg" alt="" /></p>
<p>You can read the full Josh Elman&#8217;s announcement at <a href="http://developers.facebook.com/news.php?blog=1&#038;story=217" target = "_blank">this link</a>.</p>
<p>The new ActionScript 3.0 Client Library for Facebook Platform API, fully supported by Facebook and Adobe, makes it easy to build applications that combine the strengths of the Flash Platform and Facebook Platform.</p>
<p>Flash is available on more than 98% of Internet-connected PCs, so people can immediately access the applications, content, and video that enable social interactions. The Facebook Platform is used by millions of people everyday to connect and share with the people in their lives.</p>
<p>You can read more about it at <a target = "_blank" href="http://www.adobe.com/devnet/facebook/">this page</a>.</p>
<p>Obviously I started playing with this new API, and I followed the instructions in the official tutorial <a href="http://www.adobe.com/devnet/facebook/articles/build_your_first_facebook_app.html" target = "_blank">Create your first Facebook application with Flex</a>, changing a couple of things to make it work as I wanted.<span id="more-1120"></span></p>
<p>This is the source code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Application xmlns<span style="color: #000000; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #990000;">&quot;vertical&quot;</span> 
	<span style="color: #004993;">backgroundColor</span>=<span style="color: #990000;">&quot;silver&quot;</span> backgroundImage=<span style="color: #990000;">&quot;&quot;</span>
	applicationComplete=<span style="color: #990000;">&quot;init()&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Script<span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span>
			<span style="color: #0033ff; font-weight: bold;">import</span> com.facebook.<span style="color: #004993;">data</span>.users.GetInfoData;
			<span style="color: #0033ff; font-weight: bold;">import</span> com.facebook.utils.FacebookSessionUtil;
			<span style="color: #0033ff; font-weight: bold;">import</span> com.facebook.<span style="color: #004993;">data</span>.users.FacebookUser;
			<span style="color: #0033ff; font-weight: bold;">import</span> com.facebook.<span style="color: #004993;">data</span>.users.GetInfoFieldValues;
			<span style="color: #0033ff; font-weight: bold;">import</span> com.facebook.commands.users.GetInfo;
			<span style="color: #0033ff; font-weight: bold;">import</span> com.facebook.net.FacebookCall;
			<span style="color: #0033ff; font-weight: bold;">import</span> com.facebook.events.FacebookEvent;
			<span style="color: #0033ff; font-weight: bold;">import</span> com.facebook.Facebook;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> fbook<span style="color: #000000; font-weight: bold;">:</span>Facebook;
			<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> session<span style="color: #000000; font-weight: bold;">:</span>FacebookSessionUtil;
			<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> user<span style="color: #000000; font-weight: bold;">:</span>FacebookUser;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
				session=<span style="color: #0033ff; font-weight: bold;">new</span> FacebookSessionUtil<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;83ccead57ece4086338470a75e13c5b1&quot;</span>,<span style="color: #990000;">&quot;1fff6abf608e90e70e1aad07798aa8e4&quot;</span>,<span style="color: #004993;">loaderInfo</span><span style="color: #000000;">&#41;</span>;
				session.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>FacebookEvent.<span style="color: #004993;">CONNECT</span>,onConnect<span style="color: #000000;">&#41;</span>;
				fbook=session.facebook;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onLogin<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; 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;">this</span>.<span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span>go_login<span style="color: #000000;">&#41;</span>;
				session.login<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</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> onConfirmLogin<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; 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;">this</span>.<span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span>loginbutton<span style="color: #000000;">&#41;</span>;
				session.validateLogin<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</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> onConnect<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span>FacebookEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; 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> <span style="color: #004993;">call</span><span style="color: #000000; font-weight: bold;">:</span>FacebookCall=fbook.post<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> GetInfo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>fbook.uid<span style="color: #000000;">&#93;</span>,<span style="color: #000000;">&#91;</span>GetInfoFieldValues.ALL_VALUES<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
				<span style="color: #004993;">call</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>FacebookEvent.<span style="color: #004993;">COMPLETE</span>,onGetInfo<span style="color: #000000;">&#41;</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> onGetInfo<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span>FacebookEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
				user=<span style="color: #000000;">&#40;</span>e.<span style="color: #004993;">data</span> <span style="color: #0033ff; font-weight: bold;">as</span> GetInfoData<span style="color: #000000;">&#41;</span>.userCollection.getItemAt<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> FacebookUser;
				title.<span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Hello &quot;</span><span style="color: #000000; font-weight: bold;">+</span>user.first_name<span style="color: #000000; font-weight: bold;">+</span><span style="color: #990000;">&quot; &quot;</span><span style="color: #000000; font-weight: bold;">+</span>user.last_name<span style="color: #000000; font-weight: bold;">+</span><span style="color: #990000;">&quot; born on &quot;</span><span style="color: #000000; font-weight: bold;">+</span>user.birthday;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>Script<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Label id=<span style="color: #990000;">&quot;title&quot;</span> <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Facebook API test&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;go_login&quot;</span> label=<span style="color: #990000;">&quot;Click here to login into Facebook&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;onLogin()&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;loginbutton&quot;</span> label=<span style="color: #990000;">&quot;Click once logged into Facebook&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;onConfirmLogin()&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>Application<span style="color: #000000; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<p>And this is the result:</p>
<p><embed src="/downloads/provaflex.swf" allowscriptaccess="always" menu="false" quality="high" width="500" height="120" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></p>
<p>As I am not a Flex maniac, I will fully explain (and improve) the script as soon as I&#8217;ll convert it to an AS3 class. Meanwhile I want you to focus on <strong>line 40</strong> where I am getting information about the user.</p>
<p>The official page where you can get all the information about this process is <a href="http://wiki.developers.facebook.com/index.php/Users.getInfo" target = "_blank">this one</a>.</p>
<p>Meanwhile, you can <a href="/downloads/provaflex.zip">download the full source code</a> with all needed libraries.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/04/09/official-facebook-actionscript-api-released/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Perfect maze generation &#8211; tile based version &#8211; AS3</title>
		<link>http://www.emanueleferonato.com/2008/12/08/perfect-maze-generation-tile-based-version-as3/</link>
		<comments>http://www.emanueleferonato.com/2008/12/08/perfect-maze-generation-tile-based-version-as3/#comments</comments>
		<pubDate>Mon, 08 Dec 2008 10:34:19 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=703</guid>
		<description><![CDATA[After publishing Perfect maze generation &#8211; tile based version written in Php, I got some emails asking for an AS3 version.
Pedro Taranto made the AS3 porting in less than a day, and here&#8217;s what you&#8217;ll get:

Click on the maze to generate a new one
And this is the source code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package br.com.pedrotaranto
&#123;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;
	import flash.geom.Point;
&#160;
	&#91;SWF&#40;backgroundColor [...]]]></description>
			<content:encoded><![CDATA[<p>After publishing <a href="http://www.emanueleferonato.com/2008/12/06/perfect-maze-generation-tile-based-version/">Perfect maze generation &#8211; tile based version</a> written in Php, I got some emails asking for an AS3 version.</p>
<p><strong>Pedro Taranto</strong> made the AS3 porting in less than a day, and here&#8217;s what you&#8217;ll get:</p>
<p><embed src="/downloads/tiledMazeGen.swf" allowscriptaccess="always" menu="false" quality="high" type="application/x-shockwave-flash" width ="500" height="420" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></p>
<p>Click on the maze to generate a new one</p>
<p>And this is the source code:<span id="more-703"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> br.com.pedrotaranto
<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: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">StageAlign</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">StageScaleMode</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">MouseEvent</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span>.<span style="color: #004993;">Point</span>;
&nbsp;
	<span style="color: #000000;">&#91;</span>SWF<span style="color: #000000;">&#40;</span><span style="color: #004993;">backgroundColor</span> = <span style="color: #990000;">&quot;#FFFFFF&quot;</span>, <span style="color: #004993;">width</span> = <span style="color: #990000;">'800'</span>, <span style="color: #004993;">height</span> = <span style="color: #990000;">'600'</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> TiledMazeGen extends <span style="color: #004993;">Sprite</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #009900;">//constants</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> const MAZE_WIDTH		<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">20</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> const MAZE_HEIGHT		<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">20</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> const TILE_SIZE			<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">10</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> const START_COLOR		<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span> = 0xFF0000;
		<span style="color: #0033ff; font-weight: bold;">private</span> const FINISH_COLOR		<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span> = 0x00FF00;
		<span style="color: #0033ff; font-weight: bold;">private</span> const WALL_COLOR		<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span> = 0x000000;
		<span style="color: #0033ff; font-weight: bold;">private</span> const WALKABLE_COLOR	<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span> = 0xDDDDDD;
&nbsp;
		<span style="color: #009900;">//directions</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> const NORTH				<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;N&quot;</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> const SOUTH				<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;S&quot;</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> const EAST				<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;E&quot;</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> const WEST				<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;W&quot;</span>;
&nbsp;
		<span style="color: #009900;">//variables</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _width		<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _height		<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _maze		<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Array</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _moves		<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Array</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _start		<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Point</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _finish		<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Point</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _container	<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Sprite</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> TiledMazeGen <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">align</span>		= <span style="color: #004993;">StageAlign</span>.<span style="color: #004993;">TOP_LEFT</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">scaleMode</span>	= <span style="color: #004993;">StageScaleMode</span>.<span style="color: #004993;">NO_SCALE</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>, _generate<span style="color: #000000;">&#41;</span>;
&nbsp;
			_width	= MAZE_WIDTH <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span>;
			_height	= MAZE_HEIGHT <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span>;
&nbsp;
			_start	= <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span>, <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">//_finish = new Point(_height - 2, _width - 2);</span>
&nbsp;
			_container = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			_generate<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<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> _generate <span style="color: #000000;">&#40;</span> event <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> = <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			_initMaze<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			_createMaze<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			_drawMaze<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<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> _initMaze <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			_maze	= <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span>_width<span style="color: #000000;">&#41;</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> <span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span>; <span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">&lt;</span> _height; <span style="color: #004993;">x</span><span style="color: #000000; font-weight: bold;">++</span> <span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				_maze<span style="color: #000000;">&#91;</span><span style="color: #004993;">x</span><span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span>_height<span style="color: #000000;">&#41;</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> <span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span>; <span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">&lt;</span> _width; <span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">++</span> <span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					_maze<span style="color: #000000;">&#91;</span><span style="color: #004993;">x</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #004993;">y</span><span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			_maze<span style="color: #000000;">&#91;</span>_start.<span style="color: #004993;">x</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>_start.<span style="color: #004993;">y</span><span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">false</span>;
		<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> _createMaze <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; 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> back				<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">int</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> move				<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">int</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> possibleDirections	<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> pos					<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Point</span> = _start.<span style="color: #004993;">clone</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			_moves = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			_moves.<span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>pos.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span>pos.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">*</span> _width<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span> _moves.<span style="color: #004993;">length</span> <span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				possibleDirections = <span style="color: #990000;">&quot;&quot;</span>;
&nbsp;
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>pos.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000; font-weight: bold;">&lt;</span> _height <span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000;">&#40;</span>_maze<span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">y</span><span style="color: #000000;">&#93;</span> == <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000;">&#40;</span>pos.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000;">&#40;</span>pos.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000; font-weight: bold;">!</span>= _height <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					possibleDirections <span style="color: #000000; font-weight: bold;">+</span>= SOUTH;
				<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: #000000;">&#40;</span>pos.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000; font-weight: bold;">&gt;</span>= <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000;">&#40;</span>_maze<span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">y</span><span style="color: #000000;">&#93;</span> == <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000;">&#40;</span>pos.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000;">&#40;</span>pos.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000; font-weight: bold;">!</span>= _height <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					possibleDirections <span style="color: #000000; font-weight: bold;">+</span>= NORTH;
				<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: #000000;">&#40;</span>pos.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000; font-weight: bold;">&gt;</span>= <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000;">&#40;</span>_maze<span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">x</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span> == <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000;">&#40;</span>pos.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000;">&#40;</span>pos.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000; font-weight: bold;">!</span>= _width <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					possibleDirections <span style="color: #000000; font-weight: bold;">+</span>= WEST;
				<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: #000000;">&#40;</span>pos.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000; font-weight: bold;">&lt;</span> _width <span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000;">&#40;</span>_maze<span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">x</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span> == <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000;">&#40;</span>pos.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000;">&#40;</span>pos.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000; font-weight: bold;">!</span>= _width <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					possibleDirections <span style="color: #000000; font-weight: bold;">+</span>= EAST;
				<span style="color: #000000;">&#125;</span>
&nbsp;
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> possibleDirections.<span style="color: #004993;">length</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					move = _randInt<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000;">&#40;</span>possibleDirections.<span style="color: #004993;">length</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
					<span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span> possibleDirections.<span style="color: #004993;">charAt</span><span style="color: #000000;">&#40;</span>move<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>
					<span style="color: #000000;">&#123;</span>
						<span style="color: #0033ff; font-weight: bold;">case</span> NORTH<span style="color: #000000; font-weight: bold;">:</span> 
							_maze<span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">y</span><span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">false</span>;
							_maze<span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">y</span><span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">false</span>;
							pos.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">-</span>=<span style="color: #000000; font-weight:bold;">2</span>;
							<span style="color: #0033ff; font-weight: bold;">break</span>;
&nbsp;
						<span style="color: #0033ff; font-weight: bold;">case</span> SOUTH<span style="color: #000000; font-weight: bold;">:</span> 
							_maze<span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">y</span><span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">false</span>;
							_maze<span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">y</span><span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">false</span>;
							pos.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">+</span>=<span style="color: #000000; font-weight:bold;">2</span>;
							<span style="color: #0033ff; font-weight: bold;">break</span>;
&nbsp;
						<span style="color: #0033ff; font-weight: bold;">case</span> WEST<span style="color: #000000; font-weight: bold;">:</span> 
							_maze<span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">x</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">false</span>;
							_maze<span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">x</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">false</span>;
							pos.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">-</span>=<span style="color: #000000; font-weight:bold;">2</span>;
							<span style="color: #0033ff; font-weight: bold;">break</span>;
&nbsp;
						<span style="color: #0033ff; font-weight: bold;">case</span> EAST<span style="color: #000000; font-weight: bold;">:</span> 
							_maze<span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">x</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">false</span>;
							_maze<span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">x</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>pos.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">false</span>;
							pos.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">+</span>=<span style="color: #000000; font-weight:bold;">2</span>;
							<span style="color: #0033ff; font-weight: bold;">break</span>;        
					<span style="color: #000000;">&#125;</span>
&nbsp;
					_moves.<span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>pos.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span>pos.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">*</span> _width<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
				<span style="color: #000000;">&#125;</span>
				<span style="color: #0033ff; font-weight: bold;">else</span>
				<span style="color: #000000;">&#123;</span>
					back = _moves.<span style="color: #004993;">pop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
					pos.<span style="color: #004993;">x</span> = <span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span>back <span style="color: #000000; font-weight: bold;">/</span> _width<span style="color: #000000;">&#41;</span>;
					pos.<span style="color: #004993;">y</span> = back <span style="color: #000000; font-weight: bold;">%</span> _width;
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
		<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> _drawMaze <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; 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> tile <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Sprite</span>;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> <span style="color: #004993;">contains</span><span style="color: #000000;">&#40;</span>_container<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span>_container<span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			_container = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>_container<span style="color: #000000;">&#41;</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> <span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span>; <span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">&lt;</span> _height; <span style="color: #004993;">x</span><span style="color: #000000; font-weight: bold;">++</span> <span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</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> <span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span>; <span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">&lt;</span> _width; <span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">++</span> <span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					tile	= <span style="color: #000000;">&#40;</span>_maze<span style="color: #000000;">&#91;</span><span style="color: #004993;">x</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #004993;">y</span><span style="color: #000000;">&#93;</span> == <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">?</span> _drawTile<span style="color: #000000;">&#40;</span>WALL_COLOR<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> _drawTile<span style="color: #000000;">&#40;</span>WALKABLE_COLOR<span style="color: #000000;">&#41;</span>;
					tile.<span style="color: #004993;">x</span>	= <span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">*</span> TILE_SIZE;
					tile.<span style="color: #004993;">y</span>	= <span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">*</span> TILE_SIZE;
&nbsp;
					_container.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>tile<span style="color: #000000;">&#41;</span>;
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #009900;">//start tile</span>
			tile = _drawTile<span style="color: #000000;">&#40;</span>START_COLOR<span style="color: #000000;">&#41;</span>;
			tile.<span style="color: #004993;">x</span> = _start.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">*</span> TILE_SIZE;
			tile.<span style="color: #004993;">y</span> = _start.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">*</span> TILE_SIZE;
			_container.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>tile<span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #009900;">//finish tile</span>
			<span style="color: #3f5fbf;">/*tile = _drawTile(FINISH_COLOR);
			tile.x = _finish.x * TILE_SIZE;
			tile.y = _finish.y * TILE_SIZE;
			_container.addChild(tile);*/</span>
		<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> _drawTile <span style="color: #000000;">&#40;</span> <span style="color: #004993;">color</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Sprite</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> tile <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Sprite</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
				tile.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">color</span><span style="color: #000000;">&#41;</span>;
				tile.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>, <span style="color: #000000; font-weight:bold;">0</span>, TILE_SIZE, TILE_SIZE<span style="color: #000000;">&#41;</span>;
				tile.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">return</span> tile;
		<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> _randInt <span style="color: #000000;">&#40;</span> <span style="color: #004993;">min</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">int</span>, <span style="color: #004993;">max</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">int</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">int</span> 
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span>.<span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">max</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #004993;">min</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">min</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><a href="/downloads/TiledMazeGen.zip">Download the source</a> and enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2008/12/08/perfect-maze-generation-tile-based-version-as3/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>New tile based platform engine &#8211; AS3 version updated to step 10 PLUS scrolling</title>
		<link>http://www.emanueleferonato.com/2008/10/14/new-tile-based-platform-engine-as3-version-updated-to-step-10-plus-scrolling/</link>
		<comments>http://www.emanueleferonato.com/2008/10/14/new-tile-based-platform-engine-as3-version-updated-to-step-10-plus-scrolling/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 11:25:45 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=573</guid>
		<description><![CDATA[If you are looking for AS3 version of step 10, here it is&#8230; made by Robin vd Vleuten from the Netherlands with scrolling included!
Hello Emanuele,
I made it with flex so I use a swc to access the tiles. All the code is now in one actionscript-file, but I&#8217;m trying to convert the code in different [...]]]></description>
			<content:encoded><![CDATA[<p>If you are looking for AS3 version of <a href="http://www.emanueleferonato.com/2008/10/13/new-tile-based-platform-engine-part-10-optimization-doors-n-keys/">step 10</a>, here it is&#8230; made by <strong>Robin vd Vleuten</strong> from the Netherlands with scrolling included!</p>
<blockquote><p>Hello Emanuele,</p>
<p>I made it with flex so I use a swc to access the tiles. All the code is now in one actionscript-file, but I&#8217;m trying to convert the code in different classes. I will email it also when its finished if you&#8217;re interested in it.</p>
<p>Also many thanks for helping me out with the basics of a platform engine. It helped me a lot with a project I&#8217;m working on.</p>
<p>Regards,</p>
<p>Robin</p>
<p>P.S. Just another cool thing I had forgot to tell you. I made the game scrollable with just 2 extra lines of code :D</p></blockquote>
<p>Here it is the source code&#8230;<span id="more-573"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
</pre></td><td class="code"><pre class="actionscript2" style="font-family:monospace;">package {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
&nbsp;
	[SWF(width='500', height='400', frameRate='40', backgroundColor='0xffffff')]
	public class Platform extends Sprite
	{
		private var over:String = &quot;&quot;;
		private var bonus_speed:Number = 0;
		private var press_left:Boolean = false;
		private var press_right:Boolean = false;
		private var press_up:Boolean = false;
		private var press_down:Boolean = false;
		private var press_space:Boolean = false;
		private var x_pos:Number = 0;
		private var y_pos:Number = 0;
		private var tile_size:Number = 20;
		private var ground_acceleration:Number = 1;
		private var ground_friction:Number = 0.8;
		private var air_acceleration:Number = 0.5;
		private var air_friction:Number = 0.7;
		private var ice_acceleration:Number = 0.15;
		private var ice_friction:Number = 0.95;
		private var treadmill_speed:Number = 2;
		private var max_speed:Number = 3;
		private var xspeed:Number = 0;
		private var yspeed:Number = 0;
		private var falling:Boolean = false;
		private var gravity:Number = 0.5;
		private var jump_speed:Number = 6;
		private var climbing:Boolean = false;
		private var climb_speed:Number = 0.8;
		private var coins:Array = new Array();
		private var level:Array = new Array();
		private var levelObj:Array = new Array
		private var keys:Array = new Array();
		private var player:Array = new Array();
		private var enemy:Array = new Array();
		private var walkable_tiles:Array = new Array(0, 5, 6, 7);
		private var h:hero = new hero();
		private var level_container:Sprite = new Sprite();
&nbsp;
		private var bottom:Number;
		private var left:Number;
		private var right:Number;
		private var top:Number;
		private var bottom_left:Number;
		private var bottom_right:Number;
		private var top_left:Number;
		private var top_right:Number;
&nbsp;
		private var climbdir:Number;
		private var current_tile:Number;
		private var friction:Number;
&nbsp;
		private var speed:Number;
		private var jumping:Boolean;
		private var walking:Boolean;
		private var prev_bottom:Number;
&nbsp;
		public function Platform()
		{
			level[0] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
			level[1] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1];
			level[2] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 1, 0, 0, 0, 0, 1];
			level[3] = [1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 1];
			level[4] = [1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 1];
			level[5] = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 1];
			level[6] = [1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 1, 0, 0, 0, 0, 0, 1];
			level[7] = [1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 1];
			level[8] = [1, 1, 1, 1, 0, 9, 0, 0, 0, 5, 5, 0, 0, 0, 7, 0, 0, 6, 0, 0, 0, 0, 7, 0, 1];
			level[9] = [1, 1, 1, 1, 1, 1, 1, 2, 2, 8, 8, 8, 8, 1, 1, 3, 3, 1, 4, 4, 1, 8, 1, 8, 1];
&nbsp;
			player = [4,8];
&nbsp;
			coins[0] = [2, 2];
			coins[1] = [23, 4];
&nbsp;
			enemy[0] = [10, 3, -2];
			enemy[1] = [3, 3, -2];
&nbsp;
			keys[0] = [1, 5, 5, 8];
&nbsp;
			create_level(level);
&nbsp;
			addEventListener(Event.ENTER_FRAME,onEnterFrame);
			stage.addEventListener(KeyboardEvent.KEY_DOWN, key_down);
			stage.addEventListener(KeyboardEvent.KEY_UP, key_up);
		}
&nbsp;
		public function key_down(event:KeyboardEvent):void
		{
			if (event.keyCode == 32)
			{
				press_space = true;
			}
&nbsp;
			if (event.keyCode == 37)
			{
				press_left = true;
			}
&nbsp;
			if (event.keyCode == 38)
			{
				press_up = true;
			}
&nbsp;
			if (event.keyCode == 39)
			{
				press_right = true;
			}
&nbsp;
			if (event.keyCode == 40)
			{
				press_down = true;
			}
		}
&nbsp;
		public function key_up(event:KeyboardEvent):void
		{
			if (event.keyCode == 32)
			{
				press_space = false;
			}
&nbsp;
			if (event.keyCode == 37)
			{
				press_left = false;
			}
&nbsp;
			if (event.keyCode == 38)
			{
				press_up = false;
			}
&nbsp;
			if (event.keyCode == 39)
			{
				press_right = false;
			}
&nbsp;
			if (event.keyCode == 40)
			{
				press_down = false;
			}
		}
&nbsp;
		public function create_level(l:Array):void
		{
			var level_height:Number = l.length;
			var level_width:Number = l[0].length;
&nbsp;
			addChild(level_container);
&nbsp;
			for (var j:Number = 0; j&lt;level_height; j++)
			{
				levelObj[j] = new Array();
				for (var i:Number = 0; i&lt;level_width; i++)
				{
					if (l[j][i] != 0)
					{
						var t:tile = new tile();
						t.x = i*tile_size;
						t.y = j*tile_size;
						t.gotoAndStop(l[j][i]);
						levelObj[j][i] = t;
						level_container.addChild(levelObj[j][i]);
					}
				}
			}
&nbsp;
			place_player();
			level_container.addChild(h);
&nbsp;
			for (var m:int = 0; m &lt; coins.length; m++)
			{
				var c:coin = new coin();
				c.x = coins[m][0] * tile_size + tile_size / 2;
				c.y = coins[m][1] * tile_size + tile_size/2 + 1;
&nbsp;
				coins[m] = c;
				level_container.addChild(coins[m]);
			}
&nbsp;
			for (var n:int = 0; n &lt; keys.length; n++)
			{
				var _k:key = new key();
				_k.x = keys[n][0] * tile_size + tile_size / 2;
				_k.y = keys[n][1] * tile_size + tile_size / 2 + 1;
				_k.openX = keys[n][2];
				_k.openY = keys[n][3];
				keys[n] = _k;
				level_container.addChild(keys[n]);
			}
&nbsp;
			for (var k:int = 0; k &lt; enemy.length; k++)
			{
				var foe:patrol = new patrol();
				foe.speed = enemy[k][2];
				foe.x = enemy[k][0] * tile_size + tile_size / 2;
				foe.y = enemy[k][1] * tile_size + tile_size / 2 + 1;
&nbsp;
				enemy[k] = foe;
				level_container.addChild(enemy[k]);
			}
		}
&nbsp;
		public function onEnterFrame(event:Event):void
		{
			ground_under_feet();
&nbsp;
			walking = false;
			climbing = false;
			if (press_left) {
				xspeed-=speed;
				walking = true;
			}
			if (press_right) {
				xspeed += speed;
				walking = true;
			}
			if (press_up) {
				get_edges();
				if (top_right == 6 || bottom_right == 6 || top_left == 6 || bottom_left == 6) {
					jumping = false;
					falling = false;
					climbing = true;
					climbdir = -1;
				}
			}
			if (press_down) {
				get_edges();
				if (over == &quot;ladder&quot; || top_right == 6 || bottom_right == 6 || top_left == 6 || bottom_left == 6) {
					jumping = false;
					falling = false;
					climbing = true;
					climbdir = 1;
				}
			}
			if (press_space) {
				get_edges();
				if (!falling &amp;&amp; !jumping) {
					jumping = true;
					yspeed = -jump_speed;
				}
			}
			if (!walking) {
				xspeed *= friction;
				if (Math.abs(xspeed)&lt;0.5) {
					xspeed = 0;
				}
			}
			if (xspeed&gt;max_speed) {
				xspeed = max_speed;
			}
			if (xspeed&lt;max_speed*-1) {
				xspeed = max_speed*-1;
			}
			if (falling || jumping) {
				yspeed += gravity;
			}
			if (climbing) {
				yspeed = climb_speed*climbdir;
			}
			if (!falling &amp;&amp; !jumping &amp;&amp; !climbing) {
				yspeed = 0;
			}
			xspeed += bonus_speed;
			check_collisions();
			h.x = x_pos;
			h.y = y_pos;
&nbsp;
			level_container.x = -x_pos + 250;
			level_container.y = -y_pos + 200;
&nbsp;
			xspeed -= bonus_speed;
&nbsp;
			for (var i:int = 0; i &lt; enemy.length; i++)
			{
				enemy[i].x_pos = enemy[i].x;
				enemy[i].y_pos = enemy[i].y;
&nbsp;
				enemy[i].x_pos += enemy[i].speed;
&nbsp;
				enemy[i].left_foot_x = Math.floor((enemy[i].x_pos-6)/tile_size);
				enemy[i].right_foot_x = Math.floor((enemy[i].x_pos+5)/tile_size);
				enemy[i].foot_y = Math.floor((enemy[i].y_pos+9)/tile_size);
				enemy[i].bottom = Math.floor((enemy[i].y_pos+8)/tile_size);
				enemy[i].left_foot = level[enemy[i].foot_y][enemy[i].left_foot_x];
				enemy[i].right_foot = level[enemy[i].foot_y][enemy[i].right_foot_x];
				enemy[i].left = level[enemy[i].bottom][enemy[i].left_foot_x];
				enemy[i].right = level[enemy[i].bottom][enemy[i].right_foot_x];
&nbsp;
				if (enemy[i].left_foot != 0 &amp;&amp; enemy[i].right_foot != 0 &amp;&amp; enemy[i].left == 0 &amp;&amp; enemy[i].right == 0)
				{
					enemy[i].x = enemy[i].x_pos;
				}
				else {
					enemy[i].speed *= -1;
				}
			}
&nbsp;
			for (var j:int = 0; j &lt; coins.length; j++)
			{
				if(coins[j].hitTestObject(h))
				{
					level_container.removeChild(coins[j]);
				}
			}
&nbsp;
			for (var k:int = 0; k &lt; keys.length; k++)
			{
				if(keys[k].hitTestObject(h))
				{
					level[keys[k].openY][keys[k].openX] = 0;
&nbsp;
					level_container.removeChild(levelObj[keys[k].openY][keys[k].openX]);
					level_container.removeChild(keys[k]);
				}
			}
		}
&nbsp;
		public function ground_under_feet():void
		{
			bonus_speed = 0;
			var left_foot_x:Number = Math.floor((x_pos-6)/tile_size);
			var right_foot_x:Number = Math.floor((x_pos+5)/tile_size);
			var foot_y:Number = Math.floor((y_pos+9)/tile_size);
			var left_foot:Number = level[foot_y][left_foot_x];
			var right_foot:Number = level[foot_y][right_foot_x];
			if (left_foot != 0) {
				current_tile = left_foot;
			} else {
				current_tile = right_foot;
			}
			switch (current_tile) {
				case 0 :
					speed = air_acceleration;
					friction = air_friction;
					falling = true;
					break;
				case 1 :
					over = &quot;ground&quot;;
					speed = ground_acceleration;
					friction = ground_friction;
					break;
				case 2 :
					over = &quot;ice&quot;;
					speed = ice_acceleration;
					friction = ice_friction;
					break;
				case 3 :
					over = &quot;treadmill&quot;;
					speed = ground_acceleration;
					friction = ground_friction;
					bonus_speed = -treadmill_speed;
					break;
				case 4 :
					over = &quot;treadmill&quot;;
					speed = ground_acceleration;
					friction = ground_friction;
					bonus_speed = treadmill_speed;
					break;
				case 5 :
					over = &quot;cloud&quot;;
					speed = ground_acceleration;
					friction = ground_friction;
					break;
				case 6 :
					over = &quot;ladder&quot;;
					speed = ground_acceleration;
					friction = ground_friction;
					break;
&nbsp;
				case 7 :
					over = &quot;trampoline&quot;;
					speed = ground_acceleration;
					friction = ground_friction;
					break;
				case 8 :
					over = &quot;spikes&quot;;
					if (left_foot == 8 &amp;&amp; right_foot == 8)
					{
						place_player();
					}
			}
		}
&nbsp;
		public function check_collisions():void
		{
			y_pos += yspeed;
			get_edges();
&nbsp;
			if (yspeed&gt;0) {
				if ((bottom_right != 0 &amp;&amp; bottom_right != 6) || (bottom_left != 0 &amp;&amp; bottom_left != 6)) {
					if (bottom_right != 5 &amp;&amp; bottom_left != 5) {
						if ((bottom_right == 7 || bottom_left == 7) &amp;&amp; (Math.abs(yspeed)&gt;1))
						{
							// trampoline
                    		yspeed *= -1;
                    		jumping = true;
                    		falling = true;
						}else {
							y_pos = bottom*tile_size-9;
							yspeed = 0;
							falling = false;
							jumping = false;
						}
					} else {
						if (prev_bottom&lt;bottom) {
							y_pos = bottom*tile_size-9;
							yspeed = 0;
							falling = false;
							jumping = false;
						}
					}
				}
			}
&nbsp;
			if (yspeed&lt;0) {
				if ((top_right != 0 &amp;&amp; top_right != 5 &amp;&amp; top_right != 6) || (top_left != 0 &amp;&amp; top_left != 5 &amp;&amp; top_left != 6)) {
					y_pos = bottom*tile_size+1+8;
					yspeed = 0;
					falling = false;
					jumping = false;
				}
			}
			x_pos += xspeed;
			get_edges();
&nbsp;
			if (xspeed &lt; 0) {
				if (!is_walkable(top_left) || !is_walkable(bottom_left)) {
					x_pos = (left + 1) * tile_size + 6;
					xspeed = 0;
				}
			}
&nbsp;
			if (xspeed&gt;0) {
				if (!is_walkable(top_right) || !is_walkable(bottom_right)) {
					x_pos = right * tile_size - 6;
					xspeed = 0;
				}
			}
&nbsp;
			prev_bottom = bottom;
		}
&nbsp;
		public function get_edges():void
		{
			right = Math.floor((x_pos+5)/tile_size);
			left = Math.floor((x_pos-6)/tile_size);
			bottom = Math.floor((y_pos+8)/tile_size);
			top = Math.floor((y_pos-9)/tile_size);
&nbsp;
			top_right = level[top][right];
			top_left = level[top][left];
			bottom_left = level[bottom][left];
			bottom_right = level[bottom][right];
		}
&nbsp;
		public function place_player():void
		{
			x_pos = (player[0] * tile_size) + (tile_size / 2);
			y_pos = (player[1] * tile_size) + (tile_size / 2 + 1);
&nbsp;
			h.x = x_pos;
			h.y = y_pos;
		}
&nbsp;
		public function is_walkable(tile:int):Boolean {
			var walkable:Boolean = false;
			for (var i:int = 0; i &lt; walkable_tiles.length; i++)
			{
				if (tile == walkable_tiles[i])
				{
					walkable = true;
					break;
				}
			}
&nbsp;
			return (walkable);
		}
	}
}</pre></td></tr></table></div>

<p>And this is the result:</p>
<p><embed src="/downloads/Platform.swf" menu="false" quality="high" width="500" height="400" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p><a href="/downloads/Platform.zip">Download the source code</a> and make big kudos to Robin!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2008/10/14/new-tile-based-platform-engine-as3-version-updated-to-step-10-plus-scrolling/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>APE &#8211; Actionscript Physics Engine tutorial</title>
		<link>http://www.emanueleferonato.com/2007/10/14/ape-actionscript-physics-engine-tutorial/</link>
		<comments>http://www.emanueleferonato.com/2007/10/14/ape-actionscript-physics-engine-tutorial/#comments</comments>
		<pubDate>Sat, 13 Oct 2007 22:57:19 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/2007/10/14/ape-actionscript-physics-engine-tutorial/</guid>
		<description><![CDATA[October, 23rd update: Part 2 released
With the increasing performances of Actionscript and modern computers, now we have enough power to simulate physics in a Flash movie.
All we need is&#8230; let&#8217;s say&#8230; an huge knowledge of physics, constraints, integrations and so on. With all those things to think about, we cannot focus on the main goal: [...]]]></description>
			<content:encoded><![CDATA[<p><strong>October, 23rd</strong> update: <a href="http://www.emanueleferonato.com/2007/10/23/ape-actionscript-physics-engine-tutorial-part-2/">Part 2</a> released</p>
<p>With the increasing performances of Actionscript and modern computers, now we have enough power to simulate physics in a Flash movie.</p>
<p>All we need is&#8230; let&#8217;s say&#8230; an huge knowledge of physics, constraints, integrations and so on. With all those things to think about, we cannot focus on the main goal: produce our game/application.</p>
<p>Someone should develop an Actionscript physics engine&#8230; <a target = "_blank" href="http://www.cove.org/ape/"><strong>APE</strong> (Actionscript Physics Engine)</a> is a free AS3 open source 2D physics engine for use in Flash and Flex, released under the MIT License.</p>
<p>I started playing with it yesterday, and results are really amazing. While I need much more time for some experiments, I want to share with you my first steps.</p>
<p>The documentation about this project is very poor (some kind of API without examples, one tutorial and two demos&#8230;.) so this tutorial could be a bit unclear, but I am doing my best.</p>
<p>Moreover, it&#8217;s my first time with APE and my first time with Flex&#8230; two new tools to learn quickly, but I am a geek and I am a PROgrammer, so that&#8217;s no problem!</p>
<p>First, <a href="http://www.cove.org/ape/ape_a045.zip">download the alpha version</a> (yes&#8230; just an alpha&#8230;).</p>
<p>Now, we need Flex. Let&#8217;s say Flex 2. From its <a target = "_blank" href="http://www.adobe.com/products/flex/">official site</a>: &#8220;AdobeÂ® Flexâ„¢ 2 is a cross-platform development framework for creating rich Internet applications (RIAs). Flex enables you to create expressive, high-performance applications that run identically on all major browsers and operating systems.&#8221;</p>
<p>If it&#8217;s your first time with Flex, you can download a complete 30 days evaluation version from <a href="https://www.adobe.com/cfusion/tdrc/index.cfm?product=flex" target = "_blank">this page</a>.</p>
<p>When you have Flex installed on your computer the unzipped APE folder, you are ready to go.</p>
<p>Launch Flex and create a new ActionScript project</p>
<p><img src="/images/ap1.png" alt="APE" /></p>
<p>Call you project &#8220;ape&#8221; (you can call it as you want, but later in the code you will have to use this name, so if it&#8217;s your first time call it &#8220;ape&#8221;), <strong>don&#8217;t</strong> click on &#8220;Finish&#8221; but go to &#8220;Next >&#8221;.</p>
<p><img src="/images/ap2.png" alt="APE" /></p>
<p>Seletc &#8220;Library Path&#8221; and click on &#8220;Add SWC&#8230;&#8221;<span id="more-138"></span></p>
<p><img src="/images/ap3.png" alt="APE" /></p>
<p>Now in the dialog box select the ape.swc file, normally located in the bin directory of your APE package, then click OK and Finish.</p>
<p><img src="/images/ap4.png" alt="APE" /></p>
<p>You should have an actionscript window with this content:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="actionscript2" style="font-family:monospace;">package {
	import flash.display.Sprite;
&nbsp;
	public class ape extends Sprite
	{
		public function ape()
		{
		}
	}
}</pre></td></tr></table></div>

<p>The public class <code>ape</code> and public function <code>ape</code> are called in this way because I named the project <code>ape</code>.</p>
<p>Now it&#8217;s time to show you what can I do in less than 40 lines</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre></td><td class="code"><pre class="actionscript2" style="font-family:monospace;">package {
	import org.cove.ape.*;
	import flash.events.Event;
	import flash.display.Sprite;  
	[SWF(width='500',height='400',backgroundColor='0xFFFFFF',frameRate='30')]
	public class ape extends Sprite {
		public function ape() {
			addEventListener(Event.ENTER_FRAME, run);
			APEngine.init(1/4);
			APEngine.container = this;
			APEngine.addMasslessForce(new Vector(0,2));
			var defaultGroup:Group = new Group();
			defaultGroup.collideInternal = true;			
			var cp:CircleParticle = new CircleParticle(250,10,5);
			defaultGroup.addParticle(cp);         	
         	var wp:WheelParticle = new WheelParticle(280,10,5,false,1,0.3,0.1,1);
			defaultGroup.addParticle(wp);
			var rp:RectangleParticle = new RectangleParticle(250,300,200,10,-0.52,true);
			defaultGroup.addParticle(rp);      
			var rp2:RectangleParticle = new RectangleParticle(150,200,200,10,0.52,true);
			defaultGroup.addParticle(rp2);        
			var rp3:RectangleParticle = new RectangleParticle(250,50,200,10,-0.52,true);
			defaultGroup.addParticle(rp3);
			var wa: WheelParticle = new WheelParticle(160,20,10,false,2);
			defaultGroup.addParticle(wa);		
			var wb: WheelParticle = new WheelParticle(200,20,10,false,2)
			defaultGroup.addParticle(wb);		
			var wc:SpringConstraint = new SpringConstraint(wa, wb, 0.5, true, 3);
			defaultGroup.addConstraint(wc);       	
        	APEngine.addGroup(defaultGroup);
		}
		private function run(evt:Event):void {
			APEngine.step();
			APEngine.paint();
		}
	}
}</pre></td></tr></table></div>

<p><strong>Lines 2-4</strong>: Importing necessary libraries</p>
<p><strong>Line 5</strong>: Setting width, height, bgcolor and framerate of the movie we are going to create. This is the way you have to define attributes in pure actionscript projects.</p>
<p><strong>Note</strong>: Width and height must be specified in pixels. You are not allowed to use percentage values such as 50%.</p>
<p><strong>Line 6</strong>: Definining the ape class as an extension of the built in Sprite class.</p>
<p>The <strong>Sprite</strong> class is new in ActionScript 3.0 A Sprite object is similar to a movie clip, but does not have a timeline.</p>
<p><strong>Line 7</strong>: Declaring the main function</p>
<p><strong>Line 8</strong>: Adding an event listener. Since the <code>on(event)</code> syntax is no longer supported in ActionScript 3.0, we need to use <code>addEventListener</code> to trig for some events. In our case, the event is <code>ENTER_FRAME</code>. So it&#8217;s basically an <code>onEnterFrame = function(){}</code> coded in AS3, where the &#8220;function&#8221; is <code>run</code> (the function defined at <strong>lines 32-35</strong>).</p>
<p><strong>Line 9</strong>: Initializing the APE engine. The parameter 1/4 (0.25) is used to set the speed of the simulation.  Typical values are 1/3 or 1/4. Lower values result in slower, but more accurate simulations, and higher ones result in faster, less accurate ones.</p>
<p><strong>Line 10</strong>: Definining the default container used by the default painting methods of the particles and constraints. In other words, the area where the simulation takes place.</p>
<p><strong>Line 11</strong>: Adding a &#8220;massless&#8221; force to the system. What is a &#8220;massless&#8221; force? It&#8217;s a force that acts on all particles in the same way even if they have different masses&#8230; such as gravity. Particles with larger masses are affected by gravity same as those with smaller masses. The <code>Vector</code> represents the&#8230; vector of the force, splitted in <code>fx</code> and <code>fy</code>. <code>fx</code> is the horizontal component of the force, while fy is the vertical component of the force. In our case, we have a force that does not have horizontal force, but only a vertical one (like gravity). Changing the vector values will result in different gravity types (reverse, horizontal, and so on).</p>
<p><strong>Line 12</strong>: Creating a group called <code>defaultGroup</code>. The Group class can contain Particles, Constraints, and Composites. Groups can be assigned to be checked for collision with other Groups or internally. This means that I can have a group of particles that can collide only with particles of another group, or a group of particles that are checked for collision one with each other. As you can see from <strong>Line 13</strong>, I want my particles inside <code>defaultGroup</code> to collide, and I specify it with the <code>collideInternal</code> property</p>
<p><strong>Line 14</strong>: Creating a circle haped particle. The <code>CircleParticle</code> has some interesting parameters:</p>
<p><strong>x:Number</strong>: The initial x position of this particle.  </p>
<p><strong>y:Number:</strong> The initial y position of this particle.  </p>
<p><strong>radius:Number</strong>: The radius of this particle.  </p>
<p><strong>fixed:Boolean (default = false)</strong>: Determines if the particle is fixed or not. Fixed particles are not affected by forces or collisions and are good to use as surfaces. Non-fixed particles move freely in response to collision and forces.  </p>
<p><strong>mass:Number (default = 1)</strong>: The mass of the particle.  </p>
<p><strong>elasticity:Number (default = 0.3)</strong>: The elasticity of the particle. Higher values mean more elasticity or  &#8220;bounciness&#8221;.  </p>
<p><strong>friction:Number (default = 0)</strong>: The surface friction of the particle </p>
<p>So in my case I have a circle particle located at (250,10) with a radius of 5 pixels, that is not fixed (it will fall, bounce, etc), with a mass equal to 1 and an elasticity equal to 0.3 and no friction.</p>
<p><strong>Line 15</strong>: Adding the circle particle to the group defined at <strong>line 12</strong></p>
<p><strong>Line 16</strong>: Introducing the most interesting particle of the engine, in my opinion: the wheel particle. A wheel particle is&#8230; a particle that simulates the behavior of a wheel.</p>
<p>Let&#8217;s see its parameters:</p>
<p><strong>x:Number</strong>: The initial x position.  </p>
<p><strong>y:Number</strong>: The initial y position.  </p>
<p><strong>radius:Number</strong>: The radius of this particle.  </p>
<p><strong>fixed:Boolean (default = false)</strong>: Determines if the particle is fixed or not. Fixed particles are not affected by forces or collisions and are good to use as surfaces. Non-fixed particles move freely in response to collision and forces.  </p>
<p><strong>mass:Number (default = 1)</strong>: The mass of the particle  </p>
<p><strong>elasticity:Number (default = 0.3)</strong>: The elasticity of the particle. Higher values mean more elasticity.  </p>
<p><strong>friction:Number (default = 0)</strong>: The surface friction of the particle.  </p>
<p><strong>traction:Number (default = 1)</strong>: The surface traction of the particle. </p>
<p>So basically a wheel is a circle that can rotate and with a traction</p>
<p><strong>Line 17</strong>: Adding the wheel particle to the group</p>
<p><strong>Line 18</strong>: Another particle&#8230; this time a rectangle particle. Look at the parameters:</p>
<p><strong>x:Number</strong>: The initial x position.  </p>
<p><strong>y:Number</strong>: The initial y position.  </p>
<p><strong>width:Number</strong>: The width of this particle.  </p>
<p><strong>height:Number</strong>: The height of this particle.  </p>
<p><strong>rotation:Number (default = 0)</strong>: The rotation of this particle in radians. Read carefully! RADIANS!!</p>
<p><strong>fixed:Boolean (default = false)</strong>: Determines if the particle is fixed or not. Fixed particles are not affected by forces or collisions and are good to use as surfaces. Non-fixed particles move freely in response to collision and forces.  </p>
<p><strong>mass:Number (default = 1)</strong>: The mass of the particle  </p>
<p><strong>elasticity:Number (default = 0.3)</strong>: The elasticity of the particle. Higher values mean more elasticity.  </p>
<p><strong>friction:Number (default = 0)</strong>: The surface friction of the particle.</p>
<p><strong>Line 19</strong>: Adding the rectangle particle to the group</p>
<p><strong>Lines 20-23</strong>: Adding two more rectangle particles</p>
<p><strong>Lines 24-27</strong>: Adding two more wheel particles</p>
<p><strong>Line 28</strong>: The feature I love: the spring constraint. The spring constraint is a spring-like constraint that connects two particles. If you need more information about constraints, refer to <a href="http://www.emanueleferonato.com/2007/08/26/creation-of-a-ragdoll-with-flash-part-2-constraints/">Creation of a Ragdoll with Flash part 2: Constraints</a>.</p>
<p>I am going to connect the last two wheels I created with a constraint. This means I am going to create a car. Look at the parameters:</p>
<p><strong>p1:AbstractParticle</strong>: The first particle this constraint is connected to.  </p>
<p><strong>p2:AbstractParticle</strong>: The second particle this constraint is connected to.  </p>
<p><strong>stiffness:Number (default = 0.5)</strong>: The strength of the spring. Valid values are between 0 and 1. Lower values result in softer springs. Higher values result in stiffer, stronger springs.  </p>
<p><strong>collidable:Boolean (default = false)</strong>: Determines if the constraint will be checked for collision  </p>
<p><strong>rectHeight:Number (default = 1)</strong>: If the constraint is collidable, the height of the collidable area can be set in pixels. The height is perpendicular to the two attached particles.  </p>
<p><strong>rectScale:Number (default = 1)</strong>: If the constraint is collidable, the scale of the collidable area can be set in value from 0 to 1. The scale is percentage of the distance between the the two attached particles.  </p>
<p><strong>scaleToLength:Boolean (default = false)</strong>: If the constraint is collidable and this value is true, the collidable area will scale based on changes in the distance of the two particles.</p>
<p>In my case, I am connecting the last two wheels with a semi-strong collidable spring, with an height of 3 pixels.</p>
<p><strong>Line 29</strong>: Adding the constraint to the group</p>
<p><strong>Line 30</strong>: Adding the group to the engine</p>
<p><strong>Line 32</strong>: Beginning of the function to be executed at every frame, like declared at <strong>line 8</strong></p>
<p><strong>Line 33</strong>: The main step function of the engine. This method should be called continously to advance the simulation. The faster this method is called, the faster the simulation will run. Usually you would call this in your main program loop. </p>
<p><strong>Line 34</strong>: Calling this method will in turn call each particle and constraint&#8217;s paint method. Generally you would call this method after stepping the engine in the main program cycle.</p>
<p>The last two lines advance the simulation and display the result.</p>
<p>And this is what I got with this simple script (you may need to reload the page to see the movie work properly)</p>
<p><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="ape" width="500" height="400" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab"><param name="movie" value="/downloads/ape.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#f0fff0" /><param name="allowScriptAccess" value="sameDomain" /><embed src="/downloads/ape.swf" quality="high" bgcolor="#f0fff0" width="500" height="400" name="ape" align="middle" play="true" loop="false" quality="high" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"	pluginspage="http://www.adobe.com/go/getflashplayer"></embed></object></p>
<p>As you can see, results are really exciting. The ball, the wheel and the car go down the slope bouncing and moving in a very realistic way. I am sure I will be able to create a &#8220;Moster Truck&#8221; game in a few hours.</p>
<p>And I&#8217;ll publish it as soon as it create it.</p>
<p>Meanwhile, <a href="/downloads/ape.zip">download the entire project</a> and give me feeback. Then, move to <a href="http://www.emanueleferonato.com/2007/10/23/ape-actionscript-physics-engine-tutorial-part-2/">part 2</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2007/10/14/ape-actionscript-physics-engine-tutorial/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
	</channel>
</rss>
