<?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; Users contributions</title>
	<atom:link href="http://www.emanueleferonato.com/category/users-contributions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.emanueleferonato.com</link>
	<description>italian geek and PROgrammer</description>
	<lastBuildDate>Mon, 06 Feb 2012 14:28:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>One game, many frameworks</title>
		<link>http://www.emanueleferonato.com/2012/01/03/one-game-many-frameworks/</link>
		<comments>http://www.emanueleferonato.com/2012/01/03/one-game-many-frameworks/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 16:23:07 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=5037</guid>
		<description><![CDATA[Ever wanted to build a mobile game using a framework? <strong>Roger Engelbert</strong> built a guide to do it with <strong>four</strong> different frameworks!]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s no doubt 2012 will be the year of the frameworks. <strong><strong>Roger Engelbert</strong></strong> in his blog <a href="http://www.rengelbert.com/" target="_blank">rengelbert.com</a> show us how to do a mobile Frogger game using four different frameworks: <a href="http://www.starling-framework.org/" target="_blank">Starling</a>, <a href="http://www.sparrow-framework.org/" target="_blank">Sparrow</a>, <a href="http://cocos2d.org/" target="_blank">Cocos2D</a> and <a href="http://libgdx.badlogicgames.com/" target="_blank">LibGDX</a>.</p>
<p>This is the game involved in the experiment:</p>
<p><center><embed src="/wp-content/uploads/2012/01/FroggerAS3.swf" menu="false" quality="high" width="320" height="480" wmode="direct" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></center></p>
<p>Use arrow keys to move the frog, or click on the frog controller in the bottom right corner of the game.</p>
<p>Here is a brief intro by Roger:</p>
<p>I will first explain something of the logic controlling the game. It is very important to point out that the logic itself has nothing to do with any of the frameworks I&#8217;ll use. The frameworks for the most part only influence the VIEW part of the logic: the actual rendering of textures on screen in place of all the rectangle objects the logic handles.</p>
<p>So these tutorials are not meant to be on how to build a game like Frogger, but how to blitt stuff to the screen.</p>
<p>Having said that, I thought I might as well explain enough of the game logic so that you can separate that logic from the actual framework code.</p>
<p><strong>The Game Engine</strong></p>
<p>The engine manages a series of Screen objects, but displays only one screen at a time. So you can build an Intro Screen, a How to Play Screen, a High Scores Screen, a Game Screen&#8230; The Engine then updates the currently displayed Screen object within a loop.</p>
<p>For this example I created two screens, one called a MenuScreen that shows the instructions on how to play the game, and one screen called GameScreen where the actual game runs.</p>
<p>The main Game object contains exposed references to GameData, the TextureAtlas and Sounds. Every object in the game receives a reference to the Game object. I&#8217;ve decide to use composition and drop the Singletons.</p>
<p><strong>Controls</strong></p>
<p>For the Flash version of the game I will use two sets of controls: Key presses and Mouse clicks. Later when porting to mobile devices I will drop the Keyboard input logic and just keep the touch events.</p>
<p><strong>The Game Logic</strong></p>
<p>The game logic is very simple. The screen is divided into 13 rows, I called them Tiers. Each Tier has a bunch of sprites inside it, they can be cars, or turtles or tree logs.</p>
<p>The frog sprite, controlled by the player, can have only 13 possible values for its Y position, one value per Tier. So with every UP or DOWN movement the player Y value changes to either the next Tier or the previous one.</p>
<p>Collision is run only with the objects belonging to the Tier the frog is currently at.</p>
<p>Each Tier has the responsibility to update the positions of the sprites it contains.</p>
<p><strong>The Skin Property</strong></p>
<p>As I talked about earlier, the different frameworks used will be in charge of the SKIN property of the Sprites used in the game as well as the various Texture objects a skin may use (if it&#8217;s animated for instance.) It is here that the Framework logic and syntax can be found.</p>
<p>However when I update the position of sprites in the game I do this through the wrappers and not directly to the Image objects. This might seem like extra work for you, and you&#8217;re free to change this. I simply find this way to be the easiest when taking the same logic to different platforms as I only need to change the logic controlling rendering of the skins.</p>
<p>Now, you are ready to ready one of the most interesting tutorials I&#8217;ve ever seen.</p>
<p><a href="http://www.rengelbert.com/tutorial.php?id=163" target="_blank">http://www.rengelbert.com/tutorial.php?id=163</a> (using Starling)<br />
<a href="http://www.rengelbert.com/tutorial.php?id=167" target="_blank">http://www.rengelbert.com/tutorial.php?id=167</a> (using Sparrow)<br />
<a href="http://www.rengelbert.com/tutorial.php?id=171" target="_blank">http://www.rengelbert.com/tutorial.php?id=171</a> (using Cocos2D)<br />
<a href="http://www.rengelbert.com/tutorial.php?id=175" target="_blank">http://www.rengelbert.com/tutorial.php?id=175</a> (using LibGDX)</p>
<p>I am looking forward for playing and messing around with frameworks and publish my thoughts.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2012/01/03/one-game-many-frameworks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Claytus Hood Tower Defense case study part 2: giving the community a Flex level editor</title>
		<link>http://www.emanueleferonato.com/2011/11/11/claytus-hood-tower-defense-case-study-part-2-giving-the-community-a-flex-level-editor/</link>
		<comments>http://www.emanueleferonato.com/2011/11/11/claytus-hood-tower-defense-case-study-part-2-giving-the-community-a-flex-level-editor/#comments</comments>
		<pubDate>Fri, 11 Nov 2011 10:36:55 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Monetize]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=4827</guid>
		<description><![CDATA[Raphaël Roux, the author of <a href="http://www.claytus-towerdefense.com/" target="_blank">Claytus Hood Tower Defense</a>, explains how to create a Flex level editor, save levels on a database, add Facebook connect, build a community, and more!]]></description>
			<content:encoded><![CDATA[<p>Did you ever play <a href="http://www.claytus-towerdefense.com/" target="_blank">Claytus Hood Tower Defense</a>? Yes, you should, if you are an <a href="http://www.emanueleferonato.com/2010/07/26/claytus-hood-tower-defense-case-study/">old time reader</a>.</p>
<p><img src="/wp-content/uploads/2011/11/editor01.jpg" /></p>
<p>It&#8217;s a game (and what a game!) by <strong>Raphaël Roux</strong>, who also used Flex to create and release a level editor full of interesting features such as database management, Facebook connect, and more.</p>
<p><img src="/wp-content/uploads/2011/11/editor02.jpg" /></p>
<p>Raphaël shares with us his experience:</p>
<p><strong>Previously on Claytus Hood Tower Defense</strong></p>
<p>Let&#8217;s take Claytus&#8217; story where we left it off last time :</p>
<p>The first episode of Claytus was released on summer 2010, and it was the subject <a href="http://www.emanueleferonato.com/2010/07/26/claytus-hood-tower-defense-case-study/">this post</a>.</p>
<p>Then between September 2010 and April 2011, I was hired as a web development teacher at the University of Savoy (France). This was a really good experience combining programming  and social relations, I loved it !</p>
<p>On the last post dedicated to Claytus, I talked about a tower defense level editor.<br />
At this time, I had built a simple tool coded in Flex to help me balance the waves of enemies of the original game, but the software was not really designed in a friendly user way.<br />
I had a wish : make this software  available for players, and this is what we&#8217;ll be talking about in this post!</p>
<p><strong>Define the functionalities</strong></p>
<p>I wanted a browser application, with no installation needed for the player, like any Flash game, so I chose to improve my Flex skills.</p>
<p>This is commonly called Rich Internet Application (RIA), when you&#8217;ve got a complex software running on web browsers and Flash player.</p>
<p>This level editor must have a lot of features, this is a quick overview :<br />
- Manage users : creating account, log the users, and Facebook connect<br />
- Design your own tower defense levels.<br />
- Save your work on Claytus&#8217; server.<br />
- Share your work with Claytus community.<br />
- Linking all this in a community website, with all the common features such as comments, rates and scoring.</p>
<p>Time to code!</p>
<p><strong>Building a Rich Internet Application (RIA) in Flex 4.5</strong></p>
<p>I&#8217;ve learned how to work with Flex on the Flex 3 SDK with the &#8220;training from the source&#8221; official book, so I had to learn a lot about Flex 4.5, because in the meantime, there has been a lot of changes on the Flex 4.5 SDK.</p>
<p>Always the geekish way for me to learn about IT</p>
<p>Most part of these changes was about the new Spark components library, and how to deal with the new layouts.<br />
A bit less intuitive, stricter than the Flex 3 SDK and its MX components, but this is all for the good !</p>
<p>Nowadays, Flex 4.5 is not totally finished, in my opinion.<br />
Most of the components of MX are ported in Spark, but the features aren&#8217;t all enabled for some of them, so I had to mix between MX and Spark components, this was pretty tricky to make good choices.</p>
<p><strong>Communicate with server and databases</strong></p>
<p>First thing I had to do was to find a reliable and powerful way to communicate between my RIA, my server and databases.</p>
<p>So I chose to use <a href="http://www.silexlabs.org/amfphp/" target = "_blank">amfPHP</a>, a messaging system, very handy to do these kind of communications.</p>
<p>You can easily share an AS3 object with the PHP version of this same object on the server.<br />
This is called object versionning, and I recommend you to dig around this API !<br />
I had to modify the amfPHP API to share the PHP session between the level editor and Claytus website, there&#8217;s a little trick about the session name :)</p>
<p>During the sharing process of your level, amfphp allows me to send the byteArray of the level, so that I can save jpeg on server side and make thumbnails.<br />
It also receives the data of the level (tilemap, landscape and waves &#8230;) that I save into a XML on the server.</p>
<p>I use this API each time I have to deal with server side stuff.<br />
As I said, the PHP scripts used with the level editor are the same that in the website, so I have a pretty flexible webservice !</p>
<p><strong>What about the website?</strong></p>
<p>I designed the website like a community website.<br />
I had to implement comments, ratings and score board, everything is home made.</p>
<p>Three major parts :<br />
- Original game<br />
- Shared levels : levels created by the members of the community.<br />
- Level editor : introducing the level editor with a tutorial (a new video will come asap).</p>
<p>I also setup a forum based on a myBB forum.<br />
The trickiest thing was to  automatically create a forum account when you create a Claytus account.<br />
So I manually edited the PHP code of myBB, so that users can login both on the forum and the website with their email and password.</p>
<p>I worked a lot on a natural way to rank my pages on search engines, I put all I got in term of SEO.<br />
I also implemented the Facebook Open Graph :<br />
if you take a look at my html sources, you&#8217;ll see meta tags especially for the Open Graph.<br />
This way, Facebook considers each of my pages as an Open Graph object, and it appears on Facebook&#8217;s search engine.<br />
I can also specify the picture or the video that appears on your wall when you share one of these pages.</p>
<p>I tried to make smooth animations and interactions all over the website with the JQuerry API to have a modern webdesign.<br />
It is very important not to reload the page when the user wants to comment or rate a shared level. If not, the game would be lost and more than one user would certainly be upset and the feature would bring nothing to the community !<br />
I also tried to innovate with the &#8220;Explorer&#8221; button, that shows you a nice site map to explore Claytus&#8217; world.</p>
<p><strong>Facebook Connect</strong></p>
<p>I had to implement Facebook connect both on the website and the level editor, not easy as it sounds&#8230;<br />
An AS3 API for Facebook Connect exists, called <a href="https://github.com/yourpalmark/facebook-actionscript-api" target="_blank">GraphAPI</a>.</p>
<p>The thing is that you can&#8217;t test your script locally, if your RIA is not uploaded on a server, it won&#8217;t work&#8230;<br />
&#8221; Compile > Upload > Test &#8221;<br />
Several minutes between each of my tests, this drove me crazy :)</p>
<p>There is a way to test without uploading, but your app has to be for AIR.</p>
<p>The other thing is very, very important :<br />
First week, not all of my Facebook Connect requests were successful.<br />
I mean, registrations were well done, but the users couldn&#8217;t log themselves&#8230;</p>
<p>Why ?!<br />
Because when you store a Facebook user id in your databases, please DO NOT use a INT(11) for your user ids, but set a BIGINT(20) ! If not, you&#8217;ll get troubles, because now, FB uids are very long.<br />
This is the first thing FB should say in their documentation in my opinion :)</p>
<p><strong>Funding, monetizing</strong></p>
<p>This time, I plan to make money with my project, it&#8217;s a full time job and I hope to earn my living with this project.</p>
<p>A big part of Claytus is still available for free but I now sell lifetime licenses with Paypal.<br />
With a license, players will have full access to all of the features of Claytus community with no restriction.<br />
It was not so easy to code the Paypal callback because their documentation is pretty large and you find a lot of outdated tutorials. I finally found my way in this mess.</p>
<p>I chose a single Paypal button for payment, so you can pay both with a Paypal account and classical credit cards.<br />
After the payment, I send a serial number to the payer&#8217;s email, so that he can easily activate his license.</p>
<p>I got no external funding for the development, I hope the customers will cover the future development fees.<br />
During the development I sell licenses 50% off, like Minecraft does.</p>
<p><strong>What next?</strong></p>
<p>Depends on the selling of licenses, there are many ways to plan the future:<br />
- Just a few selling : It will fund the server.<br />
- Reasonable selling : I will update the community as much as I can with new avatars, new landscapes items and enemy sprites for the editor, if I get enough to live and pay the illustrators / musicians.<br />
- Good selling : Smart phone application and Xbox live ?</p>
<p>In the meantime I&#8217;m dedicated to community management, and I&#8217;m trying to code some little projects in freelance during my spare time (when is it ?)</p>
<p><strong>Conclusion</strong></p>
<p>After one year of work, I learned a lot about many things in IT.<br />
I would like to thank all the developers who write articles and share their experiences about these subjects, they&#8217;re all my teachers.<br />
Emanuele is one of them of course, he does a great job with his blog, but you already know that, because you&#8217;re reading this article!</p>
<p>I&#8217;m here to share my experience with you, please feel free to ask me your questions about coding techniques or Claytus community, whatever you want !</p>
<p>I hope you will enjoy my work, I put all the love I have for video games in this project, and I hope it will survive through years to come with a nice community !</p>
<p>At this time a <a href="http://www.claytus-towerdefense.com/index.php?page=level-editor-home" target="_blank">tutorial should be available</a> on the level editor&#8217;s home page in English.<br />
I can&#8217;t wait to have your feedbacks :)</p>
<p>Spread the word !</p>
<p>Thank you !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2011/11/11/claytus-hood-tower-defense-case-study-part-2-giving-the-community-a-flex-level-editor/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Create non-convex, complex shapes with Box2D</title>
		<link>http://www.emanueleferonato.com/2011/09/12/create-non-convex-complex-shapes-with-box2d/</link>
		<comments>http://www.emanueleferonato.com/2011/09/12/create-non-convex-complex-shapes-with-box2d/#comments</comments>
		<pubDate>Mon, 12 Sep 2011 10:16:51 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=4616</guid>
		<description><![CDATA[Create any kind of complex and concave shapes with Box2D and have them separated into smaller, convex shapes in a very optimized way with <code>b2Separator</code> class by <strong>Antoan Angelov</strong>]]></description>
			<content:encoded><![CDATA[<p>If you are working with Box2D for a while, probably you have already met the problem you can&#8217;t create non-convex shapes. This is a problem Box2D faces for years, as you can see from <a href="http://www.emanueleferonato.com/2008/12/19/understanding-custom-polygons-in-box2d/">this post</a>, and due to Box2D&#8217;s structure itself, we will never be able to create concave shapes.</p>
<p>That&#8217;s why some 3rd party libraries like <a href="http://www.emanueleferonato.com/2011/03/11/create-complex-box2d-shapes-in-a-click-with-physicseditor/">PhysicsEditor</a> allow us to break a concave shape into a set of convex shapes and make possible the creation of complex bodies.</p>
<p><strong>Antoan Angelov</strong>, the author of the optimized version of the <a href="http://www.emanueleferonato.com/2011/08/05/slicing-splitting-and-cutting-objects-with-box2d-part-4-using-real-graphics/">Box2d slicing engine</a>, strikes back with another great Box2D class called <code>b2Separator</code>.</p>
<p>&laquo; The class is called b2Separator, and yes &#8211; it is made to work specifically with Box2D! What does it do, you ask? Well, we all hate when we have to make a more complex, non-convex shape for our b2Body &#8211; because we have to manually make many b2Fixtures, and make those really confusing and time-wasting calculations to see how each fixture is supposed to fit in with the others. Well, our troubles are now over, because what b2Separator does is separate a non-convex shape into smaller, convex shapes in a very optimized way and add them as b2Fixtures to a b2Body. All you need to do is give it the vertices of the shape you want! &raquo;</p>
<p>This is the fully commented class:</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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #3f5fbf;">/*
* Convex Separator for Box2D Flash
*
* This class has been written by Antoan Angelov. 
* It is designed to work with Erin Catto's Box2D physics library.
*
* Everybody can use this software for any purpose, under two restrictions:
* 1. You cannot claim that you wrote this software.
* 2. You can not remove or alter this notice.
*
*/</span>
&nbsp;
<span style="color: #9900cc; font-weight: bold;">package</span> Box2DSeparator<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D<span style="color: #000066; font-weight: bold;">.</span>Collision<span style="color: #000066; font-weight: bold;">.</span>Shapes<span style="color: #000066; font-weight: bold;">.</span>b2PolygonShape<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D<span style="color: #000066; font-weight: bold;">.</span>Common<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span>b2Vec2<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D<span style="color: #000066; font-weight: bold;">.</span>Dynamics<span style="color: #000066; font-weight: bold;">.</span>b2Body<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D<span style="color: #000066; font-weight: bold;">.</span>Dynamics<span style="color: #000066; font-weight: bold;">.</span>b2FixtureDef<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> b2Separator<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> b2Separator<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Separates a non-convex polygon into convex polygons and adds them as fixtures to the &lt;code&gt;body&lt;/code&gt; parameter.&lt;br/&gt;
		 * There are some rules you should follow (otherwise you might get unexpected results) :
		 * &lt;ul&gt;
		 * &lt;li&gt;This class is specifically for non-convex polygons. If you want to create a convex polygon, you don't need to use this class - Box2D's &lt;code&gt;b2PolygonShape&lt;/code&gt; class allows you to create convex shapes with the &lt;code&gt;setAsArray()&lt;/code&gt;/&lt;code&gt;setAsVector()&lt;/code&gt; method.&lt;/li&gt;
		 * &lt;li&gt;The vertices must be in clockwise order.&lt;/li&gt;
		 * &lt;li&gt;No three neighbouring points should lie on the same line segment.&lt;/li&gt;
		 * &lt;li&gt;There must be no overlapping segments and no &quot;holes&quot;.&lt;/li&gt;
		 * &lt;/ul&gt; &lt;p/&gt;
		 * @param body The b2Body, in which the new fixtures will be stored.
		 * @param fixtureDef A b2FixtureDef, containing all the properties (friction, density, etc.) which the new fixtures will inherit.
		 * @param verticesVec The vertices of the non-convex polygon, in clockwise order.
		 * @param scale &lt;code&gt;[optional]&lt;/code&gt; The scale which you use to draw shapes in Box2D. The bigger the scale, the better the precision. The default value is 30. 
		 * @see b2PolygonShape
		 * @see b2PolygonShape.SetAsArray()
		 * @see b2PolygonShape.SetAsVector()
		 * @see b2Fixture
		 * */</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Separate<span style="color: #000000;">&#40;</span>body<span style="color: #000066; font-weight: bold;">:</span>b2Body<span style="color: #000066; font-weight: bold;">,</span>fixtureDef<span style="color: #000066; font-weight: bold;">:</span>b2FixtureDef<span style="color: #000066; font-weight: bold;">,</span>verticesVec<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>b2Vec2<span style="color: #000066; font-weight: bold;">&gt;,</span><span style="color: #004993;">scale</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">30</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span>n<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=verticesVec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span>m<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> vec<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>b2Vec2<span style="color: #000066; font-weight: bold;">&gt;</span>=<span style="color: #0033ff; font-weight: bold;">new</span> Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>b2Vec2<span style="color: #000066; font-weight: bold;">&gt;</span>  <span style="color: #000066; font-weight: bold;">,</span>figsVec<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> polyShape<span style="color: #000066; font-weight: bold;">:</span>b2PolygonShape<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span>n<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				vec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span>verticesVec<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">scale</span><span style="color: #000066; font-weight: bold;">,</span>verticesVec<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">scale</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			figsVec=calcShapes<span style="color: #000000;">&#40;</span>vec<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			n=figsVec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span>n<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				verticesVec=<span style="color: #0033ff; font-weight: bold;">new</span> Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>b2Vec2<span style="color: #000066; font-weight: bold;">&gt;</span>  <span style="color: #000066; font-weight: bold;">;</span>
				vec=figsVec<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
				m=vec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>j=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">&lt;</span>m<span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					verticesVec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span>vec<span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #004993;">scale</span><span style="color: #000066; font-weight: bold;">,</span>vec<span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #004993;">scale</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #000000;">&#125;</span>
&nbsp;
				polyShape=<span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape  <span style="color: #000066; font-weight: bold;">;</span>
				polyShape<span style="color: #000066; font-weight: bold;">.</span>SetAsVector<span style="color: #000000;">&#40;</span>verticesVec<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				fixtureDef<span style="color: #000066; font-weight: bold;">.</span>shape=polyShape<span style="color: #000066; font-weight: bold;">;</span>
				body<span style="color: #000066; font-weight: bold;">.</span>CreateFixture<span style="color: #000000;">&#40;</span>fixtureDef<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Checks whether the vertices in &lt;code&gt;verticesVec&lt;/code&gt; can be properly distributed into the new fixtures (more specifically, it makes sure there are no overlapping segments and the vertices are in clockwise order). 
		 * It is recommended that you use this method for debugging only, because it may cost more CPU usage.
		 * &lt;p/&gt;
		 * @param verticesVec The vertices to be validated.
		 * @return An integer which can have the following values:
		 * &lt;ul&gt;
		 * &lt;li&gt;0 if the vertices can be properly processed.&lt;/li&gt;
		 * &lt;li&gt;1 If there are overlapping lines.&lt;/li&gt;
		 * &lt;li&gt;2 if the points are &lt;b&gt;not&lt;/b&gt; in clockwise order.&lt;/li&gt;
		 * &lt;li&gt;3 if there are overlapping lines &lt;b&gt;and&lt;/b&gt; the points are &lt;b&gt;not&lt;/b&gt; in clockwise order.&lt;/li&gt;
		 * &lt;/ul&gt; 
		 * */</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Validate<span style="color: #000000;">&#40;</span>verticesVec<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>b2Vec2<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span>n<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=verticesVec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span>j2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span>i2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span>i3<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">d</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>ret<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> fl<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span><span style="color: #000066; font-weight: bold;">,</span>fl2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span>n<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				i2=<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">&lt;</span>n<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">?</span>i<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
				i3=<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">?</span>i<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">:</span>n<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
				fl=<span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>j=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">&lt;</span>n<span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>j<span style="color: #000066; font-weight: bold;">!</span>=i<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&amp;&amp;</span>j<span style="color: #000066; font-weight: bold;">!</span>=i2<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;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span> fl<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							<span style="color: #004993;">d</span>=det<span style="color: #000000;">&#40;</span>verticesVec<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>verticesVec<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span>verticesVec<span style="color: #000000;">&#91;</span>i2<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>verticesVec<span style="color: #000000;">&#91;</span>i2<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span>verticesVec<span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>verticesVec<span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>d<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
								fl=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #000000;">&#125;</span>
						<span style="color: #000000;">&#125;</span>
&nbsp;
						<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>j<span style="color: #000066; font-weight: bold;">!</span>=i3<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							j2=<span style="color: #000000;">&#40;</span>j<span style="color: #000066; font-weight: bold;">&lt;</span>n<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">?</span>j<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>hitSegment<span style="color: #000000;">&#40;</span>verticesVec<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>verticesVec<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span>verticesVec<span style="color: #000000;">&#91;</span>i2<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>verticesVec<span style="color: #000000;">&#91;</span>i2<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span>verticesVec<span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>verticesVec<span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span>verticesVec<span style="color: #000000;">&#91;</span>j2<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>verticesVec<span style="color: #000000;">&#91;</span>j2<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
								ret=<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #000000;">&#125;</span>
						<span style="color: #000000;">&#125;</span>
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
&nbsp;
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span> fl<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					fl2=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>fl2<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>ret==<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>
					ret=<span style="color: #000000; font-weight:bold;">3</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #000000;">&#125;</span>
				<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
					ret=<span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> ret<span style="color: #000066; font-weight: bold;">;</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> calcShapes<span style="color: #000000;">&#40;</span>verticesVec<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>b2Vec2<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> vec<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>b2Vec2<span style="color: #000066; font-weight: bold;">&gt;;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span>n<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">d</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>t<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>dx<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>dy<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>minLen<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> i1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span>i2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span>i3<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span>p1<span style="color: #000066; font-weight: bold;">:</span>b2Vec2<span style="color: #000066; font-weight: bold;">,</span>p2<span style="color: #000066; font-weight: bold;">:</span>b2Vec2<span style="color: #000066; font-weight: bold;">,</span>p3<span style="color: #000066; font-weight: bold;">:</span>b2Vec2<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> j1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span>j2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span>v1<span style="color: #000066; font-weight: bold;">:</span>b2Vec2<span style="color: #000066; font-weight: bold;">,</span>v2<span style="color: #000066; font-weight: bold;">:</span>b2Vec2<span style="color: #000066; font-weight: bold;">,</span>k<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span>h<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> vec1<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>b2Vec2<span style="color: #000066; font-weight: bold;">&gt;,</span>vec2<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>b2Vec2<span style="color: #000066; font-weight: bold;">&gt;;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> v<span style="color: #000066; font-weight: bold;">:</span>b2Vec2<span style="color: #000066; font-weight: bold;">,</span>hitV<span style="color: #000066; font-weight: bold;">:</span>b2Vec2<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> isConvex<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> figsVec<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span>=<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span>queue<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span>=<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			queue<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>verticesVec<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>queue<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				vec=queue<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
				n=vec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span>
				isConvex=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
				<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span>n<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					i1=i<span style="color: #000066; font-weight: bold;">;</span>
					i2=<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">&lt;</span>n<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">?</span>i<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">:</span>i<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">-</span>n<span style="color: #000066; font-weight: bold;">;</span>
					i3=<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">&lt;</span>n<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">?</span>i<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">:</span>i<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">-</span>n<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
					p1=vec<span style="color: #000000;">&#91;</span>i1<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
					p2=vec<span style="color: #000000;">&#91;</span>i2<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
					p3=vec<span style="color: #000000;">&#91;</span>i3<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
					<span style="color: #004993;">d</span>=det<span style="color: #000000;">&#40;</span>p1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>p1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span>p2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>p2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span>p3<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>p3<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>d<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
						isConvex=<span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
						minLen=<span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MAX_VALUE</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
						<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>j=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">&lt;</span>n<span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>j<span style="color: #000066; font-weight: bold;">!</span>=i1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&amp;&amp;</span>j<span style="color: #000066; font-weight: bold;">!</span>=i2<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
								j1=j<span style="color: #000066; font-weight: bold;">;</span>
								j2=<span style="color: #000000;">&#40;</span>j<span style="color: #000066; font-weight: bold;">&lt;</span>n<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">?</span>j<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
								v1=vec<span style="color: #000000;">&#91;</span>j1<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
								v2=vec<span style="color: #000000;">&#91;</span>j2<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
								v=hitRay<span style="color: #000000;">&#40;</span>p1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>p1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span>p2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>p2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span>v1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>v1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span>v2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>v2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
								<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>v<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
									dx=p2<span style="color: #000066; font-weight: bold;">.</span>x<span style="color: #000066; font-weight: bold;">-</span>v<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">;</span>
									dy=p2<span style="color: #000066; font-weight: bold;">.</span>y<span style="color: #000066; font-weight: bold;">-</span>v<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">;</span>
									t=dx<span style="color: #000066; font-weight: bold;">*</span>dx<span style="color: #000066; font-weight: bold;">+</span>dy<span style="color: #000066; font-weight: bold;">*</span>dy<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
									<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>t<span style="color: #000066; font-weight: bold;">&lt;</span>minLen<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
										h=j1<span style="color: #000066; font-weight: bold;">;</span>
										k=j2<span style="color: #000066; font-weight: bold;">;</span>
										hitV=v<span style="color: #000066; font-weight: bold;">;</span>
										minLen=t<span style="color: #000066; font-weight: bold;">;</span>
									<span style="color: #000000;">&#125;</span>
								<span style="color: #000000;">&#125;</span>
							<span style="color: #000000;">&#125;</span>
						<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>minLen==<span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MAX_VALUE</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							err<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
						<span style="color: #000000;">&#125;</span>
&nbsp;
						vec1=<span style="color: #0033ff; font-weight: bold;">new</span> Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>b2Vec2<span style="color: #000066; font-weight: bold;">&gt;</span>  <span style="color: #000066; font-weight: bold;">;</span>
						vec2=<span style="color: #0033ff; font-weight: bold;">new</span> Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>b2Vec2<span style="color: #000066; font-weight: bold;">&gt;</span>  <span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
						j1=h<span style="color: #000066; font-weight: bold;">;</span>
						j2=k<span style="color: #000066; font-weight: bold;">;</span>
						v1=vec<span style="color: #000000;">&#91;</span>j1<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
						v2=vec<span style="color: #000000;">&#91;</span>j2<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
						<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span> pointsMatch<span style="color: #000000;">&#40;</span>hitV<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>hitV<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span>v2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>v2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							vec1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>hitV<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
						<span style="color: #000000;">&#125;</span>
						<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span> pointsMatch<span style="color: #000000;">&#40;</span>hitV<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>hitV<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span>v1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>v1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							vec2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>hitV<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
						<span style="color: #000000;">&#125;</span>
&nbsp;
						h=<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
						k=i1<span style="color: #000066; font-weight: bold;">;</span>
						<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>k<span style="color: #000066; font-weight: bold;">!</span>=j2<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
								vec1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>vec<span style="color: #000000;">&#91;</span>k<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #000000;">&#125;</span>
							<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
								<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>h<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">||</span>h<span style="color: #000066; font-weight: bold;">&gt;</span>=n<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
									err<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
								<span style="color: #000000;">&#125;</span>
								<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>isOnSegment<span style="color: #000000;">&#40;</span>v2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>v2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span>vec<span style="color: #000000;">&#91;</span>h<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>vec<span style="color: #000000;">&#91;</span>h<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span>p1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>p1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
									vec1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>vec<span style="color: #000000;">&#91;</span>k<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
								<span style="color: #000000;">&#125;</span>
								<span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #000000;">&#125;</span>
&nbsp;
							h=k<span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>k<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
								k=n<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #000000;">&#125;</span>
							<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
								k<span style="color: #000066; font-weight: bold;">--;</span>
							<span style="color: #000000;">&#125;</span>
						<span style="color: #000000;">&#125;</span>
&nbsp;
						vec1=vec1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">reverse</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
						h=<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
						k=i2<span style="color: #000066; font-weight: bold;">;</span>
						<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>k<span style="color: #000066; font-weight: bold;">!</span>=j1<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
								vec2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>vec<span style="color: #000000;">&#91;</span>k<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #000000;">&#125;</span>
							<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
								<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>h<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">||</span>h<span style="color: #000066; font-weight: bold;">&gt;</span>=n<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
									err<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
								<span style="color: #000000;">&#125;</span>
								<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>k==j1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&amp;&amp;!</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>isOnSegment<span style="color: #000000;">&#40;</span>v1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>v1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span>vec<span style="color: #000000;">&#91;</span>h<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>vec<span style="color: #000000;">&#91;</span>h<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span>p2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>p2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
									vec2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>vec<span style="color: #000000;">&#91;</span>k<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
								<span style="color: #000000;">&#125;</span>
								<span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #000000;">&#125;</span>
&nbsp;
							h=k<span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>k<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span>n<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
								k=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #000000;">&#125;</span>
							<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
								k<span style="color: #000066; font-weight: bold;">++;</span>
							<span style="color: #000000;">&#125;</span>
						<span style="color: #000000;">&#125;</span>
&nbsp;
						queue<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>vec1<span style="color: #000066; font-weight: bold;">,</span>vec2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
						queue<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">shift</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
						<span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
&nbsp;
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>isConvex<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					figsVec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>queue<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">shift</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">return</span> figsVec<span style="color: #000066; font-weight: bold;">;</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> hitRay<span style="color: #000000;">&#40;</span>x1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>y1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>x2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>y2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>x3<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>y3<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>x4<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>y4<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>b2Vec2 <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> t1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=x3<span style="color: #000066; font-weight: bold;">-</span>x1<span style="color: #000066; font-weight: bold;">,</span>t2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=y3<span style="color: #000066; font-weight: bold;">-</span>y1<span style="color: #000066; font-weight: bold;">,</span>t3<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=x2<span style="color: #000066; font-weight: bold;">-</span>x1<span style="color: #000066; font-weight: bold;">,</span>t4<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=y2<span style="color: #000066; font-weight: bold;">-</span>y1<span style="color: #000066; font-weight: bold;">,</span>t5<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=x4<span style="color: #000066; font-weight: bold;">-</span>x3<span style="color: #000066; font-weight: bold;">,</span>t6<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=y4<span style="color: #000066; font-weight: bold;">-</span>y3<span style="color: #000066; font-weight: bold;">,</span>t7<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=t4<span style="color: #000066; font-weight: bold;">*</span>t5<span style="color: #000066; font-weight: bold;">-</span>t3<span style="color: #000066; font-weight: bold;">*</span>t6<span style="color: #000066; font-weight: bold;">,</span>a<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			a=<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>t5<span style="color: #000066; font-weight: bold;">*</span>t2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">-</span>t6<span style="color: #000066; font-weight: bold;">*</span>t1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">/</span>t7<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> px<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=x1<span style="color: #000066; font-weight: bold;">+</span>a<span style="color: #000066; font-weight: bold;">*</span>t3<span style="color: #000066; font-weight: bold;">,</span>py<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=y1<span style="color: #000066; font-weight: bold;">+</span>a<span style="color: #000066; font-weight: bold;">*</span>t4<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> b1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=isOnSegment<span style="color: #000000;">&#40;</span>x2<span style="color: #000066; font-weight: bold;">,</span>y2<span style="color: #000066; font-weight: bold;">,</span>x1<span style="color: #000066; font-weight: bold;">,</span>y1<span style="color: #000066; font-weight: bold;">,</span>px<span style="color: #000066; font-weight: bold;">,</span>py<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> b2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=isOnSegment<span style="color: #000000;">&#40;</span>px<span style="color: #000066; font-weight: bold;">,</span>py<span style="color: #000066; font-weight: bold;">,</span>x3<span style="color: #000066; font-weight: bold;">,</span>y3<span style="color: #000066; font-weight: bold;">,</span>x4<span style="color: #000066; font-weight: bold;">,</span>y4<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>b1<span style="color: #000066; font-weight: bold;">&amp;&amp;</span>b2<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;">return</span> <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span>px<span style="color: #000066; font-weight: bold;">,</span>py<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</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> hitSegment<span style="color: #000000;">&#40;</span>x1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>y1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>x2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>y2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>x3<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>y3<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>x4<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>y4<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>b2Vec2 <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> t1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=x3<span style="color: #000066; font-weight: bold;">-</span>x1<span style="color: #000066; font-weight: bold;">,</span>t2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=y3<span style="color: #000066; font-weight: bold;">-</span>y1<span style="color: #000066; font-weight: bold;">,</span>t3<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=x2<span style="color: #000066; font-weight: bold;">-</span>x1<span style="color: #000066; font-weight: bold;">,</span>t4<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=y2<span style="color: #000066; font-weight: bold;">-</span>y1<span style="color: #000066; font-weight: bold;">,</span>t5<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=x4<span style="color: #000066; font-weight: bold;">-</span>x3<span style="color: #000066; font-weight: bold;">,</span>t6<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=y4<span style="color: #000066; font-weight: bold;">-</span>y3<span style="color: #000066; font-weight: bold;">,</span>t7<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=t4<span style="color: #000066; font-weight: bold;">*</span>t5<span style="color: #000066; font-weight: bold;">-</span>t3<span style="color: #000066; font-weight: bold;">*</span>t6<span style="color: #000066; font-weight: bold;">,</span>a<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			a=<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>t5<span style="color: #000066; font-weight: bold;">*</span>t2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">-</span>t6<span style="color: #000066; font-weight: bold;">*</span>t1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">/</span>t7<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> px<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=x1<span style="color: #000066; font-weight: bold;">+</span>a<span style="color: #000066; font-weight: bold;">*</span>t3<span style="color: #000066; font-weight: bold;">,</span>py<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=y1<span style="color: #000066; font-weight: bold;">+</span>a<span style="color: #000066; font-weight: bold;">*</span>t4<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> b1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=isOnSegment<span style="color: #000000;">&#40;</span>px<span style="color: #000066; font-weight: bold;">,</span>py<span style="color: #000066; font-weight: bold;">,</span>x1<span style="color: #000066; font-weight: bold;">,</span>y1<span style="color: #000066; font-weight: bold;">,</span>x2<span style="color: #000066; font-weight: bold;">,</span>y2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> b2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=isOnSegment<span style="color: #000000;">&#40;</span>px<span style="color: #000066; font-weight: bold;">,</span>py<span style="color: #000066; font-weight: bold;">,</span>x3<span style="color: #000066; font-weight: bold;">,</span>y3<span style="color: #000066; font-weight: bold;">,</span>x4<span style="color: #000066; font-weight: bold;">,</span>y4<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>b1<span style="color: #000066; font-weight: bold;">&amp;&amp;</span>b2<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;">return</span> <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span>px<span style="color: #000066; font-weight: bold;">,</span>py<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</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> isOnSegment<span style="color: #000000;">&#40;</span>px<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>py<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>x1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>y1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>x2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>y2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> b1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>x1<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">0.1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span>=px<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&amp;&amp;</span>px<span style="color: #000066; font-weight: bold;">&gt;</span>=x2<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">0.1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">||</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>x1<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">0.1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&lt;</span>=px<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&amp;&amp;</span>px<span style="color: #000066; font-weight: bold;">&lt;</span>=x2<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">0.1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> b2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>y1<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">0.1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span>=py<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&amp;&amp;</span>py<span style="color: #000066; font-weight: bold;">&gt;</span>=y2<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">0.1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">||</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>y1<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">0.1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&lt;</span>=py<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&amp;&amp;</span>py<span style="color: #000066; font-weight: bold;">&lt;</span>=y2<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">0.1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>b1<span style="color: #000066; font-weight: bold;">&amp;&amp;</span>b2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&amp;&amp;</span>isOnLine<span style="color: #000000;">&#40;</span>px<span style="color: #000066; font-weight: bold;">,</span>py<span style="color: #000066; font-weight: bold;">,</span>x1<span style="color: #000066; font-weight: bold;">,</span>y1<span style="color: #000066; font-weight: bold;">,</span>x2<span style="color: #000066; font-weight: bold;">,</span>y2<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> pointsMatch<span style="color: #000000;">&#40;</span>x1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>y1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>x2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>y2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> dx<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000;">&#40;</span>x2<span style="color: #000066; font-weight: bold;">&gt;</span>=x1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">?</span>x2<span style="color: #000066; font-weight: bold;">-</span>x1<span style="color: #000066; font-weight: bold;">:</span>x1<span style="color: #000066; font-weight: bold;">-</span>x2<span style="color: #000066; font-weight: bold;">,</span>dy<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000;">&#40;</span>y2<span style="color: #000066; font-weight: bold;">&gt;</span>=y1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">?</span>y2<span style="color: #000066; font-weight: bold;">-</span>y1<span style="color: #000066; font-weight: bold;">:</span>y1<span style="color: #000066; font-weight: bold;">-</span>y2<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>dx<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">0.1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&amp;&amp;</span>dy<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">0.1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> isOnLine<span style="color: #000000;">&#40;</span>px<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>py<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>x1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>y1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>x2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>y2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>x2<span style="color: #000066; font-weight: bold;">-</span>x1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">0.1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">||</span>x1<span style="color: #000066; font-weight: bold;">-</span>x2<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">0.1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> a<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000;">&#40;</span>y2<span style="color: #000066; font-weight: bold;">-</span>y1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000;">&#40;</span>x2<span style="color: #000066; font-weight: bold;">-</span>x1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span>possibleY<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=a<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000;">&#40;</span>px<span style="color: #000066; font-weight: bold;">-</span>x1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">+</span>y1<span style="color: #000066; font-weight: bold;">,</span>diff<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000;">&#40;</span>possibleY<span style="color: #000066; font-weight: bold;">&gt;</span>py<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">?</span>possibleY<span style="color: #000066; font-weight: bold;">-</span>py<span style="color: #000066; font-weight: bold;">:</span>py<span style="color: #000066; font-weight: bold;">-</span>possibleY<span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #000000;">&#40;</span>diff<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">0.1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>px<span style="color: #000066; font-weight: bold;">-</span>x1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">0.1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">||</span>x1<span style="color: #000066; font-weight: bold;">-</span>px<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">0.1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> det<span style="color: #000000;">&#40;</span>x1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>y1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>x2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>y2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>x3<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>y3<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> x1<span style="color: #000066; font-weight: bold;">*</span>y2<span style="color: #000066; font-weight: bold;">+</span>x2<span style="color: #000066; font-weight: bold;">*</span>y3<span style="color: #000066; font-weight: bold;">+</span>x3<span style="color: #000066; font-weight: bold;">*</span>y1<span style="color: #000066; font-weight: bold;">-</span>y1<span style="color: #000066; font-weight: bold;">*</span>x2<span style="color: #000066; font-weight: bold;">-</span>y2<span style="color: #000066; font-weight: bold;">*</span>x3<span style="color: #000066; font-weight: bold;">-</span>y3<span style="color: #000066; font-weight: bold;">*</span>x1<span style="color: #000066; font-weight: bold;">;</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> err<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">throw</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Error</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;A problem has occurred. Use the Validate() method to see where the problem is.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>And this is what you can do with it:</p>
<p><embed src="/wp-content/uploads/2011/09/demo.swf" menu="false" quality="high" width="640" height="480" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p><a href="/wp-content/uploads/2011/09/Box2D_Separator_Archive.zip">Download the source code</a> and all required libraries.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2011/09/12/create-non-convex-complex-shapes-with-box2d/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>4 steps to turn your Flash Arcade site into a two million visitors/month portal</title>
		<link>http://www.emanueleferonato.com/2011/08/10/4-steps-to-turn-your-flash-arcade-site-into-a-two-million-visitorsmonth-portal/</link>
		<comments>http://www.emanueleferonato.com/2011/08/10/4-steps-to-turn-your-flash-arcade-site-into-a-two-million-visitorsmonth-portal/#comments</comments>
		<pubDate>Wed, 10 Aug 2011 15:04:24 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Monetize]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=4529</guid>
		<description><![CDATA[How to create a Flash Arcade portal from scratch and get it to 2,000,000 visitors/month. By Michael Edlavitch]]></description>
			<content:encoded><![CDATA[<p>Old time readers could remember <strong>Michael Edlavitch</strong>&#8216;s <a target = "_blank" href="http://hoodamath.com/" target="_blank">Hooda Math</a>, because two years ago I blogged about its <a href="http://www.emanueleferonato.com/2009/06/01/case-history-creating-a-succesful-niche-flash-arcade-site/" target="_blank">case history</a> and how Michael built from scratch a 10,000 visitors/day Flash Arcade site.</p>
<p><a target= "_blank" href="http://hoodamath.com/"><img src="/wp-content/uploads/2011/08/hooda.jpg" /></a></p>
<p>A lot of time passed (actually two years in Flash related industry is really a big amount of time), and guess what happened to Hooda Math? It turned into a <strong>2,000,000 visitors/month</strong> portal.</p>
<p>Michael shares with us the milestones of this long time ride:</p>
<p>Arcade growth can be determined by 4 stages: in-house games distribution, sponsorships, site-locks, and exclusively hosted.</p>
<p><strong>Stage one, in-house game creation and distribution</strong>, the arcade owner cannot afford to sponsor games, so he develops his own games, brands them, spreads them and hopes for traffic. At the same time you are adding games to your site with another sites branding all over it. But hey at least your arcade has games and hopefully good ones. Feel free to use some of ours at <a href="http://hm.gs/free" target="_blank">http://hm.gs/free</a>.</p>
<p><strong>Stage two, sponsorship</strong>, the arcade owner has made a little money, now he can either pay someone to create games for his site or start sponsoring already developed games. Either way the arcade owner is going to fork over some of his petty cash. For the most bang for his buck it is probably easiest to go sponsor a game at <a href="http://www.flashgamelicense.com/" target="_blank">FGL</a> (a lot of times the developer will want to include mochi or cpmstar ads, and to keep the price down you will subcumb). At least he did not have to waste time making games; instead the arcade owner can waste time spamming, improving SEO or figuring out some other way to get people to come to his site, like writing guest posts on blogs with his anchor text, &#8220;<a href="http://hoodamath.com/games/" target="_blank">Math Games</a>&#8220;, and a link to his site within it. Look up anchor text, it is very important for SEO and, more importantly, he should be looking up and learning about SEO, which is always changing. Not to mention social marketing like <a href="http://facebook.com/hoodamath/" target="_blank">http://facebook.com/hoodamath/</a>.</p>
<p><strong>Stage three, site-locks</strong>, when the arcade owner has received a decent amount of traffic to your site and he is making enough money that if he got fired, he could still survive on rent, an Internet connection, and peanut butter and crackers (and really cheap beer). Analysis comes into play and he should be asking himself, &#8220;So, why are you still wasting ad space on other peoples ads and out-links.&#8221; Every time a user clicks a &#8220;more games&#8221; link inside another arcade&#8217;s branded game, they could have been clicking on one of <strong>your</strong> google ads! (notice how I am speaking directly to stage 3 arcade owners now).  Listen, now that you have a lot of traffic, do the math, if thousands of people are clicking to go play a game elsewhere, when they could have clicked on an ad to buy penny loafers, you just lost money. It is time to buy site-locks, because you still want the already developed games, but rather pay a chunk of money up front and not lose clicks or worse yet traffic. Stage 3 will last a while. Stage three is the money stage, where most arcade owners would love to be. A perfect example, Armor Games, notice how all of their games are branded or site-locked with swords. I personally believe Armor should be on Stage 4, but Stage 4 is more of a state of mind than an actual business strategy. Stage 4 is where Addicting Games lives and few others should be. Impulsively, in Hooda Math Games land we like to fool ourselves and hang-out in Stage 4.</p>
<p><strong>Stage 4, exclusively hosted games</strong>. You may be asking, &#8220;Why would I not brand the hell out of great game and spread it to the top sites to get more traffic. Hopefully, after doing the math, your arcade believes that, like site-locks, the benefits of exclusively hosting out-weighs advertising by distribution. You may delude yourself into thinking, &#8220;Your arcade has received as much traffic as possible from other sites. I would like to remind you that the other arcades still host your old branded games and hopefully new users are still discovering your arcade. But now your arcade wants users to think that the only place they can play a game like &#8220;<a href="http://hoodamath.com/games/" target="_blank">Grow School</a>&#8221; (yes, there is a Grow School now). Play Grow School at  <a href="http://hm.gs/growschool" target="_blank">http://hm.gs/growschool</a>. (More about Short Links on my blog, <a href="http://mikeedla.com/" target="_blank">mikeedla.com</a>).</p>
<p>Caveat, not every arcade follows these 4 stages. Some arcade owners are tripping and jump straight to Stage 4, and others are stingy and refuse to leave Stage 2. Either way, this article is the current belief of an arcade owner that has earned 2 million Monthly Uniques in under 3 years times.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2011/08/10/4-steps-to-turn-your-flash-arcade-site-into-a-two-million-visitorsmonth-portal/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Complete Bejeweled game in less than 2KB &#8211; legible version</title>
		<link>http://www.emanueleferonato.com/2011/05/09/complete-bejeweled-game-in-less-than-2kb-legible-version/</link>
		<comments>http://www.emanueleferonato.com/2011/05/09/complete-bejeweled-game-in-less-than-2kb-legible-version/#comments</comments>
		<pubDate>Mon, 09 May 2011 08:11:03 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=4095</guid>
		<description><![CDATA[The legible version of my <a href="http://www.emanueleferonato.com/2010/12/16/complete-bejeweled-game-in-less-than-2kb/">Complete Bejeweled game in less than 2KB</a>, made by Brook Jordan.]]></description>
			<content:encoded><![CDATA[<p>Do you remember the <a href="http://www.emanueleferonato.com/2010/12/16/complete-bejeweled-game-in-less-than-2kb/">Complete Bejeweled game in less than 2KB</a>?</p>
<p>Putting a Bejeweled game into only 2K made the code look a bit unclear, but <strong>Brook Jordan</strong> shares his readable version with us.</p>
<p>Slightly more legible now, with proper variable names and comments.</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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextField</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> bejewelled <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> gems_array<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> aGem<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> selectorBox<span style="color: #000066; 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><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> selectorRow<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> selectorColumn<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> red<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = 0xFF0000<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> green<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = 0xFF00<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> blue<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = 0xFF<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> yellow<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = 0xFFFF00<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> cyan<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = 0xFFFF<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> magenta<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = 0xFF00FF<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> white<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = 0xFFFFFF<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> colours_array<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span>red<span style="color: #000066; font-weight: bold;">,</span>green<span style="color: #000066; font-weight: bold;">,</span>blue<span style="color: #000066; font-weight: bold;">,</span>yellow<span style="color: #000066; font-weight: bold;">,</span>cyan<span style="color: #000066; font-weight: bold;">,</span>magenta<span style="color: #000066; font-weight: bold;">,</span>white<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> clickPossible<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> score_txt<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextField</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> hint_txt<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextField</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> score<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> inaRow<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">match</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> bejewelled<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #009900; font-style: italic;">// Game initiation</span>
			<span style="color: #009900; font-style: italic;">// Create and style score text</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>score_txt<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			score_txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">textColor</span>=0xFFFFFF<span style="color: #000066; font-weight: bold;">;</span>
			score_txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span>=<span style="color: #000000; font-weight:bold;">500</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// Create and style hint text</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>hint_txt<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			hint_txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">textColor</span>=0xFFFFFF<span style="color: #000066; font-weight: bold;">;</span>
			hint_txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span>=<span style="color: #000000; font-weight:bold;">550</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// Create Gems in rows and columns</span>
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">8</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				gems_array<span style="color: #000000;">&#91;</span>i<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><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> j<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">8</span><span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #0033ff; font-weight: bold;">do</span> <span style="color: #000000;">&#123;</span>
						gems_array<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span>=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">floor</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">7</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #000000;">&#125;</span>
						<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>rowLineLength<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000066; font-weight: bold;">||</span> columnLineLength<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					aGem=<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: #000066; font-weight: bold;">;</span>
					aGem<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span>colours_array<span style="color: #000000;">&#91;</span>gems_array<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					aGem<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">drawCircle</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">30</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">30</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">29</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					aGem<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					aGem<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span>=i<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;_&quot;</span><span style="color: #000066; font-weight: bold;">+</span>j<span style="color: #000066; font-weight: bold;">;</span>
					aGem<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span>=j<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">60</span><span style="color: #000066; font-weight: bold;">;</span>
					aGem<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span>=i<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">60</span><span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>aGem<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #009900; font-style: italic;">// Create and style selector box</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>selectorBox<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			selectorBox<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">lineStyle</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">,</span>red<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			selectorBox<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</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: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">60</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			selectorBox<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">visible</span>=<span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// Listen for user input</span>
			<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span>onClick<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span>everyFrame<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #009900; font-style: italic;">// Every frame...</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> everyFrame<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #009900; font-style: italic;">//Assume that gems are not falling</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> gemsAreFalling<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// Check each gem for space below it</span>
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">6</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&gt;</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">--</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> j<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">8</span><span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #009900; font-style: italic;">// If a spot contains a gem, and has an empty space below...</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>gems_array<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span> <span style="color: #000066; font-weight: bold;">!</span>= <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000066; font-weight: bold;">&amp;&amp;</span> gems_array<span style="color: #000000;">&#91;</span>i<span style="color: #000066; 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>j<span style="color: #000000;">&#93;</span>==<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
						<span style="color: #009900; font-style: italic;">// Set gems falling</span>
						gemsAreFalling=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
						gems_array<span style="color: #000000;">&#91;</span>i<span style="color: #000066; 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>j<span style="color: #000000;">&#93;</span>=gems_array<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
						gems_array<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span>=<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
						<span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;_&quot;</span><span style="color: #000066; font-weight: bold;">+</span>j<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">+</span>=<span style="color: #000000; font-weight:bold;">60</span><span style="color: #000066; font-weight: bold;">;</span>
						<span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;_&quot;</span><span style="color: #000066; font-weight: bold;">+</span>j<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span>=<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;_&quot;</span><span style="color: #000066; font-weight: bold;">+</span>j<span style="color: #000066; font-weight: bold;">;</span>
						<span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
				<span style="color: #009900; font-style: italic;">// If a gem is falling</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>gemsAreFalling<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #009900; font-style: italic;">// don't allow any more to start falling</span>
					<span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #009900; font-style: italic;">// If no gems are falling</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span> gemsAreFalling<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #009900; font-style: italic;">// Assume no new gems are needed</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> needNewGem<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #009900; font-style: italic;">// but check all spaces...</span>
				<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i=<span style="color: #000000; font-weight:bold;">7</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&gt;</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">--</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>j=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">8</span><span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
						<span style="color: #009900; font-style: italic;">// and if a spot is empty</span>
						<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>gems_array<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span>==<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							<span style="color: #009900; font-style: italic;">// now we know we need a new gem</span>
							needNewGem=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #009900; font-style: italic;">// pick a random color for the gem</span>
							gems_array<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span>=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">floor</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">7</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #009900; font-style: italic;">// create the gem</span>
							aGem=<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: #000066; font-weight: bold;">;</span>
							aGem<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span>colours_array<span style="color: #000000;">&#91;</span>gems_array<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
							aGem<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">drawCircle</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">30</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">30</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">29</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
							aGem<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #009900; font-style: italic;">// ID it</span>
							aGem<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;0_&quot;</span><span style="color: #000066; font-weight: bold;">+</span>j<span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #009900; font-style: italic;">// position it</span>
							aGem<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span>=j<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">60</span><span style="color: #000066; font-weight: bold;">;</span>
							aGem<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #009900; font-style: italic;">// show it</span>
							<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>aGem<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #009900; font-style: italic;">// stop creating new gems</span>
							<span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
						<span style="color: #000000;">&#125;</span>
					<span style="color: #000000;">&#125;</span>
					<span style="color: #009900; font-style: italic;">// if a new gem was created, stop checking</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>needNewGem<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
						<span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
				<span style="color: #009900; font-style: italic;">// If no new gems were needed...</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span> needNewGem<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #009900; font-style: italic;">// assume no more/new lines are on the board</span>
					<span style="color: #6699cc; font-weight: bold;">var</span> moreLinesAvailable<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #009900; font-style: italic;">// check all gems</span>
					<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i=<span style="color: #000000; font-weight:bold;">7</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&gt;</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">--</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>j=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">8</span><span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							<span style="color: #009900; font-style: italic;">// if a line is found</span>
							<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>rowLineLength<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000066; font-weight: bold;">||</span> columnLineLength<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
								<span style="color: #009900; font-style: italic;">// then we know more lines are available</span>
								moreLinesAvailable=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
								<span style="color: #009900; font-style: italic;">// creat a new array, set the gem type of the line, and where it is</span>
								<span style="color: #6699cc; font-weight: bold;">var</span> lineGems<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span>=<span style="color: #000000;">&#91;</span>i<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;_&quot;</span><span style="color: #000066; font-weight: bold;">+</span>j<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
								<span style="color: #6699cc; font-weight: bold;">var</span> gemType<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span>=gems_array<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
								<span style="color: #6699cc; font-weight: bold;">var</span> linePosition<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">;</span>
								<span style="color: #009900; font-style: italic;">// check t's a horizontal line...</span>
								<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>rowLineLength<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
									<span style="color: #009900; font-style: italic;">// if so, find our how long it is and put all the line's gems into the array</span>
									linePosition=j<span style="color: #000066; font-weight: bold;">;</span>
									<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>sameGemIsHere<span style="color: #000000;">&#40;</span>gemType<span style="color: #000066; font-weight: bold;">,</span>i<span style="color: #000066; font-weight: bold;">,</span>linePosition<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
										linePosition<span style="color: #000066; font-weight: bold;">--;</span>
										lineGems<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;_&quot;</span><span style="color: #000066; font-weight: bold;">+</span>linePosition<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
									<span style="color: #000000;">&#125;</span>
									linePosition=j<span style="color: #000066; font-weight: bold;">;</span>
									<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>sameGemIsHere<span style="color: #000000;">&#40;</span>gemType<span style="color: #000066; font-weight: bold;">,</span>i<span style="color: #000066; font-weight: bold;">,</span>linePosition<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
										linePosition<span style="color: #000066; font-weight: bold;">++;</span>
										lineGems<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;_&quot;</span><span style="color: #000066; font-weight: bold;">+</span>linePosition<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
									<span style="color: #000000;">&#125;</span>
								<span style="color: #000000;">&#125;</span>
								<span style="color: #009900; font-style: italic;">// check t's a vertical line...</span>
								<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>columnLineLength<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
									<span style="color: #009900; font-style: italic;">// if so, find our how long it is and put all the line's gems into the array</span>
									linePosition=i<span style="color: #000066; font-weight: bold;">;</span>
									<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>sameGemIsHere<span style="color: #000000;">&#40;</span>gemType<span style="color: #000066; font-weight: bold;">,</span>linePosition<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
										linePosition<span style="color: #000066; font-weight: bold;">--;</span>
										lineGems<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>linePosition<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;_&quot;</span><span style="color: #000066; font-weight: bold;">+</span>j<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
									<span style="color: #000000;">&#125;</span>
									linePosition=i<span style="color: #000066; font-weight: bold;">;</span>
									<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>sameGemIsHere<span style="color: #000000;">&#40;</span>gemType<span style="color: #000066; font-weight: bold;">,</span>linePosition<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
										linePosition<span style="color: #000066; font-weight: bold;">++;</span>
										lineGems<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>linePosition<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;_&quot;</span><span style="color: #000066; font-weight: bold;">+</span>j<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
									<span style="color: #000000;">&#125;</span>
								<span style="color: #000000;">&#125;</span>
								<span style="color: #009900; font-style: italic;">// for all gems in the line...</span>
								<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span>lineGems<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
									<span style="color: #009900; font-style: italic;">// remove it from the program</span>
									<span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span>lineGems<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
									<span style="color: #009900; font-style: italic;">// find where it was in the array</span>
									<span style="color: #6699cc; font-weight: bold;">var</span> cd<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span>=lineGems<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">split</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;_&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
									<span style="color: #009900; font-style: italic;">// set it to an empty gem space</span>
									gems_array<span style="color: #000000;">&#91;</span>cd<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>cd<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span>=<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
									<span style="color: #009900; font-style: italic;">// set the new score</span>
									score<span style="color: #000066; font-weight: bold;">+</span>=inaRow<span style="color: #000066; font-weight: bold;">;</span>
									<span style="color: #009900; font-style: italic;">// set the score setter up</span>
									inaRow<span style="color: #000066; font-weight: bold;">++;</span>
								<span style="color: #000000;">&#125;</span>
								<span style="color: #009900; font-style: italic;">// if a row was made, stop the loop</span>
								<span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #000000;">&#125;</span>
						<span style="color: #000000;">&#125;</span>
						<span style="color: #009900; font-style: italic;">// if a line was made, stop making more lines</span>
						<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>moreLinesAvailable<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							<span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
						<span style="color: #000000;">&#125;</span>
					<span style="color: #000000;">&#125;</span>
					<span style="color: #009900; font-style: italic;">// if no more lines were available...</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span> moreLinesAvailable<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
						<span style="color: #009900; font-style: italic;">// allow new moves to be made</span>
						clickPossible=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
						<span style="color: #009900; font-style: italic;">// remove score multiplier</span>
						inaRow=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #009900; font-style: italic;">// display new score</span>
			score_txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span>=score<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #009900; font-style: italic;">// When the user clicks</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onClick<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #009900; font-style: italic;">// If a click is allowed</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>clickPossible<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #009900; font-style: italic;">// If the click is within the game area...</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>mouseX<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">480</span><span style="color: #000066; font-weight: bold;">&amp;&amp;</span>mouseX<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">&amp;&amp;</span>mouseY<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">480</span><span style="color: #000066; font-weight: bold;">&amp;&amp;</span>mouseY<span style="color: #000066; 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>
					<span style="color: #009900; font-style: italic;">// Find which row and column were clicked</span>
					<span style="color: #6699cc; font-weight: bold;">var</span> clickedRow<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span>=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">floor</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">mouseY</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #6699cc; font-weight: bold;">var</span> clickedColumn<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span>=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">floor</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">mouseX</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #009900; font-style: italic;">// Check if the clicked gem is adjacent to the selector</span>
					<span style="color: #009900; font-style: italic;">// If not...</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>clickedRow==selectorRow<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000066; font-weight: bold;">||</span> clickedRow==selectorRow<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&amp;&amp;</span>clickedColumn==selectorColumn<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">||</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>clickedColumn==selectorColumn<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000066; font-weight: bold;">||</span> clickedColumn==selectorColumn<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">&amp;&amp;</span> clickedRow==selectorRow<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
						<span style="color: #009900; font-style: italic;">// Find row and colum the selector should move to</span>
						selectorRow=clickedRow<span style="color: #000066; font-weight: bold;">;</span>
						selectorColumn=clickedColumn<span style="color: #000066; font-weight: bold;">;</span>
						<span style="color: #009900; font-style: italic;">// Move it to the chosen position</span>
						selectorBox<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span>=<span style="color: #000000; font-weight:bold;">60</span><span style="color: #000066; font-weight: bold;">*</span>selectorColumn<span style="color: #000066; font-weight: bold;">;</span>
						selectorBox<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span>=<span style="color: #000000; font-weight:bold;">60</span><span style="color: #000066; font-weight: bold;">*</span>selectorRow<span style="color: #000066; font-weight: bold;">;</span>
						<span style="color: #009900; font-style: italic;">// If hidden, show it.</span>
						selectorBox<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">visible</span>=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #000000;">&#125;</span>
					<span style="color: #009900; font-style: italic;">// If it is not next to it...</span>
					<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
						<span style="color: #009900; font-style: italic;">// Swap the gems;</span>
						swapGems<span style="color: #000000;">&#40;</span>selectorRow<span style="color: #000066; font-weight: bold;">,</span>selectorColumn<span style="color: #000066; font-weight: bold;">,</span>clickedRow<span style="color: #000066; font-weight: bold;">,</span>clickedColumn<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
						<span style="color: #009900; font-style: italic;">// If they make a line...</span>
						<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>rowLineLength<span style="color: #000000;">&#40;</span>selectorRow<span style="color: #000066; font-weight: bold;">,</span>selectorColumn<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000066; font-weight: bold;">||</span> columnLineLength<span style="color: #000000;">&#40;</span>selectorRow<span style="color: #000066; font-weight: bold;">,</span>selectorColumn<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">||</span>rowLineLength<span style="color: #000000;">&#40;</span>clickedRow<span style="color: #000066; font-weight: bold;">,</span>clickedColumn<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000066; font-weight: bold;">||</span> columnLineLength<span style="color: #000000;">&#40;</span>clickedRow<span style="color: #000066; font-weight: bold;">,</span>clickedColumn<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							<span style="color: #009900; font-style: italic;">// remove the hint text</span>
							hint_txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #009900; font-style: italic;">// dis-allow a new move until cascade has ended (removes glitches)</span>
							clickPossible=<span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #009900; font-style: italic;">// move and rename the gems</span>
							<span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span>selectorRow<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;_&quot;</span><span style="color: #000066; font-weight: bold;">+</span>selectorColumn<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span>=clickedColumn<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">60</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span>selectorRow<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;_&quot;</span><span style="color: #000066; font-weight: bold;">+</span>selectorColumn<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span>=clickedRow<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">60</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span>selectorRow<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;_&quot;</span><span style="color: #000066; font-weight: bold;">+</span>selectorColumn<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;t&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span>clickedRow<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;_&quot;</span><span style="color: #000066; font-weight: bold;">+</span>clickedColumn<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span>=selectorColumn<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">60</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span>clickedRow<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;_&quot;</span><span style="color: #000066; font-weight: bold;">+</span>clickedColumn<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span>=selectorRow<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">60</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span>clickedRow<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;_&quot;</span><span style="color: #000066; font-weight: bold;">+</span>clickedColumn<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span>=selectorRow<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;_&quot;</span><span style="color: #000066; font-weight: bold;">+</span>selectorColumn<span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;t&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span>=clickedRow<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;_&quot;</span><span style="color: #000066; font-weight: bold;">+</span>clickedColumn<span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #004993;">match</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
						<span style="color: #000000;">&#125;</span>
						<span style="color: #009900; font-style: italic;">// If not...</span>
						<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
							<span style="color: #009900; font-style: italic;">// Switch them back</span>
							swapGems<span style="color: #000000;">&#40;</span>selectorRow<span style="color: #000066; font-weight: bold;">,</span>selectorColumn<span style="color: #000066; font-weight: bold;">,</span>clickedRow<span style="color: #000066; font-weight: bold;">,</span>clickedColumn<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #004993;">match</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
						<span style="color: #000000;">&#125;</span>
						<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">match</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							<span style="color: #009900; font-style: italic;">// Move the selector position to default</span>
							selectorRow=<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span>
							selectorColumn=<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #009900; font-style: italic;">// and hide it</span>
							selectorBox<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">visible</span>=<span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
						<span style="color: #000000;">&#125;</span>
						<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
							<span style="color: #009900; font-style: italic;">// Set the selector position</span>
							selectorRow=clickedRow<span style="color: #000066; font-weight: bold;">;</span>
							selectorColumn=clickedColumn<span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #009900; font-style: italic;">// Move the box into position</span>
							selectorBox<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span>=<span style="color: #000000; font-weight:bold;">60</span><span style="color: #000066; font-weight: bold;">*</span>selectorColumn<span style="color: #000066; font-weight: bold;">;</span>
							selectorBox<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span>=<span style="color: #000000; font-weight:bold;">60</span><span style="color: #000066; font-weight: bold;">*</span>selectorRow<span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #004993;">match</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #009900; font-style: italic;">// If hidden, show it.</span>
							selectorBox<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">visible</span>=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
						<span style="color: #000000;">&#125;</span>
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
				<span style="color: #009900; font-style: italic;">// If the click is outside the game area</span>
				<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #009900; font-style: italic;">// For gems in all rows...</span>
					<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">8</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
						<span style="color: #009900; font-style: italic;">// and columns...</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> j<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">8</span><span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							<span style="color: #009900; font-style: italic;">// if they're not too close to the side... </span>
							<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">7</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
								<span style="color: #009900; font-style: italic;">// swap them horizontally</span>
								swapGems<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000066; font-weight: bold;">,</span>i<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
								<span style="color: #009900; font-style: italic;">// check if they form a line</span>
								<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>rowLineLength<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">||</span>columnLineLength<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">||</span>rowLineLength<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">||</span>columnLineLength<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
									<span style="color: #009900; font-style: italic;">// if so, name the move made</span>
									selectorBox<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = j<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">60</span><span style="color: #000066; font-weight: bold;">;</span>
									selectorBox<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = i<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">60</span><span style="color: #000066; font-weight: bold;">;</span>
									selectorBox<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">visible</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
									hint_txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;,&quot;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000;">&#40;</span>j<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;-&gt;&quot;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;,&quot;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000;">&#40;</span>j<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
								<span style="color: #000000;">&#125;</span>
								<span style="color: #009900; font-style: italic;">// swap the gems back</span>
								swapGems<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000066; font-weight: bold;">,</span>i<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #000000;">&#125;</span>
							<span style="color: #009900; font-style: italic;">// then if they're not to close to the bottom...</span>
							<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>j<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">7</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
								<span style="color: #009900; font-style: italic;">// swap it vertically</span>
								swapGems<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000066; font-weight: bold;">,</span>i<span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
								<span style="color: #009900; font-style: italic;">// check if it forms a line</span>
								<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>rowLineLength<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">||</span>columnLineLength<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">||</span>rowLineLength<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">||</span>columnLineLength<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
									<span style="color: #009900; font-style: italic;">// if so, name it</span>
									selectorBox<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = j<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">60</span><span style="color: #000066; font-weight: bold;">;</span>
									selectorBox<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = i<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">60</span><span style="color: #000066; font-weight: bold;">;</span>
									selectorBox<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">visible</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
									hint_txt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;,&quot;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000;">&#40;</span>j<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;-&gt;&quot;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;,&quot;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000;">&#40;</span>j<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
								<span style="color: #000000;">&#125;</span>
								<span style="color: #009900; font-style: italic;">// swap the gems back</span>
								swapGems<span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000066; font-weight: bold;">,</span>i<span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #000000;">&#125;</span>
						<span style="color: #000000;">&#125;</span>
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #009900; font-style: italic;">//Swap given gems</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> swapGems<span style="color: #000000;">&#40;</span>fromRow<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000066; font-weight: bold;">,</span>fromColumn<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000066; font-weight: bold;">,</span>toRow<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000066; font-weight: bold;">,</span>toColumn<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #009900; font-style: italic;">//Save the original position</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> originalPosition<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span>=gems_array<span style="color: #000000;">&#91;</span>fromRow<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>fromColumn<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">//Move original gem to new position</span>
			gems_array<span style="color: #000000;">&#91;</span>fromRow<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>fromColumn<span style="color: #000000;">&#93;</span>=gems_array<span style="color: #000000;">&#91;</span>toRow<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>toColumn<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">//move second gem to saved, original gem's position</span>
			gems_array<span style="color: #000000;">&#91;</span>toRow<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>toColumn<span style="color: #000000;">&#93;</span>=originalPosition<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #009900; font-style: italic;">//Find out if there us a horizontal line</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> rowLineLength<span style="color: #000000;">&#40;</span>row<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000066; font-weight: bold;">,</span>column<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> gemType<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span>=gems_array<span style="color: #000000;">&#91;</span>row<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>column<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> lineLength<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span>=<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> checkColumn<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=column<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">//check how far left it extends</span>
			<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>sameGemIsHere<span style="color: #000000;">&#40;</span>gemType<span style="color: #000066; font-weight: bold;">,</span>row<span style="color: #000066; font-weight: bold;">,</span>checkColumn<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				checkColumn<span style="color: #000066; font-weight: bold;">--;</span>
				lineLength<span style="color: #000066; font-weight: bold;">++;</span>
			<span style="color: #000000;">&#125;</span>
			checkColumn=column<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">//check how far right it extends</span>
			<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>sameGemIsHere<span style="color: #000000;">&#40;</span>gemType<span style="color: #000066; font-weight: bold;">,</span>row<span style="color: #000066; font-weight: bold;">,</span>checkColumn<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				checkColumn<span style="color: #000066; font-weight: bold;">++;</span>
				lineLength<span style="color: #000066; font-weight: bold;">++;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #009900; font-style: italic;">// return total line length</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #000000;">&#40;</span>lineLength<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #009900; font-style: italic;">//Find out if there us a vertical line</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> columnLineLength<span style="color: #000000;">&#40;</span>row<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000066; font-weight: bold;">,</span>column<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> gemType<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span>=gems_array<span style="color: #000000;">&#91;</span>row<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>column<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> lineLength<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span>=<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> checkRow<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=row<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">//check how low it extends</span>
			<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>sameGemIsHere<span style="color: #000000;">&#40;</span>gemType<span style="color: #000066; font-weight: bold;">,</span>checkRow<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span>column<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				checkRow<span style="color: #000066; font-weight: bold;">--;</span>
				lineLength<span style="color: #000066; font-weight: bold;">++;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #009900; font-style: italic;">//check how high it extends</span>
			checkRow=row<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>sameGemIsHere<span style="color: #000000;">&#40;</span>gemType<span style="color: #000066; font-weight: bold;">,</span>checkRow<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span>column<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				checkRow<span style="color: #000066; font-weight: bold;">++;</span>
				lineLength<span style="color: #000066; font-weight: bold;">++;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #009900; font-style: italic;">// return total line length</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #000000;">&#40;</span>lineLength<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> sameGemIsHere<span style="color: #000000;">&#40;</span>gemType<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000066; font-weight: bold;">,</span>row<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span>column<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #009900; font-style: italic;">//Check there are gems in the chosen row</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>gems_array<span style="color: #000000;">&#91;</span>row<span style="color: #000000;">&#93;</span>==<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #009900; font-style: italic;">//If there are, check if there is a gem in the chosen slot</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>gems_array<span style="color: #000000;">&#91;</span>row<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>column<span style="color: #000000;">&#93;</span>==<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #009900; font-style: italic;">//If there is, check if it's the same as the chosen gem type</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> gemType==gems_array<span style="color: #000000;">&#91;</span>row<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>column<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>And the final size? 2.711 bytes, a 33% larger than the <a href="http://www.emanueleferonato.com/2010/12/16/complete-bejeweled-game-in-less-than-2kb/">original code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2011/05/09/complete-bejeweled-game-in-less-than-2kb-legible-version/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>The making of A Small Car, a 3D Flash game made with Flare3D</title>
		<link>http://www.emanueleferonato.com/2011/04/18/the-making-of-a-small-car-a-3d-flash-game-made-with-flare3d/</link>
		<comments>http://www.emanueleferonato.com/2011/04/18/the-making-of-a-small-car-a-3d-flash-game-made-with-flare3d/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 20:24:03 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=4001</guid>
		<description><![CDATA[Christian Östman explains the workflow that brought A Small Car game to our monitors.]]></description>
			<content:encoded><![CDATA[<p>Do you want to know how to make a successful Flash 3D game? <strong>Christian Östman</strong> from <a target  "_blank" href="http://www.asmallgame.com/">a small game</a> made a 15 million plays (and counting) game, and shares with us some interesting information.</p>
<p>If you have played <a href="http://www.asmallgame.com/?p=658" target = "_blank">A Small Car</a> you know that  it’s a 3D Flash Game where you drive a small car on winding levels in the sky.  Since we released it in December 2010 it’s been played over 15 million times.</p>
<p><a href="http://www.asmallgame.com/?p=658" target = "_blank"><img src="/wp-content/uploads/2011/04/asmallcar.jpg" /></a></p>
<p>It was the first game made by me, Christian Östman (coding, gameplay) and Richard Åström (art,leveldesign, sound) under the “A Small Game” – name.</p>
<p>As there’s not that many 3D flash games around of this kind we thought it could be interesting for others to read about how we made the game and the workflow we used, especially with Molehill waiting around the corner.<span id="more-4001"></span></p>
<p>The game was made in about 8 weeks, but neither of us spent full-time on it, so i would estimate that we spent around 2 weeks each full-time making the game. A while before we started working on the game i had experimented a bit with the <a href="http://www.flare3d.com/" target = "_blank">Flare3D</a> engine, which is a 3D engine for Flash.</p>
<p>Besides being very easy to use and being very good performance-wise it has an awesome integration with 3d Studio Max in the form of a plugin. With the plugin it’s possible to create 3D content and preview it directly in the Flash Player, without leaving 3d Studio Max. This would prove to be very important for the workflow we used to make the game (more on that later).</p>
<p><strong>Physics</strong></p>
<p>One of my first tests with the Flare3D engine was to try and integrate it with <a href="http://www.jiglibflash.com/" target = "_blank">JiglibFlash</a>, wich is a great 3D-physics engine that i’ve used before.</p>
<p>The way Jiglib works, as most physics-engines, is that you add physics-primitives and set their properties. While running the physics simulation you then use these primitives to correctly position your displayed objects.</p>
<p>After having JiglibFlash running with Flare3D i started thinkig about how nice it would be if you could edit the physics directly from 3D Studio instead of having to write it in code . This way you could eliminate basically all level-specific code which i knew from earlier projects could take a lot of time. To be able to edit the physics from 3D Studio i wrote a small AS-class called PhysicsParser.as. It uses a great feature in the Flare3D plugin called UserData.</p>
<p>User Data makes it possible to add any custom properties to your objects directly in 3DStudio Max, these properties are then read into Flare3D when you load your scene in flash. So what PhysicsParser does is parsing a Flare3D scene and looking for a User Data property called “jiglib”, if that exists it looks at the other properties on that object and creates a physics object and sets all the properties on it.<br />
Some example properties includes: type (box,sphere,cylinder), movable, friction, restitution and so on. This is how setting userData on an object looks like in 3d studio Max:</p>
<p><img src="/wp-content/uploads/2011/04/asmallcar2.jpg" /></p>
<p><strong>Game Engine</strong></p>
<p>With a physics engine that was editable from within 3dstudio max, it was time to start making a game.</p>
<p>Jiglibflash actually comes with a class that simulates a car, and i’ve been wanting to use it for a while in a game. So I made a quick test with the JiglibCar, added some keycontrols to it and used a car-model that Richard had made for another game we had been experimenting with. I made it so it loaded an external Flare3D scene called level.f3d and parsed it using physicsparser.</p>
<p>Then i could go directly in to 3D Studio, create a level and set the physicsproperties, and just export it as level.f3d. Then start the game.swf and the level would load, and you could drive around in the level directly. It’s even possible to animate stuff (which we ended up not using that much, but for example on the spinning Earth in the Bonus Level).</p>
<p>The flare3d plugin comes with a feature that makes this even nicer, called Custom Exporter, there you just define a swf that should start when you press export. So with this it was possible to make changes to the level and instantly try it out in the game. At this point  i sent the swf to Richard and asked if he wanted to make the levels for the game.</p>
<p>Which he did, and it allowed me to focus only on the game-engine, and Richard could create all of the levels, without the need to write any code. Here are some screens of how the levels looked like in 3D Studio:</p>
<p><img src="/wp-content/uploads/2011/04/asmallcar3.jpg" /></p>
<p><img src="/wp-content/uploads/2011/04/asmallcar4.jpg" /></p>
<p><img src="/wp-content/uploads/2011/04/asmallcar5.jpg" /></p>
<p><strong>The rest</strong></p>
<p>We added some more specific user data variables that was parsed for the game, like for example “goal” wich could be set on any object, making it a goal, and if the car would get in a certain range of a goal object the level would end. After all the levels was finished we embedded them all inside the game.  Richard composed the soundtrack, and we added some menus and a titlescreen to the game. Finished!</p>
<p>For our new game <a href="http://www.asmallgame.com/?p=813" target = "_blank">INTRUDED</a> we’re using a similar (identical) workflow, even though it’s a very different game, and not using Jiglib for the physics. We’ve made it so that almost everything in the game is editable from 3d Studio, making it very fun and easy to create different style of gameplay without writing any custom code.</p>
<p>Thanks for reading, and don’t hesitate to comment below if you have any questions. Also, don’t forget to check out the awesome <a target = "_blank" href="http://www.flare3d.com/">Flare3D</a> engine. Version 2.0 (using Molehill) is in pre-beta at the moment and looks very promising!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2011/04/18/the-making-of-a-small-car-a-3d-flash-game-made-with-flare3d/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Redesigning the blog</title>
		<link>http://www.emanueleferonato.com/2011/04/04/redesigning-the-blog/</link>
		<comments>http://www.emanueleferonato.com/2011/04/04/redesigning-the-blog/#comments</comments>
		<pubDate>Mon, 04 Apr 2011 20:48:40 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Php]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Users contributions]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3955</guid>
		<description><![CDATA[Since the blog is almost five years old, I must seriously redesign it. The problem is: there are so many beautiful blog themes out there I really do not know how to redesign my blog. That&#8217;s why I am asking you some suggestions. How should this blog look like? Which features would you add? Help [...]]]></description>
			<content:encoded><![CDATA[<p>Since the blog is almost <strong>five years old</strong>, I must seriously redesign it. The problem is: there are so many beautiful blog themes out there I really do not know how to redesign my blog.</p>
<p>That&#8217;s why I am asking you some suggestions. How should this blog look like? Which features would you add?</p>
<p>Help me with your ideas and feedback and I&#8217;ll design the blog according to your suggestions, obviously publishing the source code as usual.</p>
<p>I have to say I don&#8217;t like that much the blogs with slideshows in the header, preferring minimalist design like <a target = "_blank" href="http://psd.tutsplus.com/">tutsplus network</a>.</p>
<p>Well, I will wait for some suggestions, I&#8217;d start from the header. Consider I want to keep the logo.</p>
<p>WordPress heroes, this is your time. Show me your ultimate theme.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2011/04/04/redesigning-the-blog/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Box2D collisions rendered in 3D with Away3D</title>
		<link>http://www.emanueleferonato.com/2011/03/15/box2d-collisions-rendered-in-3d-with-away3d/</link>
		<comments>http://www.emanueleferonato.com/2011/03/15/box2d-collisions-rendered-in-3d-with-away3d/#comments</comments>
		<pubDate>Tue, 15 Mar 2011 18:27:14 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3850</guid>
		<description><![CDATA[Did you ever wonder what would be possible if you could merge a 2D physics engine with a 3D engine? Roger Engelbert from Done With Computers, apart from having a blog with awesome posts (really! have a look!), tried to use Away3D to render Box2D collisions. You will see the result by yourself. &#171; Here [...]]]></description>
			<content:encoded><![CDATA[<p>Did you ever wonder what would be possible if you could merge a 2D physics engine with a 3D engine?</p>
<p><strong>Roger Engelbert</strong> from <a href="http://www.rengelbert.com/" target = "_blank">Done With Computers</a>, apart from having a blog with awesome posts (really! have a look!), tried to use Away3D to render Box2D collisions.</p>
<p>You will see the result by yourself. </p>
<p>&laquo; Here I&#8217;ll show you another way to build 3D collisions using 2D logic, by combining the Box2D engine with 3D rendering of elements. For this example, you must think of games where the 3D Y axis is not relevant (no change in altitude.)</p>
<p>In the game you can push the blue blocks, the larger one is harder to push around. And you cannot push the green cylinder. And when you shoot you a have nice recoil effect.</p>
<p>Here is the Box2D version of the &#8220;game&#8221;:<span id="more-3850"></span></p>
<p><embed src="/wp-content/uploads/2011/03/Box2Dto3D.swf" allowscriptaccess="always" menu="false" quality="high" width="640" height="450" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>Use arrows to move, and space bar to shoot.</p>
<p>And here is the code for this version:</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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>  
<span style="color: #000000;">&#123;</span>  
    <span style="color: #0033ff; font-weight: bold;">import</span> Box2D<span style="color: #000066; font-weight: bold;">.</span>Collision<span style="color: #000066; font-weight: bold;">.</span>Shapes<span style="color: #000066; font-weight: bold;">.*;</span>  
    <span style="color: #0033ff; font-weight: bold;">import</span> Box2D<span style="color: #000066; font-weight: bold;">.</span>Collision<span style="color: #000066; font-weight: bold;">.</span>b2AABB<span style="color: #000066; font-weight: bold;">;</span>  
    <span style="color: #0033ff; font-weight: bold;">import</span> Box2D<span style="color: #000066; font-weight: bold;">.</span>Common<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.*;</span>  
    <span style="color: #0033ff; font-weight: bold;">import</span> Box2D<span style="color: #000066; font-weight: bold;">.</span>Dynamics<span style="color: #000066; font-weight: bold;">.*;</span>  
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">DisplayObjectContainer</span><span style="color: #000066; font-weight: bold;">;</span>  
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>  
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span>  
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000066; font-weight: bold;">;</span>  
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span><span style="color: #000066; font-weight: bold;">.*;</span>  
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.utils</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Timer</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
    <span style="color: #000000;">&#91;</span>SWF<span style="color: #000000;">&#40;</span><span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;800&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;600&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">backgroundColor</span>=<span style="color: #990000;">&quot;0x000000&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">frameRate</span>=<span style="color: #990000;">&quot;30&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>  
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Box2Dto3D <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span>  
    <span style="color: #000000;">&#123;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> static const Y_DIR<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _moveLeft<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _moveRight<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _moveUp<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _moveDown<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
        <span style="color: #009900; font-style: italic;">//box2D stuff  </span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _world<span style="color: #000066; font-weight: bold;">:</span>b2World<span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _player<span style="color: #000066; font-weight: bold;">:</span>b2Body<span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _block1<span style="color: #000066; font-weight: bold;">:</span>b2Body<span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _block2<span style="color: #000066; font-weight: bold;">:</span>b2Body<span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> speed<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">5</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> player_rec<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">50</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> block1_rec<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,-</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">80</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">80</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> block2_rec<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> shoot_timer<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Timer</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Timer</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">500</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> bullets<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>b2body<span style="color: #000066; font-weight: bold;">&gt;;</span>  
&nbsp;
&nbsp;
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Box2Dto3D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>  
        <span style="color: #000000;">&#123;</span>  
            <span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">400</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">300</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            bullets = <span style="color: #0033ff; font-weight: bold;">new</span> Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>b2body<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            createScene<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">KEY_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> onKey_Down<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">KEY_UP</span><span style="color: #000066; font-weight: bold;">,</span> onKey_Up<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> onLoop<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #000000;">&#125;</span>  
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createScene <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>  
&nbsp;
            _world = <span style="color: #0033ff; font-weight: bold;">new</span> b2World<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #6699cc; font-weight: bold;">var</span> contactListener<span style="color: #000066; font-weight: bold;">:</span>BulletCollisionListener = <span style="color: #0033ff; font-weight: bold;">new</span> BulletCollisionListener<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            _world<span style="color: #000066; font-weight: bold;">.</span>SetContactListener<span style="color: #000000;">&#40;</span>contactListener<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #009900; font-style: italic;">//set up debug draw  </span>
            <span style="color: #6699cc; font-weight: bold;">var</span> debugDraw<span style="color: #000066; font-weight: bold;">:</span>b2DebugDraw = <span style="color: #0033ff; font-weight: bold;">new</span> b2DebugDraw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #6699cc; font-weight: bold;">var</span> container<span style="color: #000066; 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><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>container<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            debugDraw<span style="color: #000066; font-weight: bold;">.</span>SetSprite<span style="color: #000000;">&#40;</span>container<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            debugDraw<span style="color: #000066; font-weight: bold;">.</span>SetDrawScale<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">30</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            debugDraw<span style="color: #000066; font-weight: bold;">.</span>SetFlags<span style="color: #000000;">&#40;</span>b2DebugDraw<span style="color: #000066; font-weight: bold;">.</span>e_shapeBit<span style="color: #000066; font-weight: bold;">|</span>b2DebugDraw<span style="color: #000066; font-weight: bold;">.</span>e_jointBit<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            debugDraw<span style="color: #000066; font-weight: bold;">.</span>SetFillAlpha<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0.5</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
&nbsp;
            <span style="color: #009900; font-style: italic;">//create player  </span>
            <span style="color: #6699cc; font-weight: bold;">var</span> bodyDef<span style="color: #000066; font-weight: bold;">:</span>b2BodyDef = createBoxDef<span style="color: #000000;">&#40;</span>player_rec<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">type</span> = b2Body<span style="color: #000066; font-weight: bold;">.</span>b2_dynamicBody<span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span>allowSleep = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #6699cc; font-weight: bold;">var</span> bodyFixture<span style="color: #000066; font-weight: bold;">:</span>b2FixtureDef = createBoxFixture<span style="color: #000000;">&#40;</span>player_rec<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            _player = _world<span style="color: #000066; font-weight: bold;">.</span>CreateBody<span style="color: #000000;">&#40;</span>bodyDef<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            _player<span style="color: #000066; font-weight: bold;">.</span>CreateFixture<span style="color: #000000;">&#40;</span>bodyFixture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">type</span> = <span style="color: #990000;">&quot;block&quot;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #009900; font-style: italic;">//create obstacles  </span>
            <span style="color: #009900; font-style: italic;">//block 1  </span>
            bodyDef = createBoxDef<span style="color: #000000;">&#40;</span>block1_rec<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">type</span> = b2Body<span style="color: #000066; font-weight: bold;">.</span>b2_dynamicBody<span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span>linearDamping = <span style="color: #000000; font-weight:bold;">20</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture = createBoxFixture<span style="color: #000000;">&#40;</span>block1_rec<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>density = <span style="color: #000000; font-weight:bold;">0.5</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>friction = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            _block1 = _world<span style="color: #000066; font-weight: bold;">.</span>CreateBody<span style="color: #000000;">&#40;</span>bodyDef<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            _block1<span style="color: #000066; font-weight: bold;">.</span>CreateFixture<span style="color: #000000;">&#40;</span>bodyFixture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            _block1<span style="color: #000066; font-weight: bold;">.</span>SetUserData<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #009900; font-style: italic;">//block 2  </span>
            bodyDef = createBoxDef<span style="color: #000000;">&#40;</span>block2_rec<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">type</span> = b2Body<span style="color: #000066; font-weight: bold;">.</span>b2_dynamicBody<span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span>linearDamping = <span style="color: #000000; font-weight:bold;">20</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture = createBoxFixture<span style="color: #000000;">&#40;</span>block2_rec<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>density = <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>friction = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            _block2 = _world<span style="color: #000066; font-weight: bold;">.</span>CreateBody<span style="color: #000000;">&#40;</span>bodyDef<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            _block2<span style="color: #000066; font-weight: bold;">.</span>CreateFixture<span style="color: #000000;">&#40;</span>bodyFixture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            _block2<span style="color: #000066; font-weight: bold;">.</span>SetUserData<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #009900; font-style: italic;">//fixed pillar  </span>
            bodyDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">position</span><span style="color: #000066; font-weight: bold;">.</span>Set<span style="color: #000000;">&#40;</span>p2m<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> p2m<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">40</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">type</span> = b2Body<span style="color: #000066; font-weight: bold;">.</span>b2_staticBody<span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #6699cc; font-weight: bold;">var</span> bodyShape<span style="color: #000066; font-weight: bold;">:</span>b2CircleShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2CircleShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyShape<span style="color: #000066; font-weight: bold;">.</span>SetRadius <span style="color: #000000;">&#40;</span>p2m<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>shape = bodyShape<span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>density = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> pillar<span style="color: #000066; font-weight: bold;">:</span>b2Body = _world<span style="color: #000066; font-weight: bold;">.</span>CreateBody<span style="color: #000000;">&#40;</span>bodyDef<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            pillar<span style="color: #000066; font-weight: bold;">.</span>CreateFixture<span style="color: #000000;">&#40;</span>bodyFixture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            pillar<span style="color: #000066; font-weight: bold;">.</span>SetUserData<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
&nbsp;
            _world<span style="color: #000066; font-weight: bold;">.</span>SetDebugDraw<span style="color: #000000;">&#40;</span>debugDraw<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
        <span style="color: #000000;">&#125;</span>  
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> shoot <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>  
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>shoot_timer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">running</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #009900; font-style: italic;">//create particle  </span>
            <span style="color: #6699cc; font-weight: bold;">var</span> bodyDef<span style="color: #000066; font-weight: bold;">:</span>b2BodyDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #6699cc; font-weight: bold;">var</span> pPos<span style="color: #000066; font-weight: bold;">:</span>b2Vec2 = _player<span style="color: #000066; font-weight: bold;">.</span>GetPosition<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">angle</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = _player<span style="color: #000066; font-weight: bold;">.</span>GetAngle<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>  <span style="color: #000066; font-weight: bold;">+</span> Y_DIR<span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>  
            pPos<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">-</span>= p2m<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            pPos<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">-</span>= p2m<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            bodyDef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">position</span><span style="color: #000066; font-weight: bold;">.</span>Set<span style="color: #000000;">&#40;</span>pPos<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span> pPos<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            bodyDef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">type</span> = b2Body<span style="color: #000066; font-weight: bold;">.</span>b2_dynamicBody<span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span>angularDamping = <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> bodyShape<span style="color: #000066; font-weight: bold;">:</span>b2CircleShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2CircleShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyShape<span style="color: #000066; font-weight: bold;">.</span>SetRadius <span style="color: #000000;">&#40;</span>p2m<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #6699cc; font-weight: bold;">var</span> bodyFixture<span style="color: #000066; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>shape = bodyShape<span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>density = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>restitution = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> bulletData<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bulletData<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">type</span> = <span style="color: #990000;">&quot;bullet&quot;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bulletData<span style="color: #000066; font-weight: bold;">.</span>hit = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">bullet</span><span style="color: #000066; font-weight: bold;">:</span>b2Body = _world<span style="color: #000066; font-weight: bold;">.</span>CreateBody<span style="color: #000000;">&#40;</span>bodyDef<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #004993;">bullet</span><span style="color: #000066; font-weight: bold;">.</span>CreateFixture<span style="color: #000000;">&#40;</span>bodyFixture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #004993;">bullet</span><span style="color: #000066; font-weight: bold;">.</span>SetUserData<span style="color: #000000;">&#40;</span>bulletData<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #004993;">bullet</span><span style="color: #000066; font-weight: bold;">.</span>SetLinearVelocity<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,-</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            bullets<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">bullet</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #009900; font-style: italic;">//shoot_timer.reset();  </span>
            shoot_timer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
        <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> p2m<span style="color: #000000;">&#40;</span>pixel<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> <span style="color: #000000;">&#123;</span>  
            <span style="color: #0033ff; font-weight: bold;">return</span> pixel<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">30</span><span style="color: #000066; font-weight: bold;">;</span>  
        <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> m2p<span style="color: #000000;">&#40;</span>m<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> <span style="color: #000000;">&#123;</span>  
            <span style="color: #0033ff; font-weight: bold;">return</span> m <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">30</span><span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #000000;">&#125;</span>  
&nbsp;
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> updateBody <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>  
&nbsp;
            _player<span style="color: #000066; font-weight: bold;">.</span>SetLinearVelocity<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>_moveLeft<span style="color: #000000;">&#41;</span> _player<span style="color: #000066; font-weight: bold;">.</span>SetAngle<span style="color: #000000;">&#40;</span> _player<span style="color: #000066; font-weight: bold;">.</span>GetAngle<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">-</span> Y_DIR<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">0.1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>_moveRight<span style="color: #000000;">&#41;</span> _player<span style="color: #000066; font-weight: bold;">.</span>SetAngle<span style="color: #000000;">&#40;</span> _player<span style="color: #000066; font-weight: bold;">.</span>GetAngle<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> Y_DIR<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">0.1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">angle</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = _player<span style="color: #000066; font-weight: bold;">.</span>GetAngle<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #6699cc; font-weight: bold;">var</span> playerVelocity<span style="color: #000066; font-weight: bold;">:</span>b2Vec2 = _player<span style="color: #000066; font-weight: bold;">.</span>GetLinearVelocity<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>_moveUp <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>  
                playerVelocity<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">-</span>= Y_DIR<span style="color: #000066; font-weight: bold;">*</span>speed<span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
                playerVelocity<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">-</span>= Y_DIR<span style="color: #000066; font-weight: bold;">*</span>speed<span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #000000;">&#125;</span>  
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>_moveDown <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>  
                playerVelocity<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span>= Y_DIR<span style="color: #000066; font-weight: bold;">*</span>speed<span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
                playerVelocity<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">+</span>= Y_DIR<span style="color: #000066; font-weight: bold;">*</span>speed<span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>      
            <span style="color: #000000;">&#125;</span>  
&nbsp;
        <span style="color: #000000;">&#125;</span>  
&nbsp;
&nbsp;
        <span style="color: #009900; font-style: italic;">///////////////////////////// EVENTS ///////////////////////////////////////  </span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onKey_Up <span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>  
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">keyCode</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>  
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">38</span><span style="color: #000066; font-weight: bold;">:</span>  
                    <span style="color: #009900; font-style: italic;">//UP KEY is up  </span>
                    _moveUp = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>  
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>  
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">39</span><span style="color: #000066; font-weight: bold;">:</span>  
                    <span style="color: #009900; font-style: italic;">//RIGHT KEY is up  </span>
                    _moveRight = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>  
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>  
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">37</span><span style="color: #000066; font-weight: bold;">:</span>  
                    <span style="color: #009900; font-style: italic;">//LEFT Key is up  </span>
                    _moveLeft = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>  
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>  
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">40</span><span style="color: #000066; font-weight: bold;">:</span>  
                    <span style="color: #009900; font-style: italic;">//DOWN KEY is up  </span>
                    _moveDown = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>  
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>  
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">32</span><span style="color: #000066; font-weight: bold;">:</span>  
                    <span style="color: #009900; font-style: italic;">//SPACE Bar is up  </span>
                    shoot<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #000000;">&#125;</span>  
        <span style="color: #000000;">&#125;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onKey_Down <span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>  
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">keyCode</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>  
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">38</span><span style="color: #000066; font-weight: bold;">:</span>  
                    <span style="color: #009900; font-style: italic;">//UP KEY is down  </span>
                    _moveUp = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>   
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>  
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">39</span><span style="color: #000066; font-weight: bold;">:</span>  
                    <span style="color: #009900; font-style: italic;">//RIGHT KEY is down  </span>
                    _moveRight = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>  
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">37</span><span style="color: #000066; font-weight: bold;">:</span>  
                    <span style="color: #009900; font-style: italic;">//LEFT Key is down  </span>
                    _moveLeft = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>  
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">40</span><span style="color: #000066; font-weight: bold;">:</span>  
                    <span style="color: #009900; font-style: italic;">//DOWN KEY is down  </span>
                    _moveDown = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>  
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>  
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">32</span><span style="color: #000066; font-weight: bold;">:</span>  
                    <span style="color: #009900; font-style: italic;">//SPACE BAR is down  </span>
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #000000;">&#125;</span>  
        <span style="color: #000000;">&#125;</span>  
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onLoop <span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>  
            updateBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            _world<span style="color: #000066; font-weight: bold;">.</span>Step<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">30</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            _world<span style="color: #000066; font-weight: bold;">.</span>DrawDebugData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = bullets<span style="color: #000066; font-weight: bold;">.</span>length<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&gt;</span>= <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">--</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>  
                <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>bullets<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>GetUserData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>hit == <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>  
                        _world<span style="color: #000066; font-weight: bold;">.</span>DestroyBody<span style="color: #000000;">&#40;</span>bullets<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
                        bullets<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">splice</span><span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
                        <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>  
                <span style="color: #000000;">&#125;</span>  
            <span style="color: #000000;">&#125;</span>  
        <span style="color: #000000;">&#125;</span>  
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createBoxDef <span style="color: #000000;">&#40;</span>rec<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>b2BodyDef <span style="color: #000000;">&#123;</span>  
            <span style="color: #6699cc; font-weight: bold;">var</span> bodyDef<span style="color: #000066; font-weight: bold;">:</span>b2BodyDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">position</span><span style="color: #000066; font-weight: bold;">.</span>Set<span style="color: #000000;">&#40;</span>p2m<span style="color: #000000;">&#40;</span>rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span> rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> p2m<span style="color: #000000;">&#40;</span>rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">+</span> rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">type</span> = b2Body<span style="color: #000066; font-weight: bold;">.</span>b2_staticBody<span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span>angularDamping = <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #0033ff; font-weight: bold;">return</span> bodyDef<span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #000000;">&#125;</span>  
&nbsp;
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createBoxFixture <span style="color: #000000;">&#40;</span>rec<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>b2FixtureDef <span style="color: #000000;">&#123;</span>  
            <span style="color: #6699cc; font-weight: bold;">var</span> bodyShape<span style="color: #000066; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyShape<span style="color: #000066; font-weight: bold;">.</span>SetAsBox <span style="color: #000000;">&#40;</span>p2m<span style="color: #000000;">&#40;</span>rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> p2m<span style="color: #000000;">&#40;</span>rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #6699cc; font-weight: bold;">var</span> bodyFixture<span style="color: #000066; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>shape = bodyShape<span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>density = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>restitution = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #0033ff; font-weight: bold;">return</span> bodyFixture<span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #000000;">&#125;</span>  
&nbsp;
    <span style="color: #000000;">&#125;</span>  
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>And the collision object for the sake of completeness:</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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D<span style="color: #000066; font-weight: bold;">.</span>Dynamics<span style="color: #000066; font-weight: bold;">.</span>Contacts<span style="color: #000066; font-weight: bold;">.</span>b2Contact<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D<span style="color: #000066; font-weight: bold;">.</span>Dynamics<span style="color: #000066; font-weight: bold;">.</span>b2ContactListener<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> BulletCollisionListener <span style="color: #0033ff; font-weight: bold;">extends</span> b2ContactListener <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> BulletCollisionListener<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> BeginContact<span style="color: #000000;">&#40;</span>contact<span style="color: #000066; font-weight: bold;">:</span>b2Contact<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>contact<span style="color: #000066; font-weight: bold;">.</span>GetFixtureA<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>GetBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>GetUserData<span style="color: #000000;">&#40;</span><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;">if</span> <span style="color: #000000;">&#40;</span>contact<span style="color: #000066; font-weight: bold;">.</span>GetFixtureA<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>GetBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>GetUserData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">type</span> == <span style="color: #990000;">&quot;bullet&quot;</span> <span style="color: #000066; font-weight: bold;">&amp;&amp;</span>  
				                        contact<span style="color: #000066; font-weight: bold;">.</span>GetFixtureB<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>GetBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>GetUserData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">type</span> == <span style="color: #990000;">&quot;block&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					contact<span style="color: #000066; font-weight: bold;">.</span>GetFixtureA<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>GetBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>GetUserData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>hit=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>contact<span style="color: #000066; font-weight: bold;">.</span>GetFixtureB<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>GetBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>GetUserData<span style="color: #000000;">&#40;</span><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;">if</span> <span style="color: #000000;">&#40;</span> contact<span style="color: #000066; font-weight: bold;">.</span>GetFixtureB<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>GetBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>GetUserData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">type</span> == <span style="color: #990000;">&quot;bullet&quot;</span> <span style="color: #000066; font-weight: bold;">&amp;&amp;</span>  
				                        contact<span style="color: #000066; font-weight: bold;">.</span>GetFixtureA<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>GetBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>GetUserData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">type</span> == <span style="color: #990000;">&quot;block&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
					contact<span style="color: #000066; font-weight: bold;">.</span>GetFixtureB<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>GetBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>GetUserData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>hit=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Now in 3D I use the same Box2D code but I add 3D primitives. Here is the 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
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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">import</span> away3d<span style="color: #000066; font-weight: bold;">.</span>cameras<span style="color: #000066; font-weight: bold;">.*;</span>  
    <span style="color: #0033ff; font-weight: bold;">import</span> away3d<span style="color: #000066; font-weight: bold;">.</span>containers<span style="color: #000066; font-weight: bold;">.*;</span>  
    <span style="color: #0033ff; font-weight: bold;">import</span> away3d<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>base<span style="color: #000066; font-weight: bold;">.</span>Object3D<span style="color: #000066; font-weight: bold;">;</span>  
    <span style="color: #0033ff; font-weight: bold;">import</span> away3d<span style="color: #000066; font-weight: bold;">.</span>lights<span style="color: #000066; font-weight: bold;">.*;</span>  
    <span style="color: #0033ff; font-weight: bold;">import</span> away3d<span style="color: #000066; font-weight: bold;">.</span>materials<span style="color: #000066; font-weight: bold;">.*;</span>  
    <span style="color: #0033ff; font-weight: bold;">import</span> away3d<span style="color: #000066; font-weight: bold;">.</span>primitives<span style="color: #000066; font-weight: bold;">.*;</span>  
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">BitmapData</span><span style="color: #000066; font-weight: bold;">;</span>  
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">DisplayObjectContainer</span><span style="color: #000066; font-weight: bold;">;</span>  
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>  
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span>  
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000066; font-weight: bold;">;</span>  
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span><span style="color: #000066; font-weight: bold;">.*;</span>  
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.utils</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Timer</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
    <span style="color: #000000;">&#91;</span>SWF<span style="color: #000000;">&#40;</span><span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;800&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;600&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">backgroundColor</span>=<span style="color: #990000;">&quot;0x444444&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">frameRate</span>=<span style="color: #990000;">&quot;30&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>  
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Box3D <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>  
&nbsp;
        <span style="color: #009900; font-style: italic;">//in case I need to adjust the change in Y direction  </span>
        <span style="color: #0033ff; font-weight: bold;">private</span> static const Y_DIR<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _moveLeft<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _moveRight<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _moveUp<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _moveDown<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
        <span style="color: #009900; font-style: italic;">//box2D stuff  </span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _world<span style="color: #000066; font-weight: bold;">:</span>b2World<span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _b2player<span style="color: #000066; font-weight: bold;">:</span>b2Body<span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _b2block1<span style="color: #000066; font-weight: bold;">:</span>b2Body<span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _b2block2<span style="color: #000066; font-weight: bold;">:</span>b2Body<span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> speed<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">5</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> player_rec<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">50</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> block1_rec<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">80</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">80</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> block2_rec<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,-</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
        <span style="color: #009900; font-style: italic;">//away3D stuff  </span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _view<span style="color: #000066; font-weight: bold;">:</span>View3D<span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _player<span style="color: #000066; font-weight: bold;">:</span>Cube<span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _block1<span style="color: #000066; font-weight: bold;">:</span>Cube<span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _block2<span style="color: #000066; font-weight: bold;">:</span>Cube<span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _container<span style="color: #000066; font-weight: bold;">:</span>ObjectContainer3D<span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> camera<span style="color: #000066; font-weight: bold;">:</span>TargetCamera3D<span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> shoot_timer<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Timer</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Timer</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">500</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> b2bullets<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>b2body<span style="color: #000066; font-weight: bold;">&gt;;</span>  
&nbsp;
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Box3D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>  
            <span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">400</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">300</span><span style="color: #000066; font-weight: bold;">;</span>  
            createScene<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            b2bullets = <span style="color: #0033ff; font-weight: bold;">new</span> Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>b2body<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">KEY_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> onKey_Down<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">KEY_UP</span><span style="color: #000066; font-weight: bold;">,</span> onKey_Up<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> onLoop<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #000000;">&#125;</span>  
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createScene <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>  
            createBox2DWorld<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            createAway3DView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #000000;">&#125;</span>  
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createBox2DWorld<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>  
&nbsp;
            _world = <span style="color: #0033ff; font-weight: bold;">new</span> b2World<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #6699cc; font-weight: bold;">var</span> contactListener<span style="color: #000066; font-weight: bold;">:</span>BulletCollisionListener = <span style="color: #0033ff; font-weight: bold;">new</span> BulletCollisionListener<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            _world<span style="color: #000066; font-weight: bold;">.</span>SetContactListener<span style="color: #000000;">&#40;</span>contactListener<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
&nbsp;
            <span style="color: #009900; font-style: italic;">//create player  </span>
            <span style="color: #6699cc; font-weight: bold;">var</span> bodyDef<span style="color: #000066; font-weight: bold;">:</span>b2BodyDef = createBoxDef<span style="color: #000000;">&#40;</span>player_rec<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">type</span> = b2Body<span style="color: #000066; font-weight: bold;">.</span>b2_dynamicBody<span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span>allowSleep = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #6699cc; font-weight: bold;">var</span> bodyFixture<span style="color: #000066; font-weight: bold;">:</span>b2FixtureDef = createBoxFixture<span style="color: #000000;">&#40;</span>player_rec<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            _b2player = _world<span style="color: #000066; font-weight: bold;">.</span>CreateBody<span style="color: #000000;">&#40;</span>bodyDef<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            _b2player<span style="color: #000066; font-weight: bold;">.</span>CreateFixture<span style="color: #000000;">&#40;</span>bodyFixture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">type</span> = <span style="color: #990000;">&quot;block&quot;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #009900; font-style: italic;">//create obstacles  </span>
            <span style="color: #009900; font-style: italic;">//block 1  </span>
            bodyDef = createBoxDef<span style="color: #000000;">&#40;</span>block1_rec<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">type</span> = b2Body<span style="color: #000066; font-weight: bold;">.</span>b2_dynamicBody<span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span>linearDamping = <span style="color: #000000; font-weight:bold;">20</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture = createBoxFixture<span style="color: #000000;">&#40;</span>block1_rec<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>density = <span style="color: #000000; font-weight:bold;">0.5</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>friction = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            _b2block1 = _world<span style="color: #000066; font-weight: bold;">.</span>CreateBody<span style="color: #000000;">&#40;</span>bodyDef<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            _b2block1<span style="color: #000066; font-weight: bold;">.</span>CreateFixture<span style="color: #000000;">&#40;</span>bodyFixture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            _b2block1<span style="color: #000066; font-weight: bold;">.</span>SetUserData<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
&nbsp;
            <span style="color: #009900; font-style: italic;">//block 2  </span>
            bodyDef = createBoxDef<span style="color: #000000;">&#40;</span>block2_rec<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">type</span> = b2Body<span style="color: #000066; font-weight: bold;">.</span>b2_dynamicBody<span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span>linearDamping = <span style="color: #000000; font-weight:bold;">20</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture = createBoxFixture<span style="color: #000000;">&#40;</span>block2_rec<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>density = <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>friction = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            _b2block2 = _world<span style="color: #000066; font-weight: bold;">.</span>CreateBody<span style="color: #000000;">&#40;</span>bodyDef<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            _b2block2<span style="color: #000066; font-weight: bold;">.</span>CreateFixture<span style="color: #000000;">&#40;</span>bodyFixture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            _b2block2<span style="color: #000066; font-weight: bold;">.</span>SetUserData<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #009900; font-style: italic;">//fixed pillar  </span>
            bodyDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">position</span><span style="color: #000066; font-weight: bold;">.</span>Set<span style="color: #000000;">&#40;</span>p2m<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> p2m<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">40</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">type</span> = b2Body<span style="color: #000066; font-weight: bold;">.</span>b2_staticBody<span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #6699cc; font-weight: bold;">var</span> bodyShape<span style="color: #000066; font-weight: bold;">:</span>b2CircleShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2CircleShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyShape<span style="color: #000066; font-weight: bold;">.</span>SetRadius <span style="color: #000000;">&#40;</span>p2m<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>shape = bodyShape<span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>density = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> pillar<span style="color: #000066; font-weight: bold;">:</span>b2Body = _world<span style="color: #000066; font-weight: bold;">.</span>CreateBody<span style="color: #000000;">&#40;</span>bodyDef<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            pillar<span style="color: #000066; font-weight: bold;">.</span>CreateFixture<span style="color: #000000;">&#40;</span>bodyFixture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            pillar<span style="color: #000066; font-weight: bold;">.</span>SetUserData<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
&nbsp;
        <span style="color: #000000;">&#125;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createAway3DView <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>  
            _container = <span style="color: #0033ff; font-weight: bold;">new</span> ObjectContainer3D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> scene<span style="color: #000066; font-weight: bold;">:</span>Scene3D = <span style="color: #0033ff; font-weight: bold;">new</span> Scene3D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            camera = <span style="color: #0033ff; font-weight: bold;">new</span> TargetCamera3D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            camera<span style="color: #000066; font-weight: bold;">.</span>z = <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1200</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            _view = <span style="color: #0033ff; font-weight: bold;">new</span> View3D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#123;</span>scene<span style="color: #000066; font-weight: bold;">:</span>scene<span style="color: #000066; font-weight: bold;">,</span> camera<span style="color: #000066; font-weight: bold;">:</span>camera<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>_view<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> light <span style="color: #000066; font-weight: bold;">:</span> PointLight3D = <span style="color: #0033ff; font-weight: bold;">new</span> PointLight3D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>   
            light<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">position</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Vector3D<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">500</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,-</span><span style="color: #000000; font-weight:bold;">500</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            light<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">color</span> = 0xFFFFFF<span style="color: #000066; font-weight: bold;">;</span>   
            light<span style="color: #000066; font-weight: bold;">.</span>diffuse = <span style="color: #000000; font-weight:bold;">0.7</span><span style="color: #000066; font-weight: bold;">;</span>  
            light<span style="color: #000066; font-weight: bold;">.</span>brightness = <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>  
            _view<span style="color: #000066; font-weight: bold;">.</span>scene<span style="color: #000066; font-weight: bold;">.</span>addLight<span style="color: #000000;">&#40;</span>light<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #009900; font-style: italic;">//var material:WireColorMaterial = new WireColorMaterial(0xFF9900,{wireColor:0x000000});  </span>
            <span style="color: #6699cc; font-weight: bold;">var</span> material<span style="color: #000066; font-weight: bold;">:</span>ShadingColorMaterial = <span style="color: #0033ff; font-weight: bold;">new</span> ShadingColorMaterial<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>   
            material<span style="color: #000066; font-weight: bold;">.</span>ambient = 0xFF9900<span style="color: #000066; font-weight: bold;">;</span>   
            material<span style="color: #000066; font-weight: bold;">.</span>diffuse = 0xFF9900<span style="color: #000066; font-weight: bold;">;</span>   
            material<span style="color: #000066; font-weight: bold;">.</span>specular = 0xFF9900<span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> plane<span style="color: #000066; font-weight: bold;">:</span>Plane = <span style="color: #0033ff; font-weight: bold;">new</span> Plane<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#123;</span>material<span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">new</span> WireColorMaterial<span style="color: #000000;">&#40;</span>0x666666<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000;">&#123;</span>wireColor<span style="color: #000066; font-weight: bold;">:</span>0x666666<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">1000</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">height</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">1000</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            plane<span style="color: #000066; font-weight: bold;">.</span>bothsides = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>  
            plane<span style="color: #000066; font-weight: bold;">.</span>rotationX = <span style="color: #000000; font-weight:bold;">90</span><span style="color: #000066; font-weight: bold;">;</span>  
            plane<span style="color: #000066; font-weight: bold;">.</span>segmentsW = plane<span style="color: #000066; font-weight: bold;">.</span>segmentsH = <span style="color: #000000; font-weight:bold;">4</span><span style="color: #000066; font-weight: bold;">;</span>  
            plane<span style="color: #000066; font-weight: bold;">.</span>z = <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">;</span>  
            plane<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">;</span>  
            plane<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">30</span><span style="color: #000066; font-weight: bold;">;</span>  
            plane<span style="color: #000066; font-weight: bold;">.</span>ownCanvas = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>  
            _view<span style="color: #000066; font-weight: bold;">.</span>scene<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>plane<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            _container<span style="color: #000066; font-weight: bold;">.</span>ownCanvas = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            _player = <span style="color: #0033ff; font-weight: bold;">new</span> Cube<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#123;</span>material<span style="color: #000066; font-weight: bold;">:</span>material<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">:</span>player_rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">height</span><span style="color: #000066; font-weight: bold;">:</span>player_rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">,</span>depth<span style="color: #000066; font-weight: bold;">:</span>player_rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            _player<span style="color: #000066; font-weight: bold;">.</span>z = <span style="color: #000000; font-weight:bold;">25</span><span style="color: #000066; font-weight: bold;">;</span>  
            _player<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = player_rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">;</span>  
            _player<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = player_rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #009900; font-style: italic;">//create a 'face' for the cube, so player knows what is the front side  </span>
            _player<span style="color: #000066; font-weight: bold;">.</span>cubeMaterials<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bottom</span>=<span style="color: #0033ff; font-weight: bold;">new</span> WireColorMaterial<span style="color: #000000;">&#40;</span>0xFF3399<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000;">&#123;</span>wireColor<span style="color: #000066; font-weight: bold;">:</span>0x222222<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #009900; font-style: italic;">//use own canvas to help with z sorting       </span>
            <span style="color: #009900; font-style: italic;">//_player.ownCanvas = true;  </span>
            _container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>_player<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            material = <span style="color: #0033ff; font-weight: bold;">new</span> ShadingColorMaterial<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>   
            material<span style="color: #000066; font-weight: bold;">.</span>ambient = 0x0099FF<span style="color: #000066; font-weight: bold;">;</span>   
            material<span style="color: #000066; font-weight: bold;">.</span>diffuse = 0x0099FF<span style="color: #000066; font-weight: bold;">;</span>   
            material<span style="color: #000066; font-weight: bold;">.</span>specular = 0x0099FF<span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            _block1 = <span style="color: #0033ff; font-weight: bold;">new</span> Cube<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#123;</span>material<span style="color: #000066; font-weight: bold;">:</span>material<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">:</span>block1_rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">height</span><span style="color: #000066; font-weight: bold;">:</span>block1_rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">,</span>depth<span style="color: #000066; font-weight: bold;">:</span>block1_rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            _block1<span style="color: #000066; font-weight: bold;">.</span>z = <span style="color: #000000; font-weight:bold;">40</span><span style="color: #000066; font-weight: bold;">;</span>  
            _block1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = block1_rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">;</span>  
            _block1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = block1_rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">;</span>  
            _block1<span style="color: #000066; font-weight: bold;">.</span>segmentsD = <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>  
            _block1<span style="color: #000066; font-weight: bold;">.</span>segmentsH = <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>  
            _block1<span style="color: #000066; font-weight: bold;">.</span>segmentsW = <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            _container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>_block1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
&nbsp;
            _block2 = <span style="color: #0033ff; font-weight: bold;">new</span> Cube<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#123;</span>material<span style="color: #000066; font-weight: bold;">:</span>material<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">:</span>block2_rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">height</span><span style="color: #000066; font-weight: bold;">:</span>block2_rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000066; font-weight: bold;">,</span>depth<span style="color: #000066; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            _block2<span style="color: #000066; font-weight: bold;">.</span>z = <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">;</span>  
            _block2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = block2_rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">;</span>  
            _block2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = block2_rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">;</span>  
            _block2<span style="color: #000066; font-weight: bold;">.</span>segmentsD = <span style="color: #000000; font-weight:bold;">4</span><span style="color: #000066; font-weight: bold;">;</span>  
            _block2<span style="color: #000066; font-weight: bold;">.</span>segmentsH = <span style="color: #000000; font-weight:bold;">4</span><span style="color: #000066; font-weight: bold;">;</span>  
            _block2<span style="color: #000066; font-weight: bold;">.</span>segmentsW = <span style="color: #000000; font-weight:bold;">4</span><span style="color: #000066; font-weight: bold;">;</span>  
            _container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>_block2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            material = <span style="color: #0033ff; font-weight: bold;">new</span> ShadingColorMaterial<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>   
            material<span style="color: #000066; font-weight: bold;">.</span>ambient = 0x66FF00<span style="color: #000066; font-weight: bold;">;</span>   
            material<span style="color: #000066; font-weight: bold;">.</span>diffuse = 0x66FF00<span style="color: #000066; font-weight: bold;">;</span>   
            material<span style="color: #000066; font-weight: bold;">.</span>specular = 0x66FF00<span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> pillar<span style="color: #000066; font-weight: bold;">:</span>Cylinder = <span style="color: #0033ff; font-weight: bold;">new</span> Cylinder<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#123;</span>material<span style="color: #000066; font-weight: bold;">:</span>material<span style="color: #000066; font-weight: bold;">,</span> radius<span style="color: #000066; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">20</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">height</span><span style="color: #000066; font-weight: bold;">:</span> <span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            pillar<span style="color: #000066; font-weight: bold;">.</span>rotationX = <span style="color: #000000; font-weight:bold;">90</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #3f5fbf;">/* 
            remember that the origin of an object is at its center: 
            so the z of every object is changed so that they are all &quot;lying on the floor&quot;  
            */</span>  
            pillar<span style="color: #000066; font-weight: bold;">.</span>z = <span style="color: #000000; font-weight:bold;">30</span><span style="color: #000066; font-weight: bold;">;</span>  
            pillar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = Y_DIR<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">;</span>  
            pillar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = Y_DIR<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">40</span><span style="color: #000066; font-weight: bold;">;</span>  
            _container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>pillar<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
&nbsp;
            <span style="color: #009900; font-style: italic;">//rotate the view to add 3D feel and match the one from the 2D version   </span>
            _container<span style="color: #000066; font-weight: bold;">.</span>rotationZ = <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000066; font-weight: bold;">;</span>  
            _container<span style="color: #000066; font-weight: bold;">.</span>rotationX = <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000066; font-weight: bold;">;</span>  
            _view<span style="color: #000066; font-weight: bold;">.</span>scene<span style="color: #000066; font-weight: bold;">.</span>rotationX = <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">45</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            camera<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span> = _player<span style="color: #000066; font-weight: bold;">;</span>  
            _view<span style="color: #000066; font-weight: bold;">.</span>scene<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>_container<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
        <span style="color: #000000;">&#125;</span>  
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> shoot <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>  
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>shoot_timer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">running</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #009900; font-style: italic;">//create particle in box2D  </span>
            <span style="color: #6699cc; font-weight: bold;">var</span> bodyDef<span style="color: #000066; font-weight: bold;">:</span>b2BodyDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #6699cc; font-weight: bold;">var</span> pPos<span style="color: #000066; font-weight: bold;">:</span>b2Vec2 = _b2player<span style="color: #000066; font-weight: bold;">.</span>GetPosition<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">angle</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = _b2player<span style="color: #000066; font-weight: bold;">.</span>GetAngle<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>  
            pPos<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">-</span>= p2m<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            pPos<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">-</span>= p2m<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            bodyDef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">position</span><span style="color: #000066; font-weight: bold;">.</span>Set<span style="color: #000000;">&#40;</span>pPos<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span> pPos<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            bodyDef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">type</span> = b2Body<span style="color: #000066; font-weight: bold;">.</span>b2_dynamicBody<span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span>angularDamping = <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> bodyShape<span style="color: #000066; font-weight: bold;">:</span>b2CircleShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2CircleShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyShape<span style="color: #000066; font-weight: bold;">.</span>SetRadius <span style="color: #000000;">&#40;</span>p2m<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #6699cc; font-weight: bold;">var</span> bodyFixture<span style="color: #000066; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>shape = bodyShape<span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>density = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>restitution = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">bullet</span><span style="color: #000066; font-weight: bold;">:</span>b2Body = _world<span style="color: #000066; font-weight: bold;">.</span>CreateBody<span style="color: #000000;">&#40;</span>bodyDef<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #004993;">bullet</span><span style="color: #000066; font-weight: bold;">.</span>CreateFixture<span style="color: #000000;">&#40;</span>bodyFixture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #004993;">bullet</span><span style="color: #000066; font-weight: bold;">.</span>SetLinearVelocity<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,-</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
&nbsp;
            <span style="color: #009900; font-style: italic;">//create sprite3D  </span>
            <span style="color: #6699cc; font-weight: bold;">var</span> sphere <span style="color: #000066; font-weight: bold;">:</span> Sphere = <span style="color: #0033ff; font-weight: bold;">new</span> Sphere<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#123;</span>segmentsW<span style="color: #000066; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">4</span><span style="color: #000066; font-weight: bold;">,</span>segmentsH<span style="color: #000066; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">,</span> material<span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">new</span> WireColorMaterial<span style="color: #000000;">&#40;</span>0xFF3399<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000;">&#123;</span>wireColor<span style="color: #000066; font-weight: bold;">:</span>0x222222<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> radius<span style="color: #000066; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">10</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            sphere<span style="color: #000066; font-weight: bold;">.</span>z = <span style="color: #000000; font-weight:bold;">35</span><span style="color: #000066; font-weight: bold;">;</span>  
            sphere<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = m2p<span style="color: #000000;">&#40;</span>pPos<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            sphere<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = m2p<span style="color: #000000;">&#40;</span>pPos<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            _container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>sphere<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> bulletData<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bulletData<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">type</span> = <span style="color: #990000;">&quot;bullet&quot;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bulletData<span style="color: #000066; font-weight: bold;">.</span>hit = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>  
            bulletData<span style="color: #000066; font-weight: bold;">.</span>sphere = sphere<span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #004993;">bullet</span><span style="color: #000066; font-weight: bold;">.</span>SetUserData<span style="color: #000000;">&#40;</span>bulletData<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            b2bullets<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">bullet</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            shoot_timer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #000000;">&#125;</span>  
&nbsp;
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> p2m<span style="color: #000000;">&#40;</span>pixel<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> <span style="color: #000000;">&#123;</span>  
            <span style="color: #0033ff; font-weight: bold;">return</span> pixel<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">30</span><span style="color: #000066; font-weight: bold;">;</span>  
        <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> m2p<span style="color: #000000;">&#40;</span>m<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> <span style="color: #000000;">&#123;</span>  
            <span style="color: #0033ff; font-weight: bold;">return</span> m <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">30</span><span style="color: #000066; font-weight: bold;">;</span>  
        <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> updateBody <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>  
&nbsp;
&nbsp;
            _b2player<span style="color: #000066; font-weight: bold;">.</span>SetLinearVelocity<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>_moveLeft<span style="color: #000000;">&#41;</span> _b2player<span style="color: #000066; font-weight: bold;">.</span>SetAngle<span style="color: #000000;">&#40;</span> _b2player<span style="color: #000066; font-weight: bold;">.</span>GetAngle<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">0.05</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>_moveRight<span style="color: #000000;">&#41;</span> _b2player<span style="color: #000066; font-weight: bold;">.</span>SetAngle<span style="color: #000000;">&#40;</span> _b2player<span style="color: #000066; font-weight: bold;">.</span>GetAngle<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">0.05</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">angle</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = _b2player<span style="color: #000066; font-weight: bold;">.</span>GetAngle<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #6699cc; font-weight: bold;">var</span> playerVelocity<span style="color: #000066; font-weight: bold;">:</span>b2Vec2 = _b2player<span style="color: #000066; font-weight: bold;">.</span>GetLinearVelocity<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>_moveUp <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>  
                playerVelocity<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">-</span>= speed<span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
                playerVelocity<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">-</span>= speed<span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #000000;">&#125;</span>  
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>_moveDown <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>  
                playerVelocity<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span>= speed<span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
                playerVelocity<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">+</span>= speed<span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>    
            <span style="color: #000000;">&#125;</span>  
&nbsp;
        <span style="color: #000000;">&#125;</span>  
        <span style="color: #009900; font-style: italic;">///////////////////////////// EVENTS ///////////////////////////////////////  </span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onKey_Up <span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>  
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">keyCode</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>  
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">38</span><span style="color: #000066; font-weight: bold;">:</span>  
                    <span style="color: #009900; font-style: italic;">//UP KEY is up  </span>
                    _moveUp = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>  
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>  
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">39</span><span style="color: #000066; font-weight: bold;">:</span>  
                    <span style="color: #009900; font-style: italic;">//RIGHT KEY is up  </span>
                    _moveRight = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>  
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>  
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">37</span><span style="color: #000066; font-weight: bold;">:</span>  
                    <span style="color: #009900; font-style: italic;">//LEFT Key is up  </span>
                    _moveLeft = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>  
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>  
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">40</span><span style="color: #000066; font-weight: bold;">:</span>  
                    <span style="color: #009900; font-style: italic;">//DOWN KEY is up  </span>
                    _moveDown = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>  
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>  
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">32</span><span style="color: #000066; font-weight: bold;">:</span>  
                    <span style="color: #009900; font-style: italic;">//SPACE Bar is up  </span>
                    shoot<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #000000;">&#125;</span>  
        <span style="color: #000000;">&#125;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onKey_Down <span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>  
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">keyCode</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>  
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">38</span><span style="color: #000066; font-weight: bold;">:</span>  
                    <span style="color: #009900; font-style: italic;">//UP KEY is down  </span>
                    _moveUp = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>   
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>  
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">39</span><span style="color: #000066; font-weight: bold;">:</span>  
                    <span style="color: #009900; font-style: italic;">//RIGHT KEY is down  </span>
                    _moveRight = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>  
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">37</span><span style="color: #000066; font-weight: bold;">:</span>  
                    <span style="color: #009900; font-style: italic;">//LEFT Key is down  </span>
                    _moveLeft = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>  
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">40</span><span style="color: #000066; font-weight: bold;">:</span>  
                    <span style="color: #009900; font-style: italic;">//DOWN KEY is down  </span>
                    _moveDown = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>  
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>  
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">32</span><span style="color: #000066; font-weight: bold;">:</span>  
                    <span style="color: #009900; font-style: italic;">//SPACE BAR is down  </span>
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #000000;">&#125;</span>  
        <span style="color: #000000;">&#125;</span>  
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onLoop <span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>  
            updateBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            _world<span style="color: #000066; font-weight: bold;">.</span>Step<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">30</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            transformObject<span style="color: #000000;">&#40;</span>_b2player<span style="color: #000066; font-weight: bold;">,</span> _player<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            transformObject<span style="color: #000000;">&#40;</span>_b2block1<span style="color: #000066; font-weight: bold;">,</span> _block1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            transformObject<span style="color: #000000;">&#40;</span>_b2block2<span style="color: #000066; font-weight: bold;">,</span> _block2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>b2bullets<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> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = b2bullets<span style="color: #000066; font-weight: bold;">.</span>length<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&gt;</span>= <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">--</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>  
                    transformObject<span style="color: #000000;">&#40;</span>b2bullets<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> b2bullets<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>GetUserData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>sphere<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
                    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>b2bullets<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>GetUserData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>hit == <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>  
                        _container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span>b2bullets<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>GetUserData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>sphere<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
                        _world<span style="color: #000066; font-weight: bold;">.</span>DestroyBody<span style="color: #000000;">&#40;</span>b2bullets<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
                        b2bullets<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">splice</span><span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
                        <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>  
                    <span style="color: #000000;">&#125;</span>  
                <span style="color: #000000;">&#125;</span>  
            <span style="color: #000000;">&#125;</span>  
&nbsp;
            _view<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">render</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
        <span style="color: #000000;">&#125;</span>  
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> transformObject <span style="color: #000000;">&#40;</span>original<span style="color: #000066; font-weight: bold;">:</span>b2Body<span style="color: #000066; font-weight: bold;">,</span> threeD<span style="color: #000066; font-weight: bold;">:</span>Object3D<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>  
            <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">position</span><span style="color: #000066; font-weight: bold;">:</span>b2Vec2 = original<span style="color: #000066; font-weight: bold;">.</span>GetPosition<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">angle</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = original<span style="color: #000066; font-weight: bold;">.</span>GetAngle<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">180</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span> <span style="color: #000066; font-weight: bold;">;</span>  
&nbsp;
            threeD<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = Y_DIR<span style="color: #000066; font-weight: bold;">*</span>m2p<span style="color: #000000;">&#40;</span><span style="color: #004993;">position</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            threeD<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = Y_DIR<span style="color: #000066; font-weight: bold;">*</span>m2p<span style="color: #000000;">&#40;</span><span style="color: #004993;">position</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            threeD<span style="color: #000066; font-weight: bold;">.</span>rotationZ = <span style="color: #004993;">angle</span><span style="color: #000066; font-weight: bold;">;</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> createBoxDef <span style="color: #000000;">&#40;</span>rec<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>b2BodyDef <span style="color: #000000;">&#123;</span>  
            <span style="color: #6699cc; font-weight: bold;">var</span> bodyDef<span style="color: #000066; font-weight: bold;">:</span>b2BodyDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2BodyDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">position</span><span style="color: #000066; font-weight: bold;">.</span>Set<span style="color: #000000;">&#40;</span>p2m<span style="color: #000000;">&#40;</span>rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span> rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> p2m<span style="color: #000000;">&#40;</span>rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">+</span> rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">type</span> = b2Body<span style="color: #000066; font-weight: bold;">.</span>b2_staticBody<span style="color: #000066; font-weight: bold;">;</span>  
            bodyDef<span style="color: #000066; font-weight: bold;">.</span>angularDamping = <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #0033ff; font-weight: bold;">return</span> bodyDef<span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #000000;">&#125;</span>  
&nbsp;
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createBoxFixture <span style="color: #000000;">&#40;</span>rec<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>b2FixtureDef <span style="color: #000000;">&#123;</span>  
            <span style="color: #6699cc; font-weight: bold;">var</span> bodyShape<span style="color: #000066; font-weight: bold;">:</span>b2PolygonShape = <span style="color: #0033ff; font-weight: bold;">new</span> b2PolygonShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyShape<span style="color: #000066; font-weight: bold;">.</span>SetAsBox <span style="color: #000000;">&#40;</span>p2m<span style="color: #000000;">&#40;</span>rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> p2m<span style="color: #000000;">&#40;</span>rec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #6699cc; font-weight: bold;">var</span> bodyFixture<span style="color: #000066; font-weight: bold;">:</span>b2FixtureDef = <span style="color: #0033ff; font-weight: bold;">new</span> b2FixtureDef<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>shape = bodyShape<span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>density = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>  
            bodyFixture<span style="color: #000066; font-weight: bold;">.</span>restitution = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>  
            <span style="color: #0033ff; font-weight: bold;">return</span> bodyFixture<span style="color: #000066; font-weight: bold;">;</span>  
        <span style="color: #000000;">&#125;</span>         
&nbsp;
    <span style="color: #000000;">&#125;</span>  
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>And this is the result:</p>
<p><embed src="/wp-content/uploads/2011/03/Box3D.swf" allowscriptaccess="always" menu="false" quality="high" width="640" height="450" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>Use arrows to move, and space bar to shoot.</p>
<p>The code could be a lot cleaner and shorter if I&#8217;d used multiple classes, but I thought the example would be easier to understand if I used only one class.</p>
<p>One tip which I think is important would be to add some space between objects upon collision, in other words, make the collision area be slightly larger than the actual object. This will help with Z sorting. Sometimes in this example here, when you collide the player box with the blue boxes you can see the face segments get jagged and blink.</p>
<p>And the extra distance could be easily countered with a simple bump map in case it looks weird.</p>
<p>The problem of file size is however a big one. Box2D and Away3D are very heavy loads unfortunately. I&#8217;ll try to post the same code but with JigLib and see how that goes.</p>
<p>But I hope this helps with any ideas for 3D games you might have. I&#8217;ve seen race games using this engine, and third person shooters. They might seem very simple, but the number of fun games one could create with these simple ideas is amazing. And who says 3D has to be complicated!</p>
<p>Of course, uneven terrain in 3D can be a bitch&#8230;</p>
<p>Next I&#8217;ll do some line collision in 3D. &raquo;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2011/03/15/box2d-collisions-rendered-in-3d-with-away3d/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Flash 3D Sokoban Prototype with Alternativa3D &#8211; final version</title>
		<link>http://www.emanueleferonato.com/2011/03/02/flash-3d-sokoban-prototype-with-alternativa3d-final-version/</link>
		<comments>http://www.emanueleferonato.com/2011/03/02/flash-3d-sokoban-prototype-with-alternativa3d-final-version/#comments</comments>
		<pubDate>Tue, 01 Mar 2011 22:04:03 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3824</guid>
		<description><![CDATA[Flare3D and Away3D versions of the Sokoban prototype have been published. What&#8217;s now? Directly from InspiritGames we have an Alternativa3D port of the prototype. It&#8217;s a great porting, although it looks a bit &#8220;flat&#8221; because Alternativa3D does not support light. In the same blog you can find the Alternativa3D first prototype and even a version [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.emanueleferonato.com/2011/02/25/flash-3d-sokoban-prototype-with-flare3d-final-version/">Flare3D</a> and <a href="http://www.emanueleferonato.com/2011/02/28/flash-3d-sokoban-prototype-with-away3d-%E2%80%93-final-version/">Away3D</a> versions of the Sokoban prototype have been published. What&#8217;s now?</p>
<p>Directly from <strong><a href="http://inspiritgames.com/" target = "_blank">InspiritGames</a></strong> we have an <a href="http://inspiritgames.com/blog/2011/02/flash-3d-sokoban-prototype-with-alternativa3d-textured-version/" target = "_blank">Alternativa3D port of the prototype</a>.</p>
<p>It&#8217;s a great porting, although it looks a bit &#8220;flat&#8221; because Alternativa3D does not support light.</p>
<p>In the same blog you can find the Alternativa3D <a target = "_blank" href="http://inspiritgames.com/blog/2011/02/flash-3d-sokoban-prototype-with-alternativa3d/">first prototype</a> and even a <a href="http://inspiritgames.com/blog/2011/02/flash-3d-sokoban-with-alternativa3d-and-animated-character/" target = "_blank">version with a walking character</a>.</p>
<p>Here it is the source code:<span id="more-3824"></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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>Alternativa3D<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>containers<span style="color: #000066; font-weight: bold;">.*;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>controllers<span style="color: #000066; font-weight: bold;">.*;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>Camera3D<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>Clipping<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>Debug<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>MipMapping<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>MouseEvent3D<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>Object3D<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>Object3DContainer<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>Sorting<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>View<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>materials<span style="color: #000066; font-weight: bold;">.</span>FillMaterial<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>materials<span style="color: #000066; font-weight: bold;">.</span>TextureMaterial<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>objects<span style="color: #000066; font-weight: bold;">.</span>Sprite3D<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>primitives<span style="color: #000066; font-weight: bold;">.</span>Box<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>primitives<span style="color: #000066; font-weight: bold;">.</span>Plane<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> alternativa<span style="color: #000066; font-weight: bold;">.</span>engine3d<span style="color: #000066; font-weight: bold;">.</span>primitives<span style="color: #000066; font-weight: bold;">.</span>Sphere<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">BitmapData</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">BlendMode</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">StageAlign</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">StageQuality</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">StageScaleMode</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.filters</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">GlowFilter</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ColorTransform</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span><span style="color: #000066; font-weight: bold;">.</span>Vector3D<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> flash<span style="color: #000066; font-weight: bold;">.</span>sampler<span style="color: #000066; font-weight: bold;">.</span>NewObjectSample<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.system</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Capabilities</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.ui</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Keyboard</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #000000;">&#91;</span>SWF<span style="color: #000000;">&#40;</span><span style="color: #004993;">backgroundColor</span>=<span style="color: #990000;">&quot;#000000&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">frameRate</span>=<span style="color: #990000;">&quot;100&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;640&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;480&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> alternativa3dSokoban <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> const CUBESIZE<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #009900; font-style: italic;">//embeding textures images</span>
        <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;resource/crateTextureImg.jpg&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> static <span style="color: #0033ff; font-weight: bold;">private</span> const crateTextureImg<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Class</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;resource/floorTextureImg.png&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> static <span style="color: #0033ff; font-weight: bold;">private</span> const floorTextureImg<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Class</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;resource/crateTopTextureImg.jpg&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> static <span style="color: #0033ff; font-weight: bold;">private</span> const crateTopTextureImg<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Class</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;resource/crateTopGoalTextureImg.jpg&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> static <span style="color: #0033ff; font-weight: bold;">private</span> const crateTopGoalTextureImg<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Class</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;resource/wallTextureImg.png&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> static <span style="color: #0033ff; font-weight: bold;">private</span> const wallTextureImg<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Class</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;resource/goalTextureImg.jpg&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> static <span style="color: #0033ff; font-weight: bold;">private</span> const goalTextureImg<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Class</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;resource/playerTextureImg.jpg&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> static <span style="color: #0033ff; font-weight: bold;">private</span> const playerTextureImg<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Class</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;resource/backBitmapImg.jpg&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> static <span style="color: #0033ff; font-weight: bold;">private</span> const backTextureImg<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Class</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;resource/backBottomBitmapImg.jpg&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> static <span style="color: #0033ff; font-weight: bold;">private</span> const backBottomTextureImg<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Class</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
        <span style="color: #009900; font-style: italic;">// sokobal demo level and player position</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> levels<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span>=<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">4</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> playerCol<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> playerRow<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> playerRotation<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> playerAngle<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> playerMovement<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> dRow<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> dCol<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
        <span style="color: #009900; font-style: italic;">// alternativa3d  engine variables</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> camera<span style="color: #000066; font-weight: bold;">:</span>Camera3D<span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> controller<span style="color: #000066; font-weight: bold;">:</span>SimpleObjectController<span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> container<span style="color: #000066; font-weight: bold;">:</span>ConflictContainer<span style="color: #000066; font-weight: bold;">;</span>           
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">frame</span><span style="color: #000066; 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><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> player<span style="color: #000066; font-weight: bold;">:</span>Sphere<span style="color: #000066; font-weight: bold;">;</span><span style="color: #009900; font-style: italic;">// Sphere primitive representing the player</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> cplayer<span style="color: #000066; font-weight: bold;">:</span>SimpleObjectController<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//controller for player object</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> conplayer<span style="color: #000066; font-weight: bold;">:</span>Object3DContainer<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//container for player</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> movingCrate<span style="color: #000066; font-weight: bold;">:</span>Box<span style="color: #000066; font-weight: bold;">;</span><span style="color: #009900; font-style: italic;">// cube primitive representing the moving crate    </span>
&nbsp;
        <span style="color: #009900; font-style: italic;">// textures    </span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> crateTexture<span style="color: #000066; font-weight: bold;">:</span>TextureMaterial = <span style="color: #0033ff; font-weight: bold;">new</span> TextureMaterial<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> crateTextureImg<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bitmapData</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> floorTexture<span style="color: #000066; font-weight: bold;">:</span>TextureMaterial = <span style="color: #0033ff; font-weight: bold;">new</span> TextureMaterial<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> floorTextureImg<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bitmapData</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> crateTopTexture<span style="color: #000066; font-weight: bold;">:</span>TextureMaterial = <span style="color: #0033ff; font-weight: bold;">new</span> TextureMaterial<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> crateTopTextureImg<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bitmapData</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> crateTopGoalTexture<span style="color: #000066; font-weight: bold;">:</span>TextureMaterial = <span style="color: #0033ff; font-weight: bold;">new</span> TextureMaterial<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> crateTopGoalTextureImg<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bitmapData</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> wallTexture<span style="color: #000066; font-weight: bold;">:</span>TextureMaterial = <span style="color: #0033ff; font-weight: bold;">new</span> TextureMaterial<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> wallTextureImg<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bitmapData</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> goalTexture<span style="color: #000066; font-weight: bold;">:</span>TextureMaterial = <span style="color: #0033ff; font-weight: bold;">new</span> TextureMaterial<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> goalTextureImg<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bitmapData</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> playerTexture<span style="color: #000066; font-weight: bold;">:</span>TextureMaterial = <span style="color: #0033ff; font-weight: bold;">new</span> TextureMaterial<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> playerTextureImg<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bitmapData</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #009900; font-style: italic;">// SkyBox textures</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> backTexture<span style="color: #000066; font-weight: bold;">:</span>TextureMaterial = <span style="color: #0033ff; font-weight: bold;">new</span> TextureMaterial<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> backTextureImg<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bitmapData</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> backBottomTexture<span style="color: #000066; font-weight: bold;">:</span>TextureMaterial = <span style="color: #0033ff; font-weight: bold;">new</span> TextureMaterial<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> backBottomTextureImg<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bitmapData</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> alternativa3dSokoban<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>          
            <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">scaleMode</span> = <span style="color: #004993;">StageScaleMode</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NO_SCALE</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">align</span> = <span style="color: #004993;">StageAlign</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TOP_LEFT</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">quality</span> = <span style="color: #004993;">StageQuality</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">BEST</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
            <span style="color: #009900; font-style: italic;">// Camera</span>
            camera = <span style="color: #0033ff; font-weight: bold;">new</span> Camera3D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            camera<span style="color: #000066; font-weight: bold;">.</span>view = <span style="color: #0033ff; font-weight: bold;">new</span> View<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">640</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">480</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>camera<span style="color: #000066; font-weight: bold;">.</span>view<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
            <span style="color: #009900; font-style: italic;">// Camera controller</span>
            controller = <span style="color: #0033ff; font-weight: bold;">new</span> SimpleObjectController<span style="color: #000000;">&#40;</span><span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">,</span> camera<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
            <span style="color: #009900; font-style: italic;">// Root object</span>
            container = <span style="color: #0033ff; font-weight: bold;">new</span> ConflictContainer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            container<span style="color: #000066; font-weight: bold;">.</span>resolveByAABB = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
            container<span style="color: #000066; font-weight: bold;">.</span>resolveByOOBB = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
            <span style="color: #009900; font-style: italic;">//Player controller</span>
            conplayer = <span style="color: #0033ff; font-weight: bold;">new</span> Object3DContainer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            cplayer = <span style="color: #0033ff; font-weight: bold;">new</span> SimpleObjectController<span style="color: #000000;">&#40;</span><span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">,</span> player<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//i am not shure about SkyBox in Alternativa and will prepare it manually</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> backBottom<span style="color: #000066; font-weight: bold;">:</span>Plane = <span style="color: #0033ff; font-weight: bold;">new</span> Plane<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">*</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">*</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            backBottom<span style="color: #000066; font-weight: bold;">.</span>setMaterialToAllFaces<span style="color: #000000;">&#40;</span>backBottomTexture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            backBottom<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
            backBottom<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">*</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>
            backBottom<span style="color: #000066; font-weight: bold;">.</span>z = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
            backBottom<span style="color: #000066; font-weight: bold;">.</span>rotationX = <span style="color: #000000; font-weight:bold;">90</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000066; font-weight: bold;">;</span>
            container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>backBottom<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> backLeft<span style="color: #000066; font-weight: bold;">:</span>Plane = <span style="color: #0033ff; font-weight: bold;">new</span> Plane<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">*</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">*</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            backLeft<span style="color: #000066; font-weight: bold;">.</span>setMaterialToAllFaces<span style="color: #000000;">&#40;</span>backTexture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            backLeft<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
            backLeft<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
            backLeft<span style="color: #000066; font-weight: bold;">.</span>z = <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">*</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>
            container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>backLeft<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> backRight<span style="color: #000066; font-weight: bold;">:</span>Plane = <span style="color: #0033ff; font-weight: bold;">new</span> Plane<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">*</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">*</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            backRight<span style="color: #000066; font-weight: bold;">.</span>setMaterialToAllFaces<span style="color: #000000;">&#40;</span>backTexture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            backRight<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
            backRight<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
            backRight<span style="color: #000066; font-weight: bold;">.</span>z = <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">*</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>
            container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>backRight<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> backFront<span style="color: #000066; font-weight: bold;">:</span>Plane = <span style="color: #0033ff; font-weight: bold;">new</span> Plane<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">*</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">*</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            backFront<span style="color: #000066; font-weight: bold;">.</span>setMaterialToAllFaces<span style="color: #000000;">&#40;</span>backTexture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            backFront<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">*</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>
            backFront<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
            backFront<span style="color: #000066; font-weight: bold;">.</span>z = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
            backFront<span style="color: #000066; font-weight: bold;">.</span>rotationY = <span style="color: #000000; font-weight:bold;">90</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000066; font-weight: bold;">;</span>
            container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>backFront<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> backBack<span style="color: #000066; font-weight: bold;">:</span>Plane = <span style="color: #0033ff; font-weight: bold;">new</span> Plane<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">*</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">*</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            backBack<span style="color: #000066; font-weight: bold;">.</span>setMaterialToAllFaces<span style="color: #000000;">&#40;</span>backTexture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            backBack<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">*</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span>
            backBack<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
            backBack<span style="color: #000066; font-weight: bold;">.</span>z = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
            backBack<span style="color: #000066; font-weight: bold;">.</span>rotationY = <span style="color: #000000; font-weight:bold;">90</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000066; font-weight: bold;">;</span>
            container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>backBack<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">// end SkyBox</span>
&nbsp;
            <span style="color: #6699cc; font-weight: bold;">var</span> box<span style="color: #000066; font-weight: bold;">:</span>Box<span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #3f5fbf;">/*
            [[1,1,1,1,0,0,0,0],
             [1,0,0,1,1,1,1,1],
             [1,0,2,0,0,3,0,1],
             [1,0,3,0,0,2,4,1],
             [1,1,1,0,0,1,1,1],
             [0,0,1,1,1,1,0,0]];
            */</span>
            <span style="color: #009900; font-style: italic;">// level construction</span>
            <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">6</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> j<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">8</span><span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>levels<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                        <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000066; font-weight: bold;">:</span>
                            box = <span style="color: #0033ff; font-weight: bold;">new</span> Box<span style="color: #000000;">&#40;</span>CUBESIZE<span style="color: #000066; font-weight: bold;">,</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">,</span>CUBESIZE<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span>setMaterialToAllFaces<span style="color: #000000;">&#40;</span>floorTexture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = CUBESIZE<span style="color: #000066; font-weight: bold;">*</span>j<span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span>z = CUBESIZE<span style="color: #000066; font-weight: bold;">*</span>i<span style="color: #000066; font-weight: bold;">;</span>
                            container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>box<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                            <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000066; font-weight: bold;">:</span>
                            box = <span style="color: #0033ff; font-weight: bold;">new</span> Box<span style="color: #000000;">&#40;</span>CUBESIZE<span style="color: #000066; font-weight: bold;">,</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">,</span>CUBESIZE<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span>setMaterialToAllFaces<span style="color: #000000;">&#40;</span>floorTexture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = CUBESIZE<span style="color: #000066; font-weight: bold;">*</span>j<span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span>z = CUBESIZE<span style="color: #000066; font-weight: bold;">*</span>i<span style="color: #000066; font-weight: bold;">;</span>
                            container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>box<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
                            box = <span style="color: #0033ff; font-weight: bold;">new</span> Box<span style="color: #000000;">&#40;</span>CUBESIZE<span style="color: #000066; font-weight: bold;">,</span>CUBESIZE<span style="color: #000066; font-weight: bold;">,</span>CUBESIZE<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span>setMaterialToAllFaces<span style="color: #000000;">&#40;</span>wallTexture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = CUBESIZE<span style="color: #000066; font-weight: bold;">*</span>j<span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = CUBESIZE<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">4</span><span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span>z = CUBESIZE<span style="color: #000066; font-weight: bold;">*</span>i<span style="color: #000066; font-weight: bold;">;</span>
                            container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>box<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                            <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000066; font-weight: bold;">:</span>
                            box = <span style="color: #0033ff; font-weight: bold;">new</span> Box<span style="color: #000000;">&#40;</span>CUBESIZE<span style="color: #000066; font-weight: bold;">,</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">,</span>CUBESIZE<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span>setMaterialToAllFaces<span style="color: #000000;">&#40;</span>goalTexture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = CUBESIZE<span style="color: #000066; font-weight: bold;">*</span>j<span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span>z = CUBESIZE<span style="color: #000066; font-weight: bold;">*</span>i<span style="color: #000066; font-weight: bold;">;</span>
                            container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>box<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                            <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">3</span> <span style="color: #000066; font-weight: bold;">:</span>
                            box = <span style="color: #0033ff; font-weight: bold;">new</span> Box<span style="color: #000000;">&#40;</span>CUBESIZE<span style="color: #000066; font-weight: bold;">,</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">,</span>CUBESIZE<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span>setMaterialToAllFaces<span style="color: #000000;">&#40;</span>floorTexture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = CUBESIZE<span style="color: #000066; font-weight: bold;">*</span>j<span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span>z = CUBESIZE<span style="color: #000066; font-weight: bold;">*</span>i<span style="color: #000066; font-weight: bold;">;</span>
                            container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>box<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                            box = <span style="color: #0033ff; font-weight: bold;">new</span> Box<span style="color: #000000;">&#40;</span>CUBESIZE<span style="color: #000066; font-weight: bold;">,</span>CUBESIZE<span style="color: #000066; font-weight: bold;">,</span>CUBESIZE<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span> = <span style="color: #990000;">&quot;crate_&quot;</span><span style="color: #000066; font-weight: bold;">+</span>i<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;_&quot;</span><span style="color: #000066; font-weight: bold;">+</span>j<span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span>setMaterialToAllFaces<span style="color: #000000;">&#40;</span>crateTexture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = CUBESIZE<span style="color: #000066; font-weight: bold;">*</span>j<span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = CUBESIZE<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">4</span><span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span>z = CUBESIZE<span style="color: #000066; font-weight: bold;">*</span>i<span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span>rotationX <span style="color: #000066; font-weight: bold;">-</span>= <span style="color: #000000; font-weight:bold;">90</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000066; font-weight: bold;">;</span>
                            <span style="color: #009900; font-style: italic;">// top of the crate</span>
                            box<span style="color: #000066; font-weight: bold;">.</span>faces<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">4</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>material=crateTopTexture<span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span>faces<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">5</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>material=crateTopTexture<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
                            container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>box<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                            <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">4</span> <span style="color: #000066; font-weight: bold;">:</span>
                            box = <span style="color: #0033ff; font-weight: bold;">new</span> Box<span style="color: #000000;">&#40;</span>CUBESIZE<span style="color: #000066; font-weight: bold;">,</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">,</span>CUBESIZE<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span>setMaterialToAllFaces<span style="color: #000000;">&#40;</span>floorTexture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = CUBESIZE<span style="color: #000066; font-weight: bold;">*</span>j<span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
                            box<span style="color: #000066; font-weight: bold;">.</span>z = CUBESIZE<span style="color: #000066; font-weight: bold;">*</span>i<span style="color: #000066; font-weight: bold;">;</span>
                            container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>box<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
                            player = <span style="color: #0033ff; font-weight: bold;">new</span> Sphere<span style="color: #000000;">&#40;</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">16</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">16</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span>playerTexture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
                            conplayer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>player<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                            conplayer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">visible</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
                            conplayer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = CUBESIZE<span style="color: #000066; font-weight: bold;">*</span>j<span style="color: #000066; font-weight: bold;">;</span>
                            conplayer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = CUBESIZE<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">4</span><span style="color: #000066; font-weight: bold;">;</span>
                            conplayer<span style="color: #000066; font-weight: bold;">.</span>z = CUBESIZE<span style="color: #000066; font-weight: bold;">*</span>i<span style="color: #000066; font-weight: bold;">;</span>
                            conplayer<span style="color: #000066; font-weight: bold;">.</span>rotationX <span style="color: #000066; font-weight: bold;">-</span>= <span style="color: #000000; font-weight:bold;">90</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000066; font-weight: bold;">;</span>
                            container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>conplayer<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                            playerCol=j<span style="color: #000066; font-weight: bold;">;</span>
                            playerRow=i<span style="color: #000066; font-weight: bold;">;</span>
                            <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #000000;">&#125;</span>
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #009900; font-style: italic;">// Adding camera</span>
            container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>camera<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
            <span style="color: #009900; font-style: italic;">// View frame</span>
            <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">frame</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>                                               
            onResize<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>    
            <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER_FRAME</span><span style="color: #000066; font-weight: bold;">,</span> updateEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>        
            <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">KEY_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> onKeyDwn<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>      
            <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">RESIZE</span><span style="color: #000066; font-weight: bold;">,</span> onResize<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onKeyDwn<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">KeyboardEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>playerRotation==<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">&amp;&amp;</span>playerMovement==<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">keyCode</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #004993;">Keyboard</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">LEFT</span> <span style="color: #000066; font-weight: bold;">:</span>
                        playerRotation=<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">9</span><span style="color: #000066; font-weight: bold;">;</span>
                        playerAngle<span style="color: #000066; font-weight: bold;">+</span>=<span style="color: #000000; font-weight:bold;">90</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #004993;">Keyboard</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">RIGHT</span> <span style="color: #000066; font-weight: bold;">:</span>
                        playerRotation=<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">9</span><span style="color: #000066; font-weight: bold;">;</span>
                        playerAngle<span style="color: #000066; font-weight: bold;">-</span>=<span style="color: #000000; font-weight:bold;">90</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #004993;">Keyboard</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">UP</span> <span style="color: #000066; font-weight: bold;">:</span>
                        movingCrate=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
                        playerAngle=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">round</span><span style="color: #000000;">&#40;</span>conplayer<span style="color: #000066; font-weight: bold;">.</span>rotationY<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">%</span>360<span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>playerAngle<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>
                        <span style="color: #000000;">&#123;</span>
                            playerAngle<span style="color: #000066; font-weight: bold;">+</span>=<span style="color: #000000; font-weight:bold;">360</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #000000;">&#125;</span>
                        <span style="color: #009900; font-style: italic;">// we have to determine the difference between current row and column</span>
                        <span style="color: #009900; font-style: italic;">// and the new row and column according to player heading</span>
                        <span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>playerAngle<span style="color: #000000;">&#41;</span>
                        <span style="color: #000000;">&#123;</span>
                            <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000066; font-weight: bold;">:</span>
                                dRow=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
                                dCol=<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
                                <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
                            <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">90</span> <span style="color: #000066; font-weight: bold;">:</span>
                                <span style="color: #009900; font-style: italic;">//dRow=-1;</span>
                                dRow=<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
                                dCol=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
                                <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
                            <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">180</span> <span style="color: #000066; font-weight: bold;">:</span>
                                dRow=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
                                dCol=<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
                                <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
                            <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">270</span> <span style="color: #000066; font-weight: bold;">:</span>
                                <span style="color: #009900; font-style: italic;">//dRow=1;</span>
                                dRow=<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
                                dCol=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
                                <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #000000;">&#125;</span>
                        <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>levels<span style="color: #000000;">&#91;</span>playerRow<span style="color: #000066; font-weight: bold;">+</span>dRow<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>playerCol<span style="color: #000066; font-weight: bold;">+</span>dCol<span style="color: #000000;">&#93;</span>==<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">||</span>levels<span style="color: #000000;">&#91;</span>playerRow<span style="color: #000066; font-weight: bold;">+</span>dRow<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>playerCol<span style="color: #000066; font-weight: bold;">+</span>dCol<span style="color: #000000;">&#93;</span>==<span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>
                        <span style="color: #000000;">&#123;</span>
                            <span style="color: #009900; font-style: italic;">// the player can move</span>
                            playerMovement=<span style="color: #000066; font-weight: bold;">-</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #000000;">&#125;</span>
                        <span style="color: #0033ff; font-weight: bold;">else</span>
                        <span style="color: #000000;">&#123;</span>
                            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>levels<span style="color: #000000;">&#91;</span>playerRow<span style="color: #000066; font-weight: bold;">+</span>dRow<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>playerCol<span style="color: #000066; font-weight: bold;">+</span>dCol<span style="color: #000000;">&#93;</span>==<span style="color: #000000; font-weight:bold;">3</span><span style="color: #000066; font-weight: bold;">||</span>levels<span style="color: #000000;">&#91;</span>playerRow<span style="color: #000066; font-weight: bold;">+</span>dRow<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>playerCol<span style="color: #000066; font-weight: bold;">+</span>dCol<span style="color: #000000;">&#93;</span>==<span style="color: #000000; font-weight:bold;">5</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                                <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>levels<span style="color: #000000;">&#91;</span>playerRow<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">*</span>dRow<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>playerCol<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">*</span>dCol<span style="color: #000000;">&#93;</span>==<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">||</span>levels<span style="color: #000000;">&#91;</span>playerRow<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">*</span>dRow<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>playerCol<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">*</span>dCol<span style="color: #000000;">&#93;</span>==<span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                                    <span style="color: #009900; font-style: italic;">// the player can move and can push a crate</span>
                                    movingCrate=container<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;crate_&quot;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000;">&#40;</span>playerRow<span style="color: #000066; font-weight: bold;">+</span>dRow<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;_&quot;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000;">&#40;</span>playerCol<span style="color: #000066; font-weight: bold;">+</span>dCol<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #0033ff; font-weight: bold;">as</span> Box<span style="color: #000066; font-weight: bold;">;</span>
                                    playerMovement=<span style="color: #000066; font-weight: bold;">-</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span>
                                <span style="color: #000000;">&#125;</span>
                            <span style="color: #000000;">&#125;</span>
                        <span style="color: #000000;">&#125;</span>
                        <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> updateEvent<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
        <span style="color: #000000;">&#123;</span>      
                <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>playerRotation<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    conplayer<span style="color: #000066; font-weight: bold;">.</span>rotationY<span style="color: #000066; font-weight: bold;">+</span>=playerRotation<span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
                    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">abs</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">round</span><span style="color: #000000;">&#40;</span>conplayer<span style="color: #000066; font-weight: bold;">.</span>rotationY<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">%</span>90==<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                        playerRotation=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #000000;">&#125;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
                <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>playerMovement<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>                  
                    <span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>playerAngle<span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                    <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000066; font-weight: bold;">:</span>
                        conplayer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span>= playerMovement<span style="color: #000066; font-weight: bold;">;</span>
                        player<span style="color: #000066; font-weight: bold;">.</span>rotationY <span style="color: #000066; font-weight: bold;">-</span>= <span style="color: #000000; font-weight:bold;">18</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">90</span> <span style="color: #000066; font-weight: bold;">:</span>
                        conplayer<span style="color: #000066; font-weight: bold;">.</span>z <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #000066; font-weight: bold;">-</span>playerMovement<span style="color: #000066; font-weight: bold;">;</span>
                        player<span style="color: #000066; font-weight: bold;">.</span>rotationY <span style="color: #000066; font-weight: bold;">-</span>= <span style="color: #000000; font-weight:bold;">18</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">180</span> <span style="color: #000066; font-weight: bold;">:</span>
                        conplayer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #000066; font-weight: bold;">-</span>playerMovement<span style="color: #000066; font-weight: bold;">;</span>
                        player<span style="color: #000066; font-weight: bold;">.</span>rotationY <span style="color: #000066; font-weight: bold;">-</span>= <span style="color: #000000; font-weight:bold;">18</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">270</span> <span style="color: #000066; font-weight: bold;">:</span>
                        conplayer<span style="color: #000066; font-weight: bold;">.</span>z <span style="color: #000066; font-weight: bold;">+</span>= playerMovement<span style="color: #000066; font-weight: bold;">;</span>
                        player<span style="color: #000066; font-weight: bold;">.</span>rotationY <span style="color: #000066; font-weight: bold;">-</span>= <span style="color: #000000; font-weight:bold;">18</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">180</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #000000;">&#125;</span>
&nbsp;
                    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>movingCrate<span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                        <span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>playerAngle<span style="color: #000000;">&#41;</span>
                        <span style="color: #000000;">&#123;</span>
                            <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000066; font-weight: bold;">:</span>
                                movingCrate<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span>= playerMovement<span style="color: #000066; font-weight: bold;">;</span>
                                <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
                            <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">90</span> <span style="color: #000066; font-weight: bold;">:</span>
                                movingCrate<span style="color: #000066; font-weight: bold;">.</span>z <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #000066; font-weight: bold;">-</span>playerMovement<span style="color: #000066; font-weight: bold;">;</span>
                                <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
                            <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">180</span> <span style="color: #000066; font-weight: bold;">:</span>
                                movingCrate<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #000066; font-weight: bold;">-</span>playerMovement<span style="color: #000066; font-weight: bold;">;</span>
                                <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
                            <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #000000; font-weight:bold;">270</span> <span style="color: #000066; font-weight: bold;">:</span>
                                movingCrate<span style="color: #000066; font-weight: bold;">.</span>z <span style="color: #000066; font-weight: bold;">+</span>= playerMovement<span style="color: #000066; font-weight: bold;">;</span>
                                <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #000000;">&#125;</span>
                    <span style="color: #000000;">&#125;</span>
&nbsp;
                    <span style="color: #009900; font-style: italic;">// we need this to know if the player stopped on the destination tile</span>
                    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>playerAngle<span style="color: #000066; font-weight: bold;">%</span>180==<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">&amp;&amp;</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">round</span><span style="color: #000000;">&#40;</span>conplayer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">%</span>CUBESIZE==<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">||</span><span style="color: #000000;">&#40;</span>playerAngle<span style="color: #000066; font-weight: bold;">%</span>180<span style="color: #000066; font-weight: bold;">!</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">&amp;&amp;</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">round</span><span style="color: #000000;">&#40;</span>conplayer<span style="color: #000066; font-weight: bold;">.</span>z<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">%</span>CUBESIZE==<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                        playerMovement=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
                        levels<span style="color: #000000;">&#91;</span>playerRow<span style="color: #000066; font-weight: bold;">+</span>dRow<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>playerCol<span style="color: #000066; font-weight: bold;">+</span>dCol<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">+</span>=<span style="color: #000000; font-weight:bold;">4</span><span style="color: #000066; font-weight: bold;">;</span>
                        levels<span style="color: #000000;">&#91;</span>playerRow<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>playerCol<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">-</span>=<span style="color: #000000; font-weight:bold;">4</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>movingCrate<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                            levels<span style="color: #000000;">&#91;</span>playerRow<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">*</span>dRow<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>playerCol<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">*</span>dCol<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">+</span>=<span style="color: #000000; font-weight:bold;">3</span><span style="color: #000066; font-weight: bold;">;</span>
                            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>levels<span style="color: #000000;">&#91;</span>playerRow<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">*</span>dRow<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>playerCol<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">*</span>dCol<span style="color: #000000;">&#93;</span>==<span style="color: #000000; font-weight:bold;">5</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                                <span style="color: #009900; font-style: italic;">// changing materials on the fly</span>
                                movingCrate<span style="color: #000066; font-weight: bold;">.</span>setMaterialToAllFaces<span style="color: #000000;">&#40;</span>crateTexture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                                <span style="color: #009900; font-style: italic;">// top of the crate on goal</span>
                                movingCrate<span style="color: #000066; font-weight: bold;">.</span>faces<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">4</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>material=crateTopGoalTexture<span style="color: #000066; font-weight: bold;">;</span>
                                movingCrate<span style="color: #000066; font-weight: bold;">.</span>faces<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">5</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>material=crateTopGoalTexture<span style="color: #000066; font-weight: bold;">;</span>                             
&nbsp;
                            <span style="color: #000000;">&#125;</span>
                            <span style="color: #0033ff; font-weight: bold;">else</span>
                            <span style="color: #000000;">&#123;</span>
                                <span style="color: #009900; font-style: italic;">//movingCrate.setMaterialToAllFaces(crateMaterial);</span>
                                movingCrate<span style="color: #000066; font-weight: bold;">.</span>setMaterialToAllFaces<span style="color: #000000;">&#40;</span>crateTexture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                                <span style="color: #009900; font-style: italic;">// top of the crate</span>
                                movingCrate<span style="color: #000066; font-weight: bold;">.</span>faces<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">4</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>material=crateTopTexture<span style="color: #000066; font-weight: bold;">;</span>
                                movingCrate<span style="color: #000066; font-weight: bold;">.</span>faces<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">5</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>material=crateTopTexture<span style="color: #000066; font-weight: bold;">;</span>                             
                            <span style="color: #000000;">&#125;</span>
                            levels<span style="color: #000000;">&#91;</span>playerRow<span style="color: #000066; font-weight: bold;">+</span>dRow<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>playerCol<span style="color: #000066; font-weight: bold;">+</span>dCol<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">-</span>=<span style="color: #000000; font-weight:bold;">3</span><span style="color: #000066; font-weight: bold;">;</span>
                            movingCrate<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span>=<span style="color: #990000;">&quot;crate_&quot;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000;">&#40;</span>playerRow<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">*</span>dRow<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;_&quot;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000;">&#40;</span>playerCol<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">*</span>dCol<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #000000;">&#125;</span>
                        playerCol<span style="color: #000066; font-weight: bold;">+</span>=dCol<span style="color: #000066; font-weight: bold;">;</span>
                        playerRow<span style="color: #000066; font-weight: bold;">+</span>=dRow<span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #000000;">&#125;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
                onEnterFrame<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #000000;">&#125;</span>          
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> correct_camera_angles<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #009900; font-style: italic;">//set camera position</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> r<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">*</span>CUBESIZE<span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000066; font-weight: bold;">;</span>          
            <span style="color: #6699cc; font-weight: bold;">var</span> a<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000066; font-weight: bold;">-</span>conplayer<span style="color: #000066; font-weight: bold
