<?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; Actionscript 3</title>
	<atom:link href="http://www.emanueleferonato.com/category/actionscript-3/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>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>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>
		<item>
		<title>Flare3D 2.0 + Flare3D Physics overview</title>
		<link>http://www.emanueleferonato.com/2011/12/29/flare3d-2-0-flare3d-physics-overview/</link>
		<comments>http://www.emanueleferonato.com/2011/12/29/flare3d-2-0-flare3d-physics-overview/#comments</comments>
		<pubDate>Thu, 29 Dec 2011 15:39:44 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=5022</guid>
		<description><![CDATA[If Flare3D 2.0 is not enough, you can add 3D physics to your games with Flare3D Physics]]></description>
			<content:encoded><![CDATA[<p>Some days ago the <a href="http://www.flare3d.com/blog/" target="_blank">Flare3D official blog</a> announced the beta of the Flare3D physics engine, which will allow us to create 3D physics environment without using 3rd party libraries such as <a href="http://www.jiglibflash.com/blog/" target="_blank">JiglibFlash</a>, and make games like <a href="http://www.emanueleferonato.com/2011/06/06/play-cubesout-a-3d-flash-physics-game/">CubesOut</a> (based on <a href="http://www.emanueleferonato.com/2011/04/30/complete-game-prototype-using-flare3d-and-jiglibflash/">this prototype</a>) and <a href="http://www.emanueleferonato.com/2011/04/18/the-making-of-a-small-car-a-3d-flash-game-made-with-flare3d/">A Small Car</a> just using Flare3D libraries.</p>
<p>You can download the latest version of the beta from <a href="http://wiki.flare3d.com/index.php/Main_Page" target="_blank">this page</a> but you will need to publish for Flash Player 11 in order to make it work.</p>
<p>I suggest you to read <a href="http://blogs.adobe.com/rgalvan/2011/11/adding-fp11-support-to-flash-pro-cs5-and-cs5-5.html" target="_blank">this guide</a> in order to add support for FP11 to your Flash IDE.</p>
<p>I have to say The MXP included did not add any HTML template named &#8220;Flash WMODE direct&#8221; so I had to set <code>wmode</code> to <code>direct</code> by myself in the HTML page.</p>
<p>You will also need to test your works in an HTML page since publishing directly in the IDE won&#8217;t work.</p>
<p>Mixing some code in the demos and adding the camera control I explained in <a href="http://www.emanueleferonato.com/2011/02/05/flash-3d-sokoban-prototype-with-flare3d/">Flash 3D Sokoban prototype with Flare3D</a> I ended with this 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
</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> flare<span style="color: #000066; font-weight: bold;">.</span>basic<span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> flare<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> flare<span style="color: #000066; font-weight: bold;">.</span>physics<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>PhysicsBox<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> flare<span style="color: #000066; font-weight: bold;">.</span>physics<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>PhysicsPlane<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> flare<span style="color: #000066; font-weight: bold;">.</span>physics<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>PhysicsSphere<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> flare<span style="color: #000066; font-weight: bold;">.</span>physics<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>PhysicsSystemManager<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> flare<span style="color: #000066; font-weight: bold;">.</span>physics<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>RigidBody<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> flare<span style="color: #000066; font-weight: bold;">.</span>physics<span style="color: #000066; font-weight: bold;">.</span>vehicles<span style="color: #000066; font-weight: bold;">.</span>PhysicsVehicle<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> flare<span style="color: #000066; font-weight: bold;">.</span>materials<span style="color: #000066; font-weight: bold;">.</span>Shader3D<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> flare<span style="color: #000066; font-weight: bold;">.</span>materials<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">filters</span><span style="color: #000066; font-weight: bold;">.</span>ColorFilter<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> flare<span style="color: #000066; font-weight: bold;">.</span>primitives<span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> flare<span style="color: #000066; font-weight: bold;">.</span>utils<span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> flare<span style="color: #000066; font-weight: bold;">.</span>system<span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> flare<span style="color: #000066; font-weight: bold;">.</span>loaders<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: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span><span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextField</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextFieldAutoSize</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextFormat</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.ui</span><span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #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: #000000;">&#91;</span>Embed<span style="color: #000000;">&#40;</span><span style="color: #004993;">source</span> = <span style="color: #990000;">&quot;carscene.f3d&quot;</span><span style="color: #000066; font-weight: bold;">,</span> mimeType = <span style="color: #990000;">&quot;application/octet-stream&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> embeddedScene<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Class</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> scene<span style="color: #000066; font-weight: bold;">:</span>Scene3D<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> physics<span style="color: #000066; font-weight: bold;">:</span>PhysicsSystemManager<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> wheelFL<span style="color: #000066; font-weight: bold;">:</span>Pivot3D<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> wheelFR<span style="color: #000066; font-weight: bold;">:</span>Pivot3D<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> wheelRL<span style="color: #000066; font-weight: bold;">:</span>Pivot3D<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> wheelRR<span style="color: #000066; font-weight: bold;">:</span>Pivot3D<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> carBody<span style="color: #000066; font-weight: bold;">:</span>PhysicsVehicle<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> chassis<span style="color: #000066; font-weight: bold;">:</span>Pivot3D<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: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			scene = <span style="color: #0033ff; font-weight: bold;">new</span> Viewer3D<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">&quot;without_this_embed_wont_work.f3d&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			scene<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>Scene3D<span style="color: #000066; font-weight: bold;">.</span>COMPLETE_EVENT<span style="color: #000066; font-weight: bold;">,</span> completeEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			physics=PhysicsSystemManager<span style="color: #000066; font-weight: bold;">.</span>getInstance<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;">int</span><span style="color: #000066; font-weight: bold;">;</span>i<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">20</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> boxMaterial<span style="color: #000066; font-weight: bold;">:</span>Shader3D=<span style="color: #0033ff; font-weight: bold;">new</span> Shader3D<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;&quot;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000;">&#91;</span><span style="color: #0033ff; font-weight: bold;">new</span> ColorFilter<span style="color: #000000;">&#40;</span>0xc86464<span style="color: #000000;">&#41;</span><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> cube<span style="color: #000066; font-weight: bold;">:</span>Cube=<span style="color: #0033ff; font-weight: bold;">new</span> Cube<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;box&quot;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">5</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">5</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">5</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span>boxMaterial<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				cube<span style="color: #000066; font-weight: bold;">.</span>setPosition<span style="color: #000000;">&#40;</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;">0.5</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">5</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">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;">0.5</span><span style="color: #000000;">&#41;</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>
				scene<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>cube<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				cube<span style="color: #000066; font-weight: bold;">.</span>addComponent<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> PhysicsBox<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: #6699cc; font-weight: bold;">var</span> controls<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextField</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			controls<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">autoSize</span>=<span style="color: #004993;">TextFieldAutoSize</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">LEFT</span><span style="color: #000066; font-weight: bold;">;</span>
			controls<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">defaultTextFormat</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextFormat</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Arial&quot;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">12</span><span style="color: #000066; font-weight: bold;">,</span>0xffffff<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>controls<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			controls<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">htmlText</span> = <span style="color: #990000;">&quot;ARROWS KEY: control the car&quot;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">fromCharCode</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">13</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;SPACE: handbrake&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">fromCharCode</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">13</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;F1: reset position&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
			controls<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span>=<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span>stageHeight<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">53</span><span style="color: #000066; font-weight: bold;">;</span>
			scene<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">pause</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> processCar<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>
			chassis=scene<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;chassis&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			chassis<span style="color: #000066; font-weight: bold;">.</span>addComponent<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> PhysicsBox<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>
			scene<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Sphere01&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>addComponent<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> PhysicsSphere<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>
			carBody=<span style="color: #0033ff; font-weight: bold;">new</span> PhysicsVehicle<span style="color: #000000;">&#40;</span>chassis<span style="color: #000066; font-weight: bold;">.</span>components<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;">as</span> RigidBody<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">40</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">2.5</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">2000</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			carBody<span style="color: #000066; font-weight: bold;">.</span>chassis<span style="color: #000066; font-weight: bold;">.</span>mass=<span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span>
			carBody<span style="color: #000066; font-weight: bold;">.</span>chassis<span style="color: #000066; font-weight: bold;">.</span>setPosition<span style="color: #000000;">&#40;</span>chassis<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span> chassis<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span> chassis<span style="color: #000066; font-weight: bold;">.</span>z<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> chassisPos<span style="color: #000066; font-weight: bold;">:</span>Vector3D=chassis<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>
			wheelFL=scene<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;FL_tire&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			carBody<span style="color: #000066; font-weight: bold;">.</span>addWheel<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;1&quot;</span><span style="color: #000066; font-weight: bold;">,</span> wheelFL<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>
			wheelFR=scene<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;FR_tire&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			carBody<span style="color: #000066; font-weight: bold;">.</span>addWheel<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;2&quot;</span><span style="color: #000066; font-weight: bold;">,</span> wheelFR<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>
			wheelRL=scene<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;RL_tire&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			carBody<span style="color: #000066; font-weight: bold;">.</span>addWheel<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;3&quot;</span><span style="color: #000066; font-weight: bold;">,</span> wheelRL<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			wheelRR=scene<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;RR_tire&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			carBody<span style="color: #000066; font-weight: bold;">.</span>addWheel<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;4&quot;</span><span style="color: #000066; font-weight: bold;">,</span> wheelRR<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			physics<span style="color: #000066; font-weight: bold;">.</span>addVehicle<span style="color: #000000;">&#40;</span>carBody<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> completeEvent<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> planet<span style="color: #000066; font-weight: bold;">:</span>Flare3DLoader = <span style="color: #0033ff; font-weight: bold;">new</span> Flare3DLoader<span style="color: #000000;">&#40;</span> embeddedScene <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			planet<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">parent</span> = scene<span style="color: #000066; font-weight: bold;">;</span>
			planet<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">load</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> <span style="color: #004993;">floor</span><span style="color: #000066; font-weight: bold;">:</span>Pivot3D=scene<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;floor&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> floorPhysics<span style="color: #000066; font-weight: bold;">:</span> RigidBody = <span style="color: #0033ff; font-weight: bold;">new</span> PhysicsPlane<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">floor</span><span style="color: #000066; font-weight: bold;">.</span>addComponent<span style="color: #000000;">&#40;</span>floorPhysics<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			processCar<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			scene<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> Scene3D<span style="color: #000066; font-weight: bold;">.</span>UPDATE_EVENT<span style="color: #000066; font-weight: bold;">,</span> updateEvent <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			scene<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">resume</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> updateEvent<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span> = <span style="color: #0033ff; font-weight: bold;">null</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>
			carBody<span style="color: #000066; font-weight: bold;">.</span>setAccelerate<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			carBody<span style="color: #000066; font-weight: bold;">.</span>setSteer<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			carBody<span style="color: #000066; font-weight: bold;">.</span>setHBrake<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">false</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>Input3D<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">keyDown</span><span style="color: #000000;">&#40;</span>Input3D<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">UP</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				carBody<span style="color: #000066; font-weight: bold;">.</span>setAccelerate<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: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>Input3D<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">keyDown</span><span style="color: #000000;">&#40;</span>Input3D<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">DOWN</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				carBody<span style="color: #000066; font-weight: bold;">.</span>setAccelerate<span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">0.5</span><span style="color: #000000;">&#41;</span><span style="color: #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>Input3D<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">keyDown</span><span style="color: #000000;">&#40;</span>Input3D<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">LEFT</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				carBody<span style="color: #000066; font-weight: bold;">.</span>setSteer<span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #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>Input3D<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">keyDown</span><span style="color: #000000;">&#40;</span>Input3D<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">RIGHT</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				carBody<span style="color: #000066; font-weight: bold;">.</span>setSteer<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: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>Input3D<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">keyDown</span><span style="color: #000000;">&#40;</span>Input3D<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">SPACE</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				carBody<span style="color: #000066; font-weight: bold;">.</span>setHBrake<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>Input3D<span style="color: #000066; font-weight: bold;">.</span>keyHit<span style="color: #000000;">&#40;</span>Input3D<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">F1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				carBody<span style="color: #000066; font-weight: bold;">.</span>chassis<span style="color: #000066; font-weight: bold;">.</span>setPosition<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;">2</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				carBody<span style="color: #000066; font-weight: bold;">.</span>chassis<span style="color: #000066; font-weight: bold;">.</span>setOrientation<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> Matrix3D<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>
				carBody<span style="color: #000066; font-weight: bold;">.</span>chassis<span style="color: #000066; font-weight: bold;">.</span>setActive<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
			physics<span style="color: #000066; font-weight: bold;">.</span>step<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			Pivot3DUtils<span style="color: #000066; font-weight: bold;">.</span>setPositionWithReference<span style="color: #000000;">&#40;</span>scene<span style="color: #000066; font-weight: bold;">.</span>camera<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;">10</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>chassis<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0.1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			Pivot3DUtils<span style="color: #000066; font-weight: bold;">.</span>lookAtWithReference<span style="color: #000000;">&#40;</span>scene<span style="color: #000066; font-weight: bold;">.</span>camera<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">,</span>chassis<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>Which once executed gives this result:</p>
<p><iframe width = "640" height = "480" frameborder = "0" scrolling="no" src = "http://www.emanueleferonato.com/wp-content/uploads/2011/12/flare/flare.html" ></iframe></p>
<p>And now you have your <a href="http://www.emanueleferonato.com/2011/04/18/the-making-of-a-small-car-a-3d-flash-game-made-with-flare3d/">A Small Car</a> prototype in just a few lines.</p>
<p><a href="/wp-content/uploads/2011/12/flare.zip">Download the source code with all required libraries</a> and enjoy 3D physics</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2011/12/29/flare3d-2-0-flare3d-physics-overview/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Manage saved games with StencylWorks</title>
		<link>http://www.emanueleferonato.com/2011/12/27/manage-saved-games-with-stencylworks/</link>
		<comments>http://www.emanueleferonato.com/2011/12/27/manage-saved-games-with-stencylworks/#comments</comments>
		<pubDate>Tue, 27 Dec 2011 10:11:28 +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=5004</guid>
		<description><![CDATA[How to use StencylWorks to manage saved games as the player progresses through the levels]]></description>
			<content:encoded><![CDATA[<p>Some days ago I showed you how to <a href="http://www.emanueleferonato.com/2011/12/13/create-awesome-flash-games-in-no-time-with-stencylworks-selecting-levels/">select level with StencylWorks</a>, but selecting levels is useless if your game does not keep track of player progresses unlocking new levels as previous levels have been completed.</p>
<p>And, even more important, you should be able to manage saved games so players won&#8217;t be forced to complete the game in a single session.</p>
<p>Two posts which explain how to do it respectively with AS2 and AS3 are <a href="http://www.emanueleferonato.com/2008/01/02/managing-savegames-with-flash-shared-objects/">managing savegames with Flash shared objects</a> and <a href="http://www.emanueleferonato.com/2008/12/28/understanding-as3-shared-objects/">understanding AS3 shared objects</a>.</p>
<p>Obviously, with StencylWorks everything is easier.</p>
<p>First, we start with the creation of another animation for the door actor, which now will have two animations (two static images in this case, but it&#8217;s the same for the scope of this post).</p>
<p>One for the open, clickable door which will bring us to an unlocked level, and one for the closed, not clickable door, which represents the locked levels.</p>
<p><img src="/wp-content/uploads/2011/12/shared01.jpg" /></p>
<p>Then we have to create two game attributes. Game attributes are global variables which are accessible to every behavior. I am calling them &#8220;Highest Level Completed&#8221; and &#8220;Current Level&#8221; and I will use them to store respectively the number of the highest level completed and the current level being played. Both attributes have a starting value of zero.</p>
<p>Using game attributes for this purpose is very important, as StencylWorks allows you to save and load all game attributes.</p>
<p><img src="/wp-content/uploads/2011/12/shared02.jpg" /></p>
<p>Now we need to create a behavior to load game attributes, which should be executed as soon as possible, so you&#8217;d better bind it to the splash screen. It&#8217;s very easy as StencylWorks has a &#8220;load save file&#8221; block.</p>
<p><img src="/wp-content/uploads/2011/12/shared03.jpg" /></p>
<p>Now, the hardest task: show open gates for playable levels and make them clickable, and closed gates for unplayable levels. Modify the &#8220;Click to play level&#8221; behavior I showed you in <a href="http://www.emanueleferonato.com/2011/12/13/create-awesome-flash-games-in-no-time-with-stencylworks-selecting-levels/">create awesome Flash games in no time with StencylWorks &#8211; Selecting levels</a> this way:</p>
<p><img src="/wp-content/uploads/2011/12/shared04.jpg" /></p>
<p>Let&#8217;s see what changed:</p>
<p>In the &#8220;always&#8221; block you can see the behavior has a new attribute called &#8220;level number&#8221; and it can be clicked only if the value of &#8220;Highest Level Completed&#8221; game attribute is greater or equal than &#8220;level number&#8221; attribute.</p>
<p>If it&#8217;s true, then we set &#8220;Current Level&#8221; game attribute to &#8220;level number&#8221; value and we make the player to to the level.</p>
<p>The &#8220;when drawing&#8221; block will also check for &#8220;Highest Level Completed&#8221; game attribute to be greater or equal to &#8220;level number&#8221; attribute, and will show the &#8220;Open&#8221; door animation, along with the level number, if true. Otherwise, the &#8220;Closed&#8221; door animation will be shown.</p>
<p>At this time, we have to customize the behavior of each door, just like you made in the <a href="http://www.emanueleferonato.com/2011/12/13/create-awesome-flash-games-in-no-time-with-stencylworks-selecting-levels/">previous step</a>, this time setting also &#8220;level number&#8221; attribute to zero for level one, then one for level two, and so on. </p>
<p><img src="/wp-content/uploads/2011/12/shared05.jpg" /></p>
<p>Finally, once the player completes a level, in this case when the player hits the door, we have to set &#8220;Highest Level Completed&#8221; game variable to the larger number between &#8220;Highest Level Completed&#8221; game variable itself and &#8220;Current Level&#8221; game variable.</p>
<p>Then, you can save the game. This way, &#8220;Highest Level Completed&#8221; variable will be locally saved, and made available once you launch the game again.</p>
<p><img src="/wp-content/uploads/2011/12/shared06.jpg" /></p>
<p>This is what you should see once you beat level two:</p>
<p><img src="/wp-content/uploads/2011/12/shared07.jpg" /></p>
<p>I am making a complete game without writing a single line of code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2011/12/27/manage-saved-games-with-stencylworks/feed/</wfw:commentRss>
		<slash:comments>8</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 13/18 queries in 0.037 seconds using disk: basic

Served from: www.emanueleferonato.com @ 2012-02-08 20:05:47 -->
