<?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; Flash</title>
	<atom:link href="http://www.emanueleferonato.com/category/flash/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>SamePhysics Flash game source code released</title>
		<link>http://www.emanueleferonato.com/2012/02/06/samephysics-flash-game-source-code-released/</link>
		<comments>http://www.emanueleferonato.com/2012/02/06/samephysics-flash-game-source-code-released/#comments</comments>
		<pubDate>Mon, 06 Feb 2012 14:28:18 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Monetize]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=5138</guid>
		<description><![CDATA[The source code of SamePhysics, my first Box2D game, is available for download]]></description>
			<content:encoded><![CDATA[<p>More than three years ago I released my first Box2D game called <strong><a href="http://www.emanueleferonato.com/2009/01/12/samephysics-my-first-box2d-game/">SamePhysics</a></strong>.</p>
<p><a href="http://www.emanueleferonato.com/2009/01/12/samephysics-my-first-box2d-game/"><img src="/wp-content/uploads/2012/02/same.jpg" /></a></p>
<p>It was an experiment to port the famous tile based game <a href="http://en.wikipedia.org/wiki/SameGame" target="_blank">SameGame</a> into a real-world physics environment, and despite it was nothing that a prototype with some bugs &#8211; especially with collision management &#8211; the game got some success, with about <strong>2.5 million views</strong> and two sponsorships by Rotten Tomato Games (now offline) and <a href="http://www.girlgames.com/" target="_blank">GirlGames</a>.</p>
<p>Now I am making a sequel of the game, more polished, fun and playable, and it&#8217;s time to release the source code of the good old SamePhysics.</p>
<p>You are warned: the code is &#8220;as is&#8221; and it&#8217;s not even the latest Box2D distribution, but I think it could be interesting to learn the basics of Box2D programming from a real world successful example.</p>
<p><a href="/wp-content/uploads/2012/02/samephysics.zip">Download the source code</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2012/02/06/samephysics-flash-game-source-code-released/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Making an in-game tutorial with StencylWorks</title>
		<link>http://www.emanueleferonato.com/2012/01/31/making-an-in-game-tutorial-with-stencylworks/</link>
		<comments>http://www.emanueleferonato.com/2012/01/31/making-an-in-game-tutorial-with-stencylworks/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 16:44:10 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[StencylWorks]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=5124</guid>
		<description><![CDATA[Learn how to make in-game tutorials with StencylWorks, making your player "read" the signs placed around a level]]></description>
			<content:encoded><![CDATA[<p>If you are playing the latest Flash games, you will see the old &#8220;how to play&#8221; button no longer exists.</p>
<p>People don&#8217;t want to read detailed instructions before playing a Flash game, they want to dig into action.</p>
<p>That&#8217;s why we have the need to create in-game tutorials, which are easy levels to make players get used to the game design while keeping them in action.</p>
<p>In my upcoming Flash game <strong>Kira the Witch</strong>, the tutorial is made of signs you can find around the levels. Once you touch a sign, you will be able to &#8220;read&#8221; it this way:</p>
<p><iframe width="640" height="480" src="http://www.youtube.com/embed/MZO0vG1W2aA" frameborder="0" allowfullscreen></iframe></p>
<p>I am going to show you how to do it in the painless way.</p>
<p>We have two actors: the small sign and the big sign. Small signs are placed in the scene during level design, while the big sign (one for all) will be created on the fly.</p>
<p>Also, the small sign is a sensor so it won&#8217;t react to physics and has its own collision group, called &#8220;sign&#8221;.</p>
<p>The big sign is a doodad, which means it&#8217;s a special actor never allowed to collide with anything else.</p>
<p>There is a big difference between a sensor and a doodad. The sensor does not react to physics forces but registers collisions, the doodad does not register collisions.</p>
<p>Now let&#8217;s create some behaviors: the first, and the easiest, is called &#8220;Big sign information&#8221; and does not contain any action, as you can see:</p>
<p><img src="/wp-content/uploads/2012/01/sign01.png" /></p>
<p>So it may seems useless, but I added to this behavior three not hidden attributes called &#8220;Text to display&#8221;, &#8220;Big sign x position&#8221; and &#8220;Big sign y position&#8221;.</p>
<p>When I customize the behavior of each small sign and add &#8220;Big sign information&#8221; behavior&#8230;</p>
<p><img src="/wp-content/uploads/2012/01/sign02.png" /></p>
<p>I can set the each sign content, and the x and y coordinates to be shown once Kira &#8220;reads&#8221; a sign. This way, &#8220;Big sign information&#8221; behavior acts like a new data type:</p>
<p><img src="/wp-content/uploads/2012/01/sign03.png" /></p>
<p>Also please notice I am using an asterisk as line break character since using &#8220;\n&#8221; won&#8217;t work at this stage.</p>
<p>Then, I need another behavior called &#8220;Write sign text&#8221; which will write text inside the big sign, so obvioulsy will be tied to it:</p>
<p><img src="/wp-content/uploads/2012/01/sign04.png" /></p>
<p>This is also very easy as I am only setting a font and writing some text in the sign. Notice how at this time I need to replace &#8220;*&#8221; with &#8220;\n&#8221; to do line breaks.</p>
<p>The difficult task to create the big sign, place it, and write text in it by changing &#8220;Text to write&#8221; attribute is (and then remove it) made by main player&#8217;s behavior called &#8220;Kira touches a sign&#8221;</p>
<p><img src="/wp-content/uploads/2012/01/sign05.png" /></p>
<p>I commented it to let you understand how it works.</p>
<p>Basically the key is the communication among different behaviors to get and set attributes on the fly.</p>
<p>And we can say &#8220;goodbye&#8221; to that old lame &#8220;How to play&#8221; buttons in a matter of minutes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2012/01/31/making-an-in-game-tutorial-with-stencylworks/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Play Slingy, my latest Flash game, on Hairy Games</title>
		<link>http://www.emanueleferonato.com/2012/01/27/play-slingy-my-latest-flash-game-on-hairy-games/</link>
		<comments>http://www.emanueleferonato.com/2012/01/27/play-slingy-my-latest-flash-game-on-hairy-games/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 15:48:07 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Monetize]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=5113</guid>
		<description><![CDATA[Play <a href="http://www.hairygames.com/play-slingy.html" target = "_blank">Slingy</a>, my latest physics Flash Game sponsored by <a href="http://www.hairygames.com/" target="_blank">Hairy Games</a>]]></description>
			<content:encoded><![CDATA[<p>I want you all to play <a href="http://www.hairygames.com/play-slingy.html" target="_blank">Slingy</a>, my latest Flash game, sponsored by <strong><a href="http://www.hairygames.com/" target="_blank">Hairy Games</a></strong>.</p>
<p><a href="http://www.hairygames.com/play-slingy.html" target = "_blank"><img src="/wp-content/uploads/2012/01/slingygame1.jpg" alt="" title="slingygame" width="640" height="480" class="alignnone size-full wp-image-5114" /></a></p>
<p>In this physics game you have to beat all 40 levels collecting as much orbs as you can, throwing the ball with a sling. To make your life harder, several kind of blocks to avoid or interact with.</p>
<p>You can find some information about the prototype in these posts:</p>
<p>* <a href="http://www.emanueleferonato.com/2007/09/01/controlling-a-ball-like-in-flash-elasticity-game-tutorial/">Controlling a ball like in Flash Elasticity game tutorial</a><br />
* <a href="http://www.emanueleferonato.com/2010/03/25/flash-elasticity-prototype-as3-version/">Flash Elasticity prototype – AS3 version</a><br />
* <a href="http://www.emanueleferonato.com/2007/12/18/when-elasticity-meets-bloons/">When Elasticity meets Bloons</a></p>
<p>The physics is powered by <a href="http://www.emanueleferonato.com/category/box2d/">Box2D</a>, while I used <a href="http://flintparticles.org/" target="_blank">Flint particle system</a> for the particles.</p>
<p>Talking about advertising, I used <a href="https://www.mochimedia.com/r/972ae333a3c92a2a" target="_blank">MochiMedia</a> for the in-game ads and <a href="http://www.flashgamelicense.com/" target="_blank">FlashGameLicense</a> to find a sponsorship.</p>
<p>I recommend Rick from <a href="http://www.hairygames.com/" target="_blank">Hairy Games</a>: he provides constructive feedback, helps you to make the game better and the branding process is easy.</p>
<p>I also used both <a href="http://www.playtomic.com/" target="_blank">Playtomic</a> and <a href="http://www.mochibot.com/" target="_blank">MochiBot</a> to track game statistics.</p>
<p><a target = "_blak" href="http://www.hairygames.com/play-slingy.html">Play ita</a>, rate it and give me feedback.</p>
<p>I will update you with some interesting new about the game once it&#8217;s in the wild for some time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2012/01/27/play-slingy-my-latest-flash-game-on-hairy-games/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>The concept behind Stringy Flash game: determine if a Sprite is inside a lasso</title>
		<link>http://www.emanueleferonato.com/2012/01/25/the-concept-behind-stringy-flash-game-determine-if-a-sprite-is-inside-a-lasso/</link>
		<comments>http://www.emanueleferonato.com/2012/01/25/the-concept-behind-stringy-flash-game-determine-if-a-sprite-is-inside-a-lasso/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 16:34:42 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=5105</guid>
		<description><![CDATA[Collect stuff drawing a lasso around it like in <a href = "http://www.kongregate.com/games/triqui/stringy?src=ref-x-dev-site-x-efblog" target = "_blank">Stringy Flash game</a>]]></description>
			<content:encoded><![CDATA[<p>Do you remember my Flash game called <a href="http://www.kongregate.com/games/triqui/stringy?src=ref-x-dev-site-x-efblog" target="_blank">Stringy</a>?</p>
<p>I blogged about it <a href="http://www.emanueleferonato.com/2011/12/16/play-stringy-my-latest-flash-game/">about a month ago</a> and some people asked me some hints about the way used to catch the stars drawing a lasso around it.</p>
<p>There are a lot of mathematical formulas to solve this task, and range from &#8220;more than complicate&#8221; to &#8220;you must be joking&#8221;.</p>
<p>I decided to post a prototype of the code I used starting from the post <a href="http://www.emanueleferonato.com/2011/10/13/develop-a-flash-game-like-string-avoider-as3-version-and-more/">Develop a Flash game like String Avoider – AS3 version – and more!</a>, without any comment, and it will be up to you to guess how I solved the problem in a ridiculously easy way.</p>
<p>This is what you will get:</p>
<p><embed src="/wp-content/uploads/2012/01/stringyconcept.swf" menu="false" quality="high" width="640" height="480" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>Catch the circle with a lasso to make it move in a random spot.</p>
<p>And this 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
</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;">Event</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Point</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main <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> tailLenght<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</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> tailNodes<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">300</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> tailCanvas<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> areaCanvas<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> targetCanvas<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> nodes<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>Point<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>Point<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>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Point</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span>tailNodes<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>
				nodes<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;">Point</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">mouseX</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">mouseY</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>areaCanvas<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>tailCanvas<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>targetCanvas<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			placeTarget<span style="color: #000000;">&#40;</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>update<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> placeTarget<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: #004993;">target</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</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;">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;">600</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">20</span><span style="color: #000066; font-weight: bold;">,</span><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;">440</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			targetCanvas<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;">clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			targetCanvas<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;">1</span><span style="color: #000066; font-weight: bold;">,</span>0xffffff<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			targetCanvas<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>0xffffff<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			targetCanvas<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: #004993;">target</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;">target</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;">5</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			targetCanvas<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: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> update<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: #6699cc; font-weight: bold;">var</span> sampleNodes<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>Point<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>Point<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>
			tailCanvas<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;">clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			tailCanvas<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;">3</span><span style="color: #000066; font-weight: bold;">,</span>0x00ff00<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			tailCanvas<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;">moveTo</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">mouseX</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">mouseY</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			areaCanvas<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;">clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			nodes<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">mouseX</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">mouseY</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			sampleNodes<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">mouseX</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">mouseY</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> i<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> i<span style="color: #000066; font-weight: bold;">&lt;</span>tailNodes<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;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> nodeAngle<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">atan2</span><span style="color: #000000;">&#40;</span>nodes<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>y<span style="color: #000066; font-weight: bold;">-</span>nodes<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: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span>nodes<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>x<span style="color: #000066; font-weight: bold;">-</span>nodes<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: #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>
				nodes<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;">Point</span><span style="color: #000000;">&#40;</span>nodes<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: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">+</span>tailLenght<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>nodeAngle<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span>nodes<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: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">+</span>tailLenght<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>nodeAngle<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				tailCanvas<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;">lineTo</span><span style="color: #000000;">&#40;</span>nodes<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>nodes<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: #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>i<span style="color: #000066; font-weight: bold;">%</span>10==<span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000066; font-weight: bold;">||</span> i==tailNodes<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					sampleNodes<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>nodes<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>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</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>sampleNodes<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;">++</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;">int</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> j<span style="color: #000066; font-weight: bold;">&lt;</span>sampleNodes<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> j<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #6699cc; font-weight: bold;">var</span> p<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Point</span>=lineIntersection<span style="color: #000000;">&#40;</span>sampleNodes<span style="color: #000000;">&#91;</span>j<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>sampleNodes<span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span>sampleNodes<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: #000066; font-weight: bold;">,</span>sampleNodes<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>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>p<span style="color: #000066; font-weight: bold;">!</span>=<span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000066; font-weight: bold;">&amp;&amp;</span> <span style="color: #000066; font-weight: bold;">!</span><span style="color: #004993;">isNaN</span><span style="color: #000000;">&#40;</span>p<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</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>
						areaCanvas<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>0xff0000<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>
						areaCanvas<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;">moveTo</span><span style="color: #000000;">&#40;</span>p<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>p<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;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> k<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</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> k<span style="color: #000066; font-weight: bold;">&lt;</span>=j<span style="color: #000066; font-weight: bold;">;</span> k<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							areaCanvas<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;">lineTo</span><span style="color: #000000;">&#40;</span>sampleNodes<span style="color: #000000;">&#91;</span>k<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>sampleNodes<span style="color: #000000;">&#91;</span>k<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: #000000;">&#125;</span>
						areaCanvas<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: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>areaCanvas<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">hitTestPoint</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">target</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;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				placeTarget<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> lineIntersection<span style="color: #000000;">&#40;</span>p1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Point</span><span style="color: #000066; font-weight: bold;">,</span>p2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Point</span><span style="color: #000066; font-weight: bold;">,</span>p3<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Point</span><span style="color: #000066; font-weight: bold;">,</span>p4<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Point</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Point</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> x1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=p1<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: #6699cc; font-weight: bold;">var</span> x2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=p2<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: #6699cc; font-weight: bold;">var</span> x3<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=p3<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: #6699cc; font-weight: bold;">var</span> x4<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=p4<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: #6699cc; font-weight: bold;">var</span> y1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=p1<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: #6699cc; font-weight: bold;">var</span> y2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=p2<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: #6699cc; font-weight: bold;">var</span> y3<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=p3<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: #6699cc; font-weight: bold;">var</span> y4<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=p4<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: #6699cc; font-weight: bold;">var</span> px<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</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><span style="color: #000000;">&#40;</span>x1<span style="color: #000066; font-weight: bold;">*</span>y2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">-</span>y1<span style="color: #000066; font-weight: bold;">*</span>x2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000;">&#40;</span>x3<span style="color: #000066; font-weight: bold;">-</span>x4<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000;">&#40;</span>x1<span style="color: #000066; font-weight: bold;">-</span>x2<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>x3<span style="color: #000066; font-weight: bold;">*</span>y4<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">-</span>y3<span style="color: #000066; font-weight: bold;">*</span>x4<span style="color: #000000;">&#41;</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>x2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000;">&#40;</span>y3<span style="color: #000066; font-weight: bold;">-</span>y4<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000;">&#40;</span>y1<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: #000000;">&#40;</span>x3<span style="color: #000066; font-weight: bold;">-</span>x4<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>
			<span style="color: #6699cc; font-weight: bold;">var</span> py<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</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><span style="color: #000000;">&#40;</span>x1<span style="color: #000066; font-weight: bold;">*</span>y2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">-</span>y1<span style="color: #000066; font-weight: bold;">*</span>x2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000;">&#40;</span>y3<span style="color: #000066; font-weight: bold;">-</span>y4<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000;">&#40;</span>y1<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: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>x3<span style="color: #000066; font-weight: bold;">*</span>y4<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">-</span>y3<span style="color: #000066; font-weight: bold;">*</span>x4<span style="color: #000000;">&#41;</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>x2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000;">&#40;</span>y3<span style="color: #000066; font-weight: bold;">-</span>y4<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000;">&#40;</span>y1<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: #000000;">&#40;</span>x3<span style="color: #000066; font-weight: bold;">-</span>x4<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>
			<span style="color: #6699cc; font-weight: bold;">var</span> segment1Len<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">pow</span><span style="color: #000000;">&#40;</span>p1<span style="color: #000066; font-weight: bold;">.</span>x<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><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;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">pow</span><span style="color: #000000;">&#40;</span>p1<span style="color: #000066; font-weight: bold;">.</span>y<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><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: #6699cc; font-weight: bold;">var</span> segment2Len<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">pow</span><span style="color: #000000;">&#40;</span>p3<span style="color: #000066; font-weight: bold;">.</span>x<span style="color: #000066; font-weight: bold;">-</span>p4<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;">2</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;">pow</span><span style="color: #000000;">&#40;</span>p3<span style="color: #000066; font-weight: bold;">.</span>y<span style="color: #000066; font-weight: bold;">-</span>p4<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;">2</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: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">pow</span><span style="color: #000000;">&#40;</span>p1<span style="color: #000066; font-weight: bold;">.</span>x<span style="color: #000066; font-weight: bold;">-</span>px<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;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">pow</span><span style="color: #000000;">&#40;</span>p1<span style="color: #000066; font-weight: bold;">.</span>y<span style="color: #000066; font-weight: bold;">-</span>py<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;">&gt;</span>segment1Len<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;">null</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;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">pow</span><span style="color: #000000;">&#40;</span>p2<span style="color: #000066; font-weight: bold;">.</span>x<span style="color: #000066; font-weight: bold;">-</span>px<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;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">pow</span><span style="color: #000000;">&#40;</span>p2<span style="color: #000066; font-weight: bold;">.</span>y<span style="color: #000066; font-weight: bold;">-</span>py<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;">&gt;</span>segment1Len<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;">null</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;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">pow</span><span style="color: #000000;">&#40;</span>p3<span style="color: #000066; font-weight: bold;">.</span>x<span style="color: #000066; font-weight: bold;">-</span>px<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;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">pow</span><span style="color: #000000;">&#40;</span>p3<span style="color: #000066; font-weight: bold;">.</span>y<span style="color: #000066; font-weight: bold;">-</span>py<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;">&gt;</span>segment2Len<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;">null</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;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">pow</span><span style="color: #000000;">&#40;</span>p4<span style="color: #000066; font-weight: bold;">.</span>x<span style="color: #000066; font-weight: bold;">-</span>px<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;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">pow</span><span style="color: #000000;">&#40;</span>p4<span style="color: #000066; font-weight: bold;">.</span>y<span style="color: #000066; font-weight: bold;">-</span>py<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;">&gt;</span>segment2Len<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;">null</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><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>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>No need to download anything, you can replace the code contained in the <a href="http://www.emanueleferonato.com/2011/10/13/develop-a-flash-game-like-string-avoider-as3-version-and-more/">original prototype</a> with this one.</p>
<p>Did you figure out how I made it possible with no formulas?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2012/01/25/the-concept-behind-stringy-flash-game-determine-if-a-sprite-is-inside-a-lasso/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Make the player die after a long fall with StencylWorks</title>
		<link>http://www.emanueleferonato.com/2012/01/23/make-the-player-die-after-a-long-fall-with-stencylworks/</link>
		<comments>http://www.emanueleferonato.com/2012/01/23/make-the-player-die-after-a-long-fall-with-stencylworks/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 10:01:25 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[StencylWorks]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=5089</guid>
		<description><![CDATA[Learn how to make a StencylWorks platform game featuring death for falling from high places]]></description>
			<content:encoded><![CDATA[<p>I already showed you how easy is to <a href="http://www.emanueleferonato.com/2011/12/05/create-awesome-flash-games-in-no-time-with-stencylworks-adding-intro-jumping-and-more/">create a platform game with StencylWorks</a> and even how to include a <a href="http://www.emanueleferonato.com/2012/01/10/develop-double-jump-behavior-in-stencylworks/">double jump</a> feature.</p>
<p>Anyway, in some platform games you need to make the player die if falling from high places.</p>
<p>Try to play this prototype:</p>
<p><embed src="/wp-content/uploads/2012/01/deadly.swf" menu="false" quality="high" width="640" height="480" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>You can play with ARROW keys, and perform double jumps.</p>
<p>If you fall down the left cliff, you will die (actually, you turn gray for couple of seconds &#8211; that&#8217;s how I show you would have died).</p>
<p>If you fall down the right cliff, you won&#8217;t die.</p>
<p>If you jump from the right cliff and fall down, you will die.</p>
<p>This happens because there&#8217;s a maximum falling height. If you&#8217;re falling for more than such height, you will die.</p>
<p>To make this kind of behavior, first we need some attributes:</p>
<p><img src="/wp-content/uploads/2012/01/deadly03.jpg" /></p>
<p><strong>is falling</strong> is a Boolean variable to determine whether the player is falling or not</p>
<p><strong>falling start</strong> is the y coordinate in pixels of the player when it begins to fall</p>
<p><strong>deadly height</strong> is the height, in pixels, of the deadly height. Also notice this attribute is not hidden so it can be set when the behavior is added to the player:</p>
<p><img src="/wp-content/uploads/2012/01/deadly01.jpg" /></p>
<p>Then, this is the behavior:</p>
<p><img src="/wp-content/uploads/2012/01/deadly02.jpg" /></p>
<p>As you can see it&#8217;s just a matter of checking if player&#8217;s y speed is greater than zero (the player is moving down, so it&#8217;s falling), and once it hits the ground again, calculating for how long it kept on falling.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2012/01/23/make-the-player-die-after-a-long-fall-with-stencylworks/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Create REAL explosions with Box2D &#8211; adding textures</title>
		<link>http://www.emanueleferonato.com/2012/01/17/create-real-explosions-with-box2d-adding-textures/</link>
		<comments>http://www.emanueleferonato.com/2012/01/17/create-real-explosions-with-box2d-adding-textures/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 14:45:46 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=5079</guid>
		<description><![CDATA[Real Box2D explosions, now with textures. The final step.]]></description>
			<content:encoded><![CDATA[<p>Ok, you asked it, now you have it. Now the Box2D explosion prototype features bitmap textures and a commented source code.</p>
<p>I have to say a big thank you to <strong>Antoan Angelov</strong> for his version of the <a href="http://www.emanueleferonato.com/2011/08/05/slicing-splitting-and-cutting-objects-with-box2d-part-4-using-real-graphics/">slicing engine</a> as he allowed me to manage textures with no hassle.</p>
<p>So now basically an explosion is a number of cuts at a random angle, all passing for the same point, which is the origin of the explosion. Then, every resulting slice will have a linear velocity according to the distance between the center of the slice mass and the origin of the explosion.</p>
<p>So this is what you&#8217;ll get:</p>
<p><embed src="/wp-content/uploads/2012/01/main.swf" menu="false" quality="high" width="640" height="480" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>Click on a crate to make it explode.</p>
<p>And this is the full, commented source code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
</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;">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;">MouseEvent</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;">Matrix</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;">BitmapData</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>
	<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>
	<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>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;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main <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> world<span style="color: #000066; font-weight: bold;">:</span>b2World=<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;">10</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: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> enterPointsVec<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: #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> numEnterPoints<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: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> worldScale<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: #000066; font-weight: bold;">;</span>
		<span style="color: #009900; font-style: italic;">// variables used in the explosion process:</span>
		<span style="color: #009900; font-style: italic;">// the vector of exploding bodies</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> explodingBodies<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>
		<span style="color: #009900; font-style: italic;">// the number of cuts for every explosion</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> explosionCuts<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>
		<span style="color: #009900; font-style: italic;">// explosion x and y center</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> explosionX<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> explosionY<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: #009900; font-style: italic;">// explosion radius, useful to determine the velocity of debris</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> explosionRadius<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Main<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;">// calling the debug draw. This is used to show you the bitmaps are correctly applied,</span>
			<span style="color: #009900; font-style: italic;">// and because I did not want to draw the walls :)</span>
			debugDraw<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;">// this is the BitmapData representation of my 100x100 pixels crate image</span>
			<span style="color: #009900; font-style: italic;">// check the library to see both the raw image and CrateImage Sprite</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> crateBitmap<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">BitmapData</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">BitmapData</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			crateBitmap<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> CrateImage<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: #009900; font-style: italic;">// adding the four static, undestroyable walls</span>
			addWall<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">320</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">480</span><span style="color: #000066; font-weight: bold;">,</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;">20</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			addWall<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">320</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</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;">20</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			addWall<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;">240</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">20</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">480</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			addWall<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;">240</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">20</span><span style="color: #000066; font-weight: bold;">,</span><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: #009900; font-style: italic;">// this vector stores the clockwise local coordinates of the 100x100 pixels crate</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> crateCoordVector<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> <span style="color: #000066; font-weight: bold;">&lt;</span>b2Vec2<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000;">&#91;</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;">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;">new</span> b2Vec2<span style="color: #000000;">&#40;</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;">new</span> b2Vec2<span style="color: #000000;">&#40;</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;">new</span> b2Vec2<span style="color: #000000;">&#40;</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: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// then createBody builds the final body and applies the bitmap.</span>
			<span style="color: #009900; font-style: italic;">// the first two arguments are the X and Y position of the center of the crate, in pixels</span>
			createBody<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">95</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">420</span><span style="color: #000066; font-weight: bold;">,</span>crateCoordVector<span style="color: #000066; font-weight: bold;">,</span>crateBitmap<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			createBody<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">245</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">420</span><span style="color: #000066; font-weight: bold;">,</span>crateCoordVector<span style="color: #000066; font-weight: bold;">,</span>crateBitmap<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			createBody<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">395</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">420</span><span style="color: #000066; font-weight: bold;">,</span>crateCoordVector<span style="color: #000066; font-weight: bold;">,</span>crateBitmap<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			createBody<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">545</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">420</span><span style="color: #000066; font-weight: bold;">,</span>crateCoordVector<span style="color: #000066; font-weight: bold;">,</span>crateBitmap<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			createBody<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">170</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">320</span><span style="color: #000066; font-weight: bold;">,</span>crateCoordVector<span style="color: #000066; font-weight: bold;">,</span>crateBitmap<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			createBody<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">320</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">320</span><span style="color: #000066; font-weight: bold;">,</span>crateCoordVector<span style="color: #000066; font-weight: bold;">,</span>crateBitmap<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			createBody<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">470</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">320</span><span style="color: #000066; font-weight: bold;">,</span>crateCoordVector<span style="color: #000066; font-weight: bold;">,</span>crateBitmap<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			createBody<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">245</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">220</span><span style="color: #000066; font-weight: bold;">,</span>crateCoordVector<span style="color: #000066; font-weight: bold;">,</span>crateBitmap<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			createBody<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">395</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">220</span><span style="color: #000066; font-weight: bold;">,</span>crateCoordVector<span style="color: #000066; font-weight: bold;">,</span>crateBitmap<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			createBody<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">320</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">120</span><span style="color: #000066; font-weight: bold;">,</span>crateCoordVector<span style="color: #000066; font-weight: bold;">,</span>crateBitmap<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// You can see the reason for creating the enterPointsVec in the coments in the intersection() method.</span>
			enterPointsVec=<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: #000000;">&#40;</span>numEnterPoints<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// listeners</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;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> boom<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> update<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;">// my old friend debugDraw function</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> debugDraw<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: #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> debugSprite<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>debugSprite<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>debugSprite<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>worldScale<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>
			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>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #009900; font-style: italic;">// this function returns the body at a X,Y coordinate without using a temp body like the one in</span>
		<span style="color: #009900; font-style: italic;">// the original Box2D distribution. It uses QueryPoint method.</span>
		<span style="color: #009900; font-style: italic;">// returns the body ad X,Y coordinate or null</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> GetBodyAtXY<span style="color: #000000;">&#40;</span>coordinate<span style="color: #000066; font-weight: bold;">:</span>b2Vec2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>b2Body <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> touchedBody<span style="color: #000066; font-weight: bold;">:</span>b2Body=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
			world<span style="color: #000066; font-weight: bold;">.</span>QueryPoint<span style="color: #000000;">&#40;</span>GetBodyCallback<span style="color: #000066; font-weight: bold;">,</span>coordinate<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #339966; font-weight: bold;">function</span> GetBodyCallback<span style="color: #000000;">&#40;</span>fixture<span style="color: #000066; font-weight: bold;">:</span>b2Fixture<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> shape<span style="color: #000066; font-weight: bold;">:</span>b2Shape=fixture<span style="color: #000066; font-weight: bold;">.</span>GetShape<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> inside<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=shape<span style="color: #000066; font-weight: bold;">.</span>TestPoint<span style="color: #000000;">&#40;</span>fixture<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>GetTransform<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span>coordinate<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>inside<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					touchedBody=fixture<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>
					<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: #0033ff; font-weight: bold;">return</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: #0033ff; font-weight: bold;">return</span> touchedBody<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #009900; font-style: italic;">// simple function to add a static wall</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> addWall<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>w<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>h<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: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> wallShape<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>
			wallShape<span style="color: #000066; font-weight: bold;">.</span>SetAsBox<span style="color: #000000;">&#40;</span>w<span style="color: #000066; font-weight: bold;">/</span>worldScale<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>h<span style="color: #000066; font-weight: bold;">/</span>worldScale<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: #6699cc; font-weight: bold;">var</span> wallFixture<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>
			wallFixture<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>
			wallFixture<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>
			wallFixture<span style="color: #000066; font-weight: bold;">.</span>restitution=<span style="color: #000000; font-weight:bold;">0.5</span><span style="color: #000066; font-weight: bold;">;</span>
			wallFixture<span style="color: #000066; font-weight: bold;">.</span>shape=wallShape<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> wallBodyDef<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>
			wallBodyDef<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>pX<span style="color: #000066; font-weight: bold;">/</span>worldScale<span style="color: #000066; font-weight: bold;">,</span>pY<span style="color: #000066; font-weight: bold;">/</span>worldScale<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> wall<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>wallBodyDef<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			wall<span style="color: #000066; font-weight: bold;">.</span>CreateFixture<span style="color: #000000;">&#40;</span>wallFixture<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			numEnterPoints<span style="color: #000066; font-weight: bold;">++;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #009900; font-style: italic;">// function to create and texture a dynamic body</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createBody<span style="color: #000000;">&#40;</span>xPos<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span> yPos<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span> verticesArr<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> texture<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">BitmapData</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #009900; font-style: italic;">// I need this temp vector to convert pixels coordinates to Box2D meters coordinates</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: #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> i<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> i<span style="color: #000066; font-weight: bold;">&lt;</span>verticesArr<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>
				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>verticesArr<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>worldScale<span style="color: #000066; font-weight: bold;">,</span>verticesArr<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>worldScale<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: #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;">type</span>=b2Body<span style="color: #000066; font-weight: bold;">.</span>b2_dynamicBody<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> boxDef<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>
			boxDef<span style="color: #000066; font-weight: bold;">.</span>SetAsVector<span style="color: #000000;">&#40;</span>vec<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>xPos<span style="color: #000066; font-weight: bold;">/</span>worldScale<span style="color: #000066; font-weight: bold;">,</span> yPos<span style="color: #000066; font-weight: bold;">/</span>worldScale<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// custom userData used to map the texture</span>
			bodyDef<span style="color: #000066; font-weight: bold;">.</span>userData=<span style="color: #0033ff; font-weight: bold;">new</span> userData<span style="color: #000000;">&#40;</span>numEnterPoints<span style="color: #000066; font-weight: bold;">,</span>vec<span style="color: #000066; font-weight: bold;">,</span>texture<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>bodyDef<span style="color: #000066; font-weight: bold;">.</span>userData<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> fixtureDef<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>
			fixtureDef<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>
			fixtureDef<span style="color: #000066; font-weight: bold;">.</span>friction=<span style="color: #000000; font-weight:bold;">0.2</span><span style="color: #000066; font-weight: bold;">;</span>
			fixtureDef<span style="color: #000066; font-weight: bold;">.</span>restitution=<span style="color: #000000; font-weight:bold;">0.5</span><span style="color: #000066; font-weight: bold;">;</span>
			fixtureDef<span style="color: #000066; font-weight: bold;">.</span>shape=boxDef<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> tempBox<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>
			tempBox<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>
			numEnterPoints<span style="color: #000066; font-weight: bold;">++;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #009900; font-style: italic;">// function to create an explosion</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> boom<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: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> cutAngle<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">;</span>
			explosionX=<span style="color: #004993;">mouseX</span><span style="color: #000066; font-weight: bold;">;</span>
			explosionY=<span style="color: #004993;">mouseY</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// I am looking for a body under my mouse</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> clickedBody<span style="color: #000066; font-weight: bold;">:</span>b2Body=GetBodyAtXY<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span>explosionX<span style="color: #000066; font-weight: bold;">/</span>worldScale<span style="color: #000066; font-weight: bold;">,</span>explosionY<span style="color: #000066; font-weight: bold;">/</span>worldScale<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;">if</span> <span style="color: #000000;">&#40;</span>clickedBody<span style="color: #000066; font-weight: bold;">!</span>=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #009900; font-style: italic;">// storing the exploding bodies in a vector. I need to do it since I do not want other bodies</span>
				<span style="color: #009900; font-style: italic;">// to be affected by the raycast and explode</span>
				explodingBodies=<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>
				explodingBodies<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>clickedBody<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #009900; font-style: italic;">// the explosion begins!</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;">Number</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;">&lt;</span>=explosionCuts<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;">// choosing a random angle</span>
					cutAngle=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">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: #009900; font-style: italic;">// creating the two points to be used for the raycast, according to the random angle and mouse position</span>
					<span style="color: #009900; font-style: italic;">// also notice how I need to add a little offset (i/10) or Box2D will crash. Probably it's not able to </span>
					<span style="color: #009900; font-style: italic;">// determine raycast on objects whose area is very very close to zero (or zero)</span>
					<span style="color: #6699cc; font-weight: bold;">var</span> p1<span style="color: #000066; font-weight: bold;">:</span>b2Vec2=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>explosionX<span style="color: #000066; font-weight: bold;">+</span>i<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;">2000</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>cutAngle<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">/</span>worldScale<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000;">&#40;</span>explosionY<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">2000</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>cutAngle<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">/</span>worldScale<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #6699cc; font-weight: bold;">var</span> p2<span style="color: #000066; font-weight: bold;">:</span>b2Vec2=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>explosionX<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">2000</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>cutAngle<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">/</span>worldScale<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000;">&#40;</span>explosionY<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">2000</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>cutAngle<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">/</span>worldScale<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					world<span style="color: #000066; font-weight: bold;">.</span>RayCast<span style="color: #000000;">&#40;</span><span style="color: #004993;">intersection</span><span style="color: #000066; font-weight: bold;">,</span> p1<span style="color: #000066; font-weight: bold;">,</span> p2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					world<span style="color: #000066; font-weight: bold;">.</span>RayCast<span style="color: #000000;">&#40;</span><span style="color: #004993;">intersection</span><span style="color: #000066; font-weight: bold;">,</span> p2<span style="color: #000066; font-weight: bold;">,</span> p1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					enterPointsVec=<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: #000000;">&#40;</span>numEnterPoints<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: #009900; font-style: italic;">// update function to simulate and render the world</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> update<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>
			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>ClearForces<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> spr<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;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">:</span>b2Body = world<span style="color: #000066; font-weight: bold;">.</span>GetBodyList<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #004993;">b</span> = <span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span>GetNext<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				spr=<span style="color: #004993;">b</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: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>spr<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					spr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span>=<span style="color: #004993;">b</span><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: #004993;">x</span><span style="color: #000066; font-weight: bold;">*</span>worldScale<span style="color: #000066; font-weight: bold;">;</span>
					spr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span>=<span style="color: #004993;">b</span><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: #004993;">y</span><span style="color: #000066; font-weight: bold;">*</span>worldScale<span style="color: #000066; font-weight: bold;">;</span>
					spr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">rotation</span>=<span style="color: #004993;">b</span><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>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</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>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">intersection</span><span style="color: #000000;">&#40;</span>fixture<span style="color: #000066; font-weight: bold;">:</span>b2Fixture<span style="color: #000066; font-weight: bold;">,</span> point<span style="color: #000066; font-weight: bold;">:</span>b2Vec2<span style="color: #000066; font-weight: bold;">,</span> normal<span style="color: #000066; font-weight: bold;">:</span>b2Vec2<span style="color: #000066; font-weight: bold;">,</span> fraction<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;">if</span> <span style="color: #000000;">&#40;</span>explodingBodies<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span>fixture<span style="color: #000066; font-weight: bold;">.</span>GetBody<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: #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: #6699cc; font-weight: bold;">var</span> spr<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span>=fixture<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: #009900; font-style: italic;">// Throughout this whole code I use only one global vector, and that is enterPointsVec. Why do I need it you ask? </span>
				<span style="color: #009900; font-style: italic;">// Well, the problem is that the world.RayCast() method calls this function only when it sees that a given line gets into the body - it doesnt see when the line gets out of it.</span>
				<span style="color: #009900; font-style: italic;">// I must have 2 intersection points with a body so that it can be sliced, thats why I use world.RayCast() again, but this time from B to A - that way the point, at which BA enters the body is the point at which AB leaves it!</span>
				<span style="color: #009900; font-style: italic;">// For that reason, I use a vector enterPointsVec, where I store the points, at which AB enters the body. And later on, if I see that BA enters a body, which has been entered already by AB, I fire the splitObj() function!</span>
				<span style="color: #009900; font-style: italic;">// I need a unique ID for each body, in order to know where its corresponding enter point is - I store that id in the userData of each body.</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>spr <span style="color: #0033ff; font-weight: bold;">is</span> userData<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #6699cc; font-weight: bold;">var</span> userD<span style="color: #000066; font-weight: bold;">:</span>userData=spr <span style="color: #0033ff; font-weight: bold;">as</span> userData<span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>enterPointsVec<span style="color: #000000;">&#91;</span>userD<span style="color: #000066; font-weight: bold;">.</span>id<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
						<span style="color: #009900; font-style: italic;">// If this body has already had an intersection point, then it now has two intersection points, thus it must be split in two - thats where the splitObj() method comes in.</span>
						splitObj<span style="color: #000000;">&#40;</span>fixture<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> enterPointsVec<span style="color: #000000;">&#91;</span>userD<span style="color: #000066; font-weight: bold;">.</span>id<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> point<span style="color: #000066; font-weight: bold;">.</span>Copy<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: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
						enterPointsVec<span style="color: #000000;">&#91;</span>userD<span style="color: #000066; font-weight: bold;">.</span>id<span style="color: #000000;">&#93;</span>=point<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;">return</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: #009900; font-style: italic;">// function to get the area of a shape. I will remove tiny shape to increase performance</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> getArea<span style="color: #000000;">&#40;</span>vs<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> count<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;">Number</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> area<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">0.0</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> p1X<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">0.0</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> p1Y<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">0.0</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> inv3<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">1.0</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">3.0</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> count<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">++</span>i<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> p2<span style="color: #000066; font-weight: bold;">:</span>b2Vec2=vs<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> p3<span style="color: #000066; font-weight: bold;">:</span>b2Vec2=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;">&lt;</span>count<span style="color: #000066; font-weight: bold;">?</span>vs<span style="color: #000000;">&#91;</span><span style="color: #004993;">int</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: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">:</span>vs<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>
				<span style="color: #6699cc; font-weight: bold;">var</span> e1X<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=p2<span style="color: #000066; font-weight: bold;">.</span>x<span style="color: #000066; font-weight: bold;">-</span>p1X<span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> e1Y<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=p2<span style="color: #000066; font-weight: bold;">.</span>y<span style="color: #000066; font-weight: bold;">-</span>p1Y<span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> e2X<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=p3<span style="color: #000066; font-weight: bold;">.</span>x<span style="color: #000066; font-weight: bold;">-</span>p1X<span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> e2Y<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=p3<span style="color: #000066; font-weight: bold;">.</span>y<span style="color: #000066; font-weight: bold;">-</span>p1Y<span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> D<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000;">&#40;</span>e1X <span style="color: #000066; font-weight: bold;">*</span> e2Y <span style="color: #000066; font-weight: bold;">-</span> e1Y <span style="color: #000066; font-weight: bold;">*</span> e2X<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> triangleArea<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">0.5</span><span style="color: #000066; font-weight: bold;">*</span>D<span style="color: #000066; font-weight: bold;">;</span>
				area<span style="color: #000066; font-weight: bold;">+</span>=triangleArea<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> area<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> splitObj<span style="color: #000000;">&#40;</span>sliceBody<span style="color: #000066; font-weight: bold;">:</span>b2Body<span style="color: #000066; font-weight: bold;">,</span> A<span style="color: #000066; font-weight: bold;">:</span>b2Vec2<span style="color: #000066; font-weight: bold;">,</span> B<span style="color: #000066; font-weight: bold;">:</span>b2Vec2<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> origFixture<span style="color: #000066; font-weight: bold;">:</span>b2Fixture=sliceBody<span style="color: #000066; font-weight: bold;">.</span>GetFixtureList<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> poly<span style="color: #000066; font-weight: bold;">:</span>b2PolygonShape=origFixture<span style="color: #000066; font-weight: bold;">.</span>GetShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> b2PolygonShape<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</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>=poly<span style="color: #000066; font-weight: bold;">.</span>GetVertices<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span>numVertices<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=poly<span style="color: #000066; font-weight: bold;">.</span>GetVertexCount<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> shape1Vertices<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: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> shape2Vertices<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: #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> origUserData<span style="color: #000066; font-weight: bold;">:</span>userData=sliceBody<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>origUserDataId<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=origUserData<span style="color: #000066; font-weight: bold;">.</span>id<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>
			<span style="color: #6699cc; font-weight: bold;">var</span> polyShape<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>
			<span style="color: #6699cc; font-weight: bold;">var</span> body<span style="color: #000066; font-weight: bold;">:</span>b2Body<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// First, I destroy the original body and remove its Sprite representation from the childlist.</span>
			world<span style="color: #000066; font-weight: bold;">.</span>DestroyBody<span style="color: #000000;">&#40;</span>sliceBody<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span>origUserData<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// The world.RayCast() method returns points in world coordinates, so I use the b2Body.GetLocalPoint() to convert them to local coordinates.;</span>
			A=sliceBody<span style="color: #000066; font-weight: bold;">.</span>GetLocalPoint<span style="color: #000000;">&#40;</span>A<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			B=sliceBody<span style="color: #000066; font-weight: bold;">.</span>GetLocalPoint<span style="color: #000000;">&#40;</span>B<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// I use shape1Vertices and shape2Vertices to store the vertices of the two new shapes that are about to be created. </span>
			<span style="color: #009900; font-style: italic;">// Since both point A and B are vertices of the two new shapes, I add them to both vectors.</span>
			shape1Vertices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>A<span style="color: #000066; font-weight: bold;">,</span> B<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			shape2Vertices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>A<span style="color: #000066; font-weight: bold;">,</span> B<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// I iterate over all vertices of the original body. ;</span>
			<span style="color: #009900; font-style: italic;">// I use the function det() (&quot;det&quot; stands for &quot;determinant&quot;) to see on which side of AB each point is standing on. The parameters it needs are the coordinates of 3 points:</span>
			<span style="color: #009900; font-style: italic;">// - if it returns a value &gt;0, then the three points are in clockwise order (the point is under AB)</span>
			<span style="color: #009900; font-style: italic;">// - if it returns a value =0, then the three points lie on the same line (the point is on AB)</span>
			<span style="color: #009900; font-style: italic;">// - if it returns a value &lt;0, then the three points are in counter-clockwise order (the point is above AB). </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;">Number</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>numVertices<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: #004993;">d</span>=det<span style="color: #000000;">&#40;</span>A<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>A<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span>B<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>B<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>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: #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>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;">&#123;</span>
					shape1Vertices<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;">&#91;</span>i<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>
					shape2Vertices<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;">&#91;</span>i<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: #000000;">&#125;</span>
			<span style="color: #009900; font-style: italic;">// In order to be able to create the two new shapes, I need to have the vertices arranged in clockwise order.</span>
			<span style="color: #009900; font-style: italic;">// I call my custom method, arrangeClockwise(), which takes as a parameter a vector, representing the coordinates of the shape's vertices and returns a new vector, with the same points arranged clockwise.</span>
			shape1Vertices=arrangeClockwise<span style="color: #000000;">&#40;</span>shape1Vertices<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			shape2Vertices=arrangeClockwise<span style="color: #000000;">&#40;</span>shape2Vertices<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// setting the properties of the two newly created shapes</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;">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><span style="color: #004993;">position</span>=sliceBody<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> fixtureDef<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>
			fixtureDef<span style="color: #000066; font-weight: bold;">.</span>density=origFixture<span style="color: #000066; font-weight: bold;">.</span>GetDensity<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			fixtureDef<span style="color: #000066; font-weight: bold;">.</span>friction=origFixture<span style="color: #000066; font-weight: bold;">.</span>GetFriction<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			fixtureDef<span style="color: #000066; font-weight: bold;">.</span>restitution=origFixture<span style="color: #000066; font-weight: bold;">.</span>GetRestitution<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;">// creating the first shape, if big enough</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>getArea<span style="color: #000000;">&#40;</span>shape1Vertices<span style="color: #000066; font-weight: bold;">,</span>shape1Vertices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span>=<span style="color: #000000; font-weight:bold;">0.05</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				polyShape<span style="color: #000066; font-weight: bold;">.</span>SetAsVector<span style="color: #000000;">&#40;</span>shape1Vertices<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>
				bodyDef<span style="color: #000066; font-weight: bold;">.</span>userData=<span style="color: #0033ff; font-weight: bold;">new</span> userData<span style="color: #000000;">&#40;</span>origUserDataId<span style="color: #000066; font-weight: bold;">,</span>shape1Vertices<span style="color: #000066; font-weight: bold;">,</span>origUserData<span style="color: #000066; font-weight: bold;">.</span>texture<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>bodyDef<span style="color: #000066; font-weight: bold;">.</span>userData<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				enterPointsVec<span style="color: #000000;">&#91;</span>origUserDataId<span style="color: #000000;">&#93;</span>=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
				body=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>
				body<span style="color: #000066; font-weight: bold;">.</span>SetAngle<span style="color: #000000;">&#40;</span>sliceBody<span style="color: #000066; font-weight: bold;">.</span>GetAngle<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>
				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: #009900; font-style: italic;">// setting a velocity for the debris</span>
				body<span style="color: #000066; font-weight: bold;">.</span>SetLinearVelocity<span style="color: #000000;">&#40;</span>setExplosionVelocity<span style="color: #000000;">&#40;</span>body<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;">// the shape will be also part of the explosion and can explode too</span>
				explodingBodies<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>body<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;">// creating the second shape, if big enough</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>getArea<span style="color: #000000;">&#40;</span>shape2Vertices<span style="color: #000066; font-weight: bold;">,</span>shape2Vertices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span>=<span style="color: #000000; font-weight:bold;">0.05</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				polyShape<span style="color: #000066; font-weight: bold;">.</span>SetAsVector<span style="color: #000000;">&#40;</span>shape2Vertices<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>
				bodyDef<span style="color: #000066; font-weight: bold;">.</span>userData=<span style="color: #0033ff; font-weight: bold;">new</span> userData<span style="color: #000000;">&#40;</span>numEnterPoints<span style="color: #000066; font-weight: bold;">,</span>shape2Vertices<span style="color: #000066; font-weight: bold;">,</span>origUserData<span style="color: #000066; font-weight: bold;">.</span>texture<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>bodyDef<span style="color: #000066; font-weight: bold;">.</span>userData<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				enterPointsVec<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;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				numEnterPoints<span style="color: #000066; font-weight: bold;">++;</span>
				body=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>
				body<span style="color: #000066; font-weight: bold;">.</span>SetAngle<span style="color: #000000;">&#40;</span>sliceBody<span style="color: #000066; font-weight: bold;">.</span>GetAngle<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>
				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: #009900; font-style: italic;">// setting a velocity for the debris</span>
				body<span style="color: #000066; font-weight: bold;">.</span>SetLinearVelocity<span style="color: #000000;">&#40;</span>setExplosionVelocity<span style="color: #000000;">&#40;</span>body<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;">// the shape will be also part of the explosion and can explode too</span>
				explodingBodies<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>body<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;">// this function will determine the velocity of the debris according</span>
		<span style="color: #009900; font-style: italic;">// to the center of mass of the body and the distance from the explosion point</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> setExplosionVelocity<span style="color: #000000;">&#40;</span><span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">:</span>b2Body<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> distX<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span>GetWorldCenter<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">*</span>worldScale<span style="color: #000066; font-weight: bold;">-</span>explosionX<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>distX<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>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>distX<span style="color: #000066; font-weight: bold;">&lt;-</span>explosionRadius<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					distX=<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>
					distX=<span style="color: #000066; font-weight: bold;">-</span> explosionRadius<span style="color: #000066; font-weight: bold;">-</span>distX<span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>distX<span style="color: #000066; font-weight: bold;">&gt;</span>explosionRadius<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					distX=<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>
					distX=explosionRadius<span style="color: #000066; font-weight: bold;">-</span>distX<span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> distY<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">.</span>GetWorldCenter<span style="color: #000000;">&#40;</span><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>worldScale<span style="color: #000066; font-weight: bold;">-</span>explosionY<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>distY<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>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>distY<span style="color: #000066; font-weight: bold;">&lt;-</span>explosionRadius<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					distY=<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>
					distY=<span style="color: #000066; font-weight: bold;">-</span> explosionRadius<span style="color: #000066; font-weight: bold;">-</span>distY<span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>distY<span style="color: #000066; font-weight: bold;">&gt;</span>explosionRadius<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					distY=<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>
					distY=explosionRadius<span style="color: #000066; font-weight: bold;">-</span>distY<span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			distX<span style="color: #000066; font-weight: bold;">*</span>=<span style="color: #000000; font-weight:bold;">0.25</span><span style="color: #000066; font-weight: bold;">;</span>
			distY<span style="color: #000066; font-weight: bold;">*</span>=<span style="color: #000000; font-weight:bold;">0.25</span><span style="color: #000066; font-weight: bold;">;</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>distX<span style="color: #000066; font-weight: bold;">,</span>distY<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> arrangeClockwise<span style="color: #000000;">&#40;</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: #000000;">&#41;</span><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;">&#123;</span>
			<span style="color: #009900; font-style: italic;">// The algorithm is simple: </span>
			<span style="color: #009900; font-style: italic;">// First, it arranges all given points in ascending order, according to their x-coordinate.</span>
			<span style="color: #009900; font-style: italic;">// Secondly, it takes the leftmost and rightmost points (lets call them C and D), and creates tempVec, where the points arranged in clockwise order will be stored.</span>
			<span style="color: #009900; font-style: italic;">// Then, it iterates over the vertices vector, and uses the det() method I talked about earlier. It starts putting the points above CD from the beginning of the vector, and the points below CD from the end of the vector. </span>
			<span style="color: #009900; font-style: italic;">// That was it!</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> n<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=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: #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>i1<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>i2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</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>
			<span style="color: #6699cc; font-weight: bold;">var</span> tempVec<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: #000000;">&#40;</span>n<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span>C<span style="color: #000066; font-weight: bold;">:</span>b2Vec2<span style="color: #000066; font-weight: bold;">,</span>D<span style="color: #000066; font-weight: bold;">:</span>b2Vec2<span style="color: #000066; font-weight: bold;">;</span>
			vec<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sort</span><span style="color: #000000;">&#40;</span>comp1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			tempVec<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span>=vec<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>
			C=vec<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>
			D=vec<span style="color: #000000;">&#91;</span>n<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: #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;">Number</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;">&lt;</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> i<span style="color: #000066; font-weight: bold;">++</span><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>C<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>C<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span>D<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>D<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>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>vec<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: #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>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;">&#123;</span>
					tempVec<span style="color: #000000;">&#91;</span>i1<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#93;</span>=vec<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</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>
					tempVec<span style="color: #000000;">&#91;</span>i2<span style="color: #000066; font-weight: bold;">--</span><span style="color: #000000;">&#93;</span>=vec<span style="color: #000000;">&#91;</span>i<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>
			tempVec<span style="color: #000000;">&#91;</span>i1<span style="color: #000000;">&#93;</span>=vec<span style="color: #000000;">&#91;</span>n<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: #0033ff; font-weight: bold;">return</span> tempVec<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> comp1<span style="color: #000000;">&#40;</span>a<span style="color: #000066; font-weight: bold;">:</span>b2Vec2<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">:</span>b2Vec2<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: #009900; font-style: italic;">// This is a compare function, used in the arrangeClockwise() method - a fast way to arrange the points in ascending order, according to their x-coordinate.</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>a<span style="color: #000066; font-weight: bold;">.</span>x<span style="color: #000066; font-weight: bold;">&gt;</span>b<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</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: #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: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>a<span style="color: #000066; font-weight: bold;">.</span>x<span style="color: #000066; font-weight: bold;">&lt;</span>b<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</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: #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;">return</span> <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;">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: #009900; font-style: italic;">// This is a function which finds the determinant of a 3x3 matrix.</span>
			<span style="color: #009900; font-style: italic;">// If you studied matrices, you'd know that it returns a positive number if three given points are in clockwise order, negative if they are in anti-clockwise order and zero if they lie on the same line.</span>
			<span style="color: #009900; font-style: italic;">// Another useful thing about determinants is that their absolute value is two times the face of the triangle, formed by the three given points.</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>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>and this is <code>userData</code> 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
</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>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> <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;">BitmapData</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;">Matrix</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> userData <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> id<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span>texture<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;">public</span> <span style="color: #339966; font-weight: bold;">function</span> userData<span style="color: #000000;">&#40;</span>id<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><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> texture<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">BitmapData</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>id=id<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>texture=texture<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// I use the matrix so that I can have the center of the shape I'm drawing match the center of the BitmapData image - I &quot;move&quot; the BitmapData projection left by half its width and up by half its height.</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> m<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Matrix</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Matrix</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			m<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">tx</span>=<span style="color: #000066; font-weight: bold;">-</span> texture<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;">0.5</span><span style="color: #000066; font-weight: bold;">;</span>
			m<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ty</span>=<span style="color: #000066; font-weight: bold;">-</span> texture<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;">0.5</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// I then draw lines from each vertex to the next, in clockwise order and use the beginBitmapFill() method to add the texture.</span>
			<span style="color: #0033ff; font-weight: bold;">this</span><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;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">beginBitmapFill</span><span style="color: #000000;">&#40;</span>texture<span style="color: #000066; font-weight: bold;">,</span> m<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">this</span><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;">moveTo</span><span style="color: #000000;">&#40;</span>verticesVec<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><span style="color: #004993;">x</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> verticesVec<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><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">*</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;">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;">1</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span>verticesVec<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: #0033ff; font-weight: bold;">this</span><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;">lineTo</span><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: #000000; font-weight:bold;">30</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: #000000; font-weight:bold;">30</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;">this</span><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;">lineTo</span><span style="color: #000000;">&#40;</span>verticesVec<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><span style="color: #004993;">x</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> verticesVec<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><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">*</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;">this</span><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: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>And now let me see what kind of games can you make using this concept.</p>
<p><a href="/wp-content/uploads/2012/01/main.zip">Download the source code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2012/01/17/create-real-explosions-with-box2d-adding-textures/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Attend the Flash Gaming Summit 2012 with a 15% OFF!</title>
		<link>http://www.emanueleferonato.com/2012/01/11/attend-the-flash-gaming-summit-2012-with-a-15-off/</link>
		<comments>http://www.emanueleferonato.com/2012/01/11/attend-the-flash-gaming-summit-2012-with-a-15-off/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 20:41:15 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Monetize]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=5068</guid>
		<description><![CDATA[The <strong><a href="http://www.flashgamingsummit.com/" target="_blank">Flash Gaming Summit</a></strong> is the leading annual one-day conference dedicated to fostering the growth and success of the Flash games community. Now you can attend it with a 15% OFF!]]></description>
			<content:encoded><![CDATA[<p>Do you love to work in Flash games industry? The <strong><a href="http://www.flashgamingsummit.com/" target="_blank">Flash Gaming Summit</a></strong> is the leading annual one-day conference dedicated to fostering the growth and success of the Flash games community. In this 4th edition, on March 4th, 2012 San Francisco will host the biggest names in the Flash games space to share industry insights and strategies on successful game design, development, and monetization.</p>
<p><a href="http://www.flashgamingsummit.com/" target = "_blank"><img src="/wp-content/uploads/2012/01/fgs.jpg" alt="" title="fgs" width="640" height="333" class="alignnone size-full wp-image-5069" /></a> </p>
<p>The official theme for FGS 2012 is <strong>Maximize Your Game</strong>. Why? Game developers (and the industry in general) are doing amazing things with Flash games. We are seeing games being designed and created (maximized) for multiple devices and platforms. Developers are increasing (maximizing) the value of their IP. Game designers and artists are improving (maximizing) the overall quality of their games. New tools and resources are available to help improve (maximize) development time. Marketing and monetization strategies are emerging to enhance (maximize) overall game distribution, discovery, and revenue streams. Maximize Your Game reflects all of the exciting innovation we are seeing in the Flash games industry today.</p>
<p>Moreover, there is space for speakers in the following topics:</p>
<p>* Mobile-specific<br />
* Design<br />
* Development<br />
* Marketing strategy<br />
* Designing for multiple devices<br />
* Game post-mortems<br />
* Game Development<br />
* Multi-player<br />
* Developing for multiple platforms<br />
* Development tools<br />
* Performance optimization<br />
* Game Design<br />
* Design tips &#038; tricks<br />
* Game post-mortems<br />
* 3D-specific<br />
* Pros and cons<br />
* Optimizing 2D performance<br />
* Using Stage 3D<br />
* Game post-mortems<br />
* Business<br />
* Building a business (going from one person to a small team)<br />
* Artwork<br />
* Graphics<br />
* Animation</p>
<p>And it&#8217;s not over yet! Sign up for the conference with the discount code <a href="http://www.eventbrite.com/discounts?eid=2363661776&#038;discount=2574847" target="_blank">blog_Emanuele</a> (hey! It&#8217;s me!!) and attend the summit with a 15% OFF!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2012/01/11/attend-the-flash-gaming-summit-2012-with-a-15-off/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Develop double jump behavior in StencylWorks</title>
		<link>http://www.emanueleferonato.com/2012/01/10/develop-double-jump-behavior-in-stencylworks/</link>
		<comments>http://www.emanueleferonato.com/2012/01/10/develop-double-jump-behavior-in-stencylworks/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 16:31:56 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[StencylWorks]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=5056</guid>
		<description><![CDATA[Learn how to make a double jump behavior with StencylWorks. Very useful for your platform games.]]></description>
			<content:encoded><![CDATA[<p>One of the most interesting features to add in a platform game is the double jump.</p>
<p>This means the player can jump, and while in the air, can jump once more to get higher platforms.</p>
<p>Something like this demo made with <a href="http://www.stencyl.com/stencylworks/overview/" target="_blank">StencylWorks</a>, taken from my upcoming game <strong>Kira the Witch</strong>:</p>
<p><embed src="/wp-content/uploads/2012/01/doublejump.swf" menu="false" quality="high" width="640" height="480" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>Move with LEFT and RIGHT arrow keys, jump and double jump with UP arrow key.</p>
<p>I already showed you how to make an actor jump in the post <a href="http://www.emanueleferonato.com/2011/12/05/create-awesome-flash-games-in-no-time-with-stencylworks-adding-intro-jumping-and-more/">Create awesome Flash games in no time with StencylWorks – adding intro, jumping and more</a>, but when we want a double jump, we need two more attributes: one to see if we are jumping, that is if we are in the air because we made a jump (and not because we are falling down a platform) and one to determine if we can perform a double jump.</p>
<p>In the end, the double jump can be made only when you jump, and before you touch the ground you release the jump key and then press it again.</p>
<p>That is, the behavior you can see here:</p>
<p><img src="/wp-content/uploads/2012/01/doublejump.jpg" /></p>
<p>Useless to say, really easy, like all <a href="http://www.stencyl.com/stencylworks/overview/" target="_blank">StencylWorks</a> features.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2012/01/10/develop-double-jump-behavior-in-stencylworks/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Create REAL explosions with Box2D &#8211; exploding objects and setting the center of explosion with mouse click</title>
		<link>http://www.emanueleferonato.com/2012/01/05/create-real-explosions-with-box2d-exploding-objects-and-setting-the-center-of-explosion-with-mouse-click/</link>
		<comments>http://www.emanueleferonato.com/2012/01/05/create-real-explosions-with-box2d-exploding-objects-and-setting-the-center-of-explosion-with-mouse-click/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 11:55:13 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=5047</guid>
		<description><![CDATA[Real Box2D explosions get even more real]]></description>
			<content:encoded><![CDATA[<p>I got a lot of requests once I published how to <a href="http://www.emanueleferonato.com/2011/12/08/create-real-explosions-with-box2d/">create REAL explosions with Box2D</a> and most of them asked for exploding objects clicking on them, setting the center of explosion with mouse pointer.</p>
<p>So I changed a bit the script and now you have such features, and to preserve speed I also removed all chunks whose area is too small. They just slow down the prototype with no advantage.</p>
<p>So that&#8217;s what you have now:</p>
<p><embed src="/wp-content/uploads/2012/01/boom.swf" menu="false" quality="high" width="640" height="480" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>Click on any object (static or dynamic) to explode it.</p>
<p>And this is the uncommented, yet to be optimized script:</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
</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>
	<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>
	<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>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> <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;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main <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> world<span style="color: #000066; font-weight: bold;">:</span>b2World=<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;">10</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: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> worldScale<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">30</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> laserSegment<span style="color: #000066; font-weight: bold;">:</span>b2Segment<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> drawing<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> affectedByLaser<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>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> entryPoint<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;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> explodingBodies<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>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> explosionCenterX<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> explosionCenterY<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> chunks<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>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> explosionRadius<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			debugDraw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			addWall<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">320</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">480</span><span style="color: #000066; font-weight: bold;">,</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;">20</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			addWall<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">320</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</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;">20</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			addWall<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;">240</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">20</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">480</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			addWall<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;">240</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">20</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">480</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			addWall<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">320</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">240</span><span style="color: #000066; font-weight: bold;">,</span><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: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			addWall<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">250</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">110</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>
			addWall<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">390</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">110</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>
			<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> updateWorld<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;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span>mousePressed<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> mousePressed<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> cutAngle<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">;</span>
			explosionCenterX=<span style="color: #004993;">mouseX</span><span style="color: #000066; font-weight: bold;">;</span>
			explosionCenterY=<span style="color: #004993;">mouseY</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> clickedBody<span style="color: #000066; font-weight: bold;">:</span>b2Body=GetBodyAtXY<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span>explosionCenterX<span style="color: #000066; font-weight: bold;">/</span>worldScale<span style="color: #000066; font-weight: bold;">,</span>explosionCenterY<span style="color: #000066; font-weight: bold;">/</span>worldScale<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			explodingBodies=<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>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>clickedBody<span style="color: #000066; font-weight: bold;">!</span>=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				explodingBodies<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>clickedBody<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> i<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> i<span style="color: #000066; font-weight: bold;">&lt;</span>chunks<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>
					cutAngle=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">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>
					laserSegment=<span style="color: #0033ff; font-weight: bold;">new</span> b2Segment<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					laserSegment<span style="color: #000066; font-weight: bold;">.</span>p1=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>explosionCenterX<span style="color: #000066; font-weight: bold;">+</span>i<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;">200</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span>cutAngle<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">/</span>worldScale<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000;">&#40;</span>explosionCenterY<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span>cutAngle<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">/</span>worldScale<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					laserSegment<span style="color: #000066; font-weight: bold;">.</span>p2=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>explosionCenterX<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span>cutAngle<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">/</span>worldScale<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000;">&#40;</span>explosionCenterY<span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span>cutAngle<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">/</span>worldScale<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					affectedByLaser=<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>
					entryPoint=<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: #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>RayCast<span style="color: #000000;">&#40;</span>laserFired<span style="color: #000066; font-weight: bold;">,</span>laserSegment<span style="color: #000066; font-weight: bold;">.</span>p1<span style="color: #000066; font-weight: bold;">,</span>laserSegment<span style="color: #000066; font-weight: bold;">.</span>p2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					world<span style="color: #000066; font-weight: bold;">.</span>RayCast<span style="color: #000000;">&#40;</span>laserFired<span style="color: #000066; font-weight: bold;">,</span>laserSegment<span style="color: #000066; font-weight: bold;">.</span>p2<span style="color: #000066; font-weight: bold;">,</span>laserSegment<span style="color: #000066; font-weight: bold;">.</span>p1<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: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> debugDraw<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: #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> debugSprite<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>debugSprite<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>debugSprite<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>worldScale<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>
			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>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> addWall<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>w<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>h<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: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> wallShape<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>
			wallShape<span style="color: #000066; font-weight: bold;">.</span>SetAsBox<span style="color: #000000;">&#40;</span>w<span style="color: #000066; font-weight: bold;">/</span>worldScale<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>h<span style="color: #000066; font-weight: bold;">/</span>worldScale<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: #6699cc; font-weight: bold;">var</span> wallFixture<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>
			wallFixture<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>
			wallFixture<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>
			wallFixture<span style="color: #000066; font-weight: bold;">.</span>restitution=<span style="color: #000000; font-weight:bold;">0.5</span><span style="color: #000066; font-weight: bold;">;</span>
			wallFixture<span style="color: #000066; font-weight: bold;">.</span>shape=wallShape<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> wallBodyDef<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>
			wallBodyDef<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>pX<span style="color: #000066; font-weight: bold;">/</span>worldScale<span style="color: #000066; font-weight: bold;">,</span>pY<span style="color: #000066; font-weight: bold;">/</span>worldScale<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> wall<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>wallBodyDef<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			wall<span style="color: #000066; font-weight: bold;">.</span>CreateFixture<span style="color: #000000;">&#40;</span>wallFixture<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> updateWorld<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>
			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>ClearForces<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>DrawDebugData<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;">private</span> <span style="color: #339966; font-weight: bold;">function</span> laserFired<span style="color: #000000;">&#40;</span>fixture<span style="color: #000066; font-weight: bold;">:</span>b2Fixture<span style="color: #000066; font-weight: bold;">,</span>point<span style="color: #000066; font-weight: bold;">:</span>b2Vec2<span style="color: #000066; font-weight: bold;">,</span>normal<span style="color: #000066; font-weight: bold;">:</span>b2Vec2<span style="color: #000066; font-weight: bold;">,</span>fraction<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: #6699cc; font-weight: bold;">var</span> affectedBody<span style="color: #000066; font-weight: bold;">:</span>b2Body=fixture<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>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>explodingBodies<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span>affectedBody<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">!</span>=<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> affectedPolygon<span style="color: #000066; font-weight: bold;">:</span>b2PolygonShape=fixture<span style="color: #000066; font-weight: bold;">.</span>GetShape<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> b2PolygonShape<span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> fixtureIndex<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=affectedByLaser<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span>affectedBody<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>fixtureIndex==<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>
					affectedByLaser<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>affectedBody<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					entryPoint<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>point<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: #6699cc; font-weight: bold;">var</span> rayCenter<span style="color: #000066; font-weight: bold;">:</span>b2Vec2=<span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>point<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">+</span>entryPoint<span style="color: #000000;">&#91;</span>fixtureIndex<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000;">&#40;</span>point<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">+</span>entryPoint<span style="color: #000000;">&#91;</span>fixtureIndex<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: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #6699cc; font-weight: bold;">var</span> rayAngle<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">atan2</span><span style="color: #000000;">&#40;</span>entryPoint<span style="color: #000000;">&#91;</span>fixtureIndex<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>y<span style="color: #000066; font-weight: bold;">-</span>point<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span>entryPoint<span style="color: #000000;">&#91;</span>fixtureIndex<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>x<span style="color: #000066; font-weight: bold;">-</span>point<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #6699cc; font-weight: bold;">var</span> polyVertices<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>=affectedPolygon<span style="color: #000066; font-weight: bold;">.</span>GetVertices<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> newPolyVertices1<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: #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> newPolyVertices2<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: #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> currentPoly<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> cutPlaced1<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: #6699cc; font-weight: bold;">var</span> cutPlaced2<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;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span>polyVertices<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: #6699cc; font-weight: bold;">var</span> worldPoint<span style="color: #000066; font-weight: bold;">:</span>b2Vec2=affectedBody<span style="color: #000066; font-weight: bold;">.</span>GetWorldPoint<span style="color: #000000;">&#40;</span>polyVertices<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>
						<span style="color: #6699cc; font-weight: bold;">var</span> cutAngle<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">atan2</span><span style="color: #000000;">&#40;</span>worldPoint<span style="color: #000066; font-weight: bold;">.</span>y<span style="color: #000066; font-weight: bold;">-</span>rayCenter<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span>worldPoint<span style="color: #000066; font-weight: bold;">.</span>x<span style="color: #000066; font-weight: bold;">-</span>rayCenter<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>rayAngle<span style="color: #000066; font-weight: bold;">;</span>
						<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>cutAngle<span style="color: #000066; font-weight: bold;">&lt;</span>Math<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;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							cutAngle<span style="color: #000066; font-weight: bold;">+</span>=<span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span><span style="color: #000066; font-weight: bold;">;</span>
						<span style="color: #000000;">&#125;</span>
						<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>cutAngle<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>cutAngle<span style="color: #000066; font-weight: bold;">&lt;</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;">&#123;</span>
							<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>currentPoly==<span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
								cutPlaced1=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
								newPolyVertices1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>point<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
								newPolyVertices1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>entryPoint<span style="color: #000000;">&#91;</span>fixtureIndex<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>
							newPolyVertices1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>worldPoint<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
							currentPoly=<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>
							<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>currentPoly==<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
								cutPlaced2=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
								newPolyVertices2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>entryPoint<span style="color: #000000;">&#91;</span>fixtureIndex<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
								newPolyVertices2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>point<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #000000;">&#125;</span>
							newPolyVertices2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>worldPoint<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
							currentPoly=<span style="color: #000000; font-weight:bold;">2</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: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span> cutPlaced1<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
						newPolyVertices1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>point<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
						newPolyVertices1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>entryPoint<span style="color: #000000;">&#91;</span>fixtureIndex<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;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span> cutPlaced2<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
						newPolyVertices2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>entryPoint<span style="color: #000000;">&#91;</span>fixtureIndex<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
						newPolyVertices2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>point<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #000000;">&#125;</span>
					createSlice<span style="color: #000000;">&#40;</span>newPolyVertices1<span style="color: #000066; font-weight: bold;">,</span>newPolyVertices1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					createSlice<span style="color: #000000;">&#40;</span>newPolyVertices2<span style="color: #000066; font-weight: bold;">,</span>newPolyVertices2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><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>affectedBody<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">return</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;">private</span> <span style="color: #339966; font-weight: bold;">function</span> findCentroid<span style="color: #000000;">&#40;</span>vs<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> count<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>b2Vec2 <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">c</span><span style="color: #000066; font-weight: bold;">:</span>b2Vec2 = <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<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> area<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">0.0</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> p1X<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">0.0</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> p1Y<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">0.0</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> inv3<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">1.0</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">3.0</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> count<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">++</span>i<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> p2<span style="color: #000066; font-weight: bold;">:</span>b2Vec2=vs<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> p3<span style="color: #000066; font-weight: bold;">:</span>b2Vec2=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;">&lt;</span>count<span style="color: #000066; font-weight: bold;">?</span>vs<span style="color: #000000;">&#91;</span><span style="color: #004993;">int</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: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">:</span>vs<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>
				<span style="color: #6699cc; font-weight: bold;">var</span> e1X<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=p2<span style="color: #000066; font-weight: bold;">.</span>x<span style="color: #000066; font-weight: bold;">-</span>p1X<span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> e1Y<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=p2<span style="color: #000066; font-weight: bold;">.</span>y<span style="color: #000066; font-weight: bold;">-</span>p1Y<span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> e2X<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=p3<span style="color: #000066; font-weight: bold;">.</span>x<span style="color: #000066; font-weight: bold;">-</span>p1X<span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> e2Y<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=p3<span style="color: #000066; font-weight: bold;">.</span>y<span style="color: #000066; font-weight: bold;">-</span>p1Y<span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> D<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000;">&#40;</span>e1X <span style="color: #000066; font-weight: bold;">*</span> e2Y <span style="color: #000066; font-weight: bold;">-</span> e1Y <span style="color: #000066; font-weight: bold;">*</span> e2X<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> triangleArea<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">0.5</span><span style="color: #000066; font-weight: bold;">*</span>D<span style="color: #000066; font-weight: bold;">;</span>
				area<span style="color: #000066; font-weight: bold;">+</span>=triangleArea<span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #004993;">c</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span>= triangleArea <span style="color: #000066; font-weight: bold;">*</span> inv3 <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000;">&#40;</span>p1X <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> p3<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #004993;">c</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">+</span>= triangleArea <span style="color: #000066; font-weight: bold;">*</span> inv3 <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000;">&#40;</span>p1Y <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;">y</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #004993;">c</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">*</span>=<span style="color: #000000; font-weight:bold;">1.0</span><span style="color: #000066; font-weight: bold;">/</span>area<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">c</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">*</span>=<span style="color: #000000; font-weight:bold;">1.0</span><span style="color: #000066; font-weight: bold;">/</span>area<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #004993;">c</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> getArea<span style="color: #000000;">&#40;</span>vs<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> count<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;">Number</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> area<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">0.0</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> p1X<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">0.0</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> p1Y<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">0.0</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> inv3<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">1.0</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">3.0</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> count<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">++</span>i<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> p2<span style="color: #000066; font-weight: bold;">:</span>b2Vec2=vs<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> p3<span style="color: #000066; font-weight: bold;">:</span>b2Vec2=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;">&lt;</span>count<span style="color: #000066; font-weight: bold;">?</span>vs<span style="color: #000000;">&#91;</span><span style="color: #004993;">int</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: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">:</span>vs<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>
				<span style="color: #6699cc; font-weight: bold;">var</span> e1X<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=p2<span style="color: #000066; font-weight: bold;">.</span>x<span style="color: #000066; font-weight: bold;">-</span>p1X<span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> e1Y<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=p2<span style="color: #000066; font-weight: bold;">.</span>y<span style="color: #000066; font-weight: bold;">-</span>p1Y<span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> e2X<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=p3<span style="color: #000066; font-weight: bold;">.</span>x<span style="color: #000066; font-weight: bold;">-</span>p1X<span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> e2Y<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=p3<span style="color: #000066; font-weight: bold;">.</span>y<span style="color: #000066; font-weight: bold;">-</span>p1Y<span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> D<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000;">&#40;</span>e1X <span style="color: #000066; font-weight: bold;">*</span> e2Y <span style="color: #000066; font-weight: bold;">-</span> e1Y <span style="color: #000066; font-weight: bold;">*</span> e2X<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> triangleArea<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">0.5</span><span style="color: #000066; font-weight: bold;">*</span>D<span style="color: #000066; font-weight: bold;">;</span>
				area<span style="color: #000066; font-weight: bold;">+</span>=triangleArea<span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> area<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> createSlice<span style="color: #000000;">&#40;</span>vertices<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>numVertices<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: #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>getArea<span style="color: #000000;">&#40;</span>vertices<span style="color: #000066; font-weight: bold;">,</span>vertices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&gt;</span>=<span style="color: #000000; font-weight:bold;">0.05</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> centre<span style="color: #000066; font-weight: bold;">:</span>b2Vec2=findCentroid<span style="color: #000000;">&#40;</span>vertices<span style="color: #000066; font-weight: bold;">,</span>vertices<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</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> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span>numVertices<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>
					vertices<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>Subtract<span style="color: #000000;">&#40;</span>centre<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #000000;">&#125;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> sliceBody<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>
				sliceBody<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>centre<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span> centre<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>
				sliceBody<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>
				<span style="color: #6699cc; font-weight: bold;">var</span> slicePoly<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>
				slicePoly<span style="color: #000066; font-weight: bold;">.</span>SetAsVector<span style="color: #000000;">&#40;</span>vertices<span style="color: #000066; font-weight: bold;">,</span>numVertices<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> sliceFixture<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>
				sliceFixture<span style="color: #000066; font-weight: bold;">.</span>shape=slicePoly<span style="color: #000066; font-weight: bold;">;</span>
				sliceFixture<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>
				<span style="color: #6699cc; font-weight: bold;">var</span> worldSlice<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>sliceBody<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				worldSlice<span style="color: #000066; font-weight: bold;">.</span>CreateFixture<span style="color: #000000;">&#40;</span>sliceFixture<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>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>numVertices<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>
					vertices<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>Add<span style="color: #000000;">&#40;</span>centre<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #000000;">&#125;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> distX<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000;">&#40;</span>centre<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">*</span>worldScale<span style="color: #000066; font-weight: bold;">-</span>explosionCenterX<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>distX<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>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>distX<span style="color: #000066; font-weight: bold;">&lt;-</span>explosionRadius<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
						distX=<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>
						distX=<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>distX<span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
				<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>distX<span style="color: #000066; font-weight: bold;">&gt;</span>explosionRadius<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
						distX=<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>
						distX=<span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">-</span>distX<span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> distY<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000;">&#40;</span>centre<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">*</span>worldScale<span style="color: #000066; font-weight: bold;">-</span>explosionCenterY<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>distY<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>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>distY<span style="color: #000066; font-weight: bold;">&lt;-</span>explosionRadius<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
						distY=<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>
						distY=<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>distY<span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
				<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>distY<span style="color: #000066; font-weight: bold;">&gt;</span>explosionRadius<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
						distY=<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>
						distY=<span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">-</span>distY<span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
				distX<span style="color: #000066; font-weight: bold;">*</span>=<span style="color: #000000; font-weight:bold;">0.25</span><span style="color: #000066; font-weight: bold;">;</span>
				distY<span style="color: #000066; font-weight: bold;">*</span>=<span style="color: #000000; font-weight:bold;">0.25</span><span style="color: #000066; font-weight: bold;">;</span>
				worldSlice<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>distX<span style="color: #000066; font-weight: bold;">,</span>distY<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				explodingBodies<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>worldSlice<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> GetBodyAtXY<span style="color: #000000;">&#40;</span>coordinate<span style="color: #000066; font-weight: bold;">:</span>b2Vec2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>b2Body <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> touchedBody<span style="color: #000066; font-weight: bold;">:</span>b2Body=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
			world<span style="color: #000066; font-weight: bold;">.</span>QueryPoint<span style="color: #000000;">&#40;</span>GetBodyCallback<span style="color: #000066; font-weight: bold;">,</span>coordinate<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #339966; font-weight: bold;">function</span> GetBodyCallback<span style="color: #000000;">&#40;</span>fixture<span style="color: #000066; font-weight: bold;">:</span>b2Fixture<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> shape<span style="color: #000066; font-weight: bold;">:</span>b2Shape=fixture<span style="color: #000066; font-weight: bold;">.</span>GetShape<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> inside<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=shape<span style="color: #000066; font-weight: bold;">.</span>TestPoint<span style="color: #000000;">&#40;</span>fixture<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>GetTransform<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span>coordinate<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>inside<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					touchedBody=fixture<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>
					<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: #0033ff; font-weight: bold;">return</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: #0033ff; font-weight: bold;">return</span> touchedBody<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>I will post the complete tutorial once I&#8217;ll complete the final step: adding textures to explosions. If you want to try the class, you can copy/paste it in the example you can download at <a href="http://www.emanueleferonato.com/2011/06/13/slicing-splitting-and-cutting-objects-with-box2d/">slicing, splitting and cutting objects with Box2D</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2012/01/05/create-real-explosions-with-box2d-exploding-objects-and-setting-the-center-of-explosion-with-mouse-click/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<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>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching 12/18 queries in 0.081 seconds using disk: basic

Served from: www.emanueleferonato.com @ 2012-02-08 19:48:57 -->
