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

<channel>
	<title>Emanuele Feronato &#187; Users contributions</title>
	<atom:link href="http://www.emanueleferonato.com/category/users-contributions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.emanueleferonato.com</link>
	<description>italian geek and PROgrammer</description>
	<lastBuildDate>Thu, 02 Sep 2010 09:32:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Worms-like destructible terrain in Flash &#8211; Part 3</title>
		<link>http://www.emanueleferonato.com/2010/08/18/worms-like-destructible-terrain-in-flash-part-3/</link>
		<comments>http://www.emanueleferonato.com/2010/08/18/worms-like-destructible-terrain-in-flash-part-3/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 18:30:32 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3247</guid>
		<description><![CDATA[After another truck of Aspirin, Jordi Sanglas Molist is back with the 3rd step of his Worms tutorial. I&#8217;ve finished part 3. I almost got a headache. Forgive me if there are some mistakes, I wrote this post and the comments quickly. Now the character is affected by the explosions. To do that, I added [...]]]></description>
			<content:encoded><![CDATA[<p>After another truck of Aspirin, <strong>Jordi Sanglas Molist</strong> is back with the 3rd step of his Worms tutorial.</p>
<p>I&#8217;ve finished part 3. I almost got a headache. Forgive me if there are some mistakes, I wrote this post and the comments quickly.</p>
<p>Now the character is affected by the explosions. To do that, I added an horizontal speed and a friction. However, I don&#8217;t want the character to slide when I&#8217;m using the arrow keys, so:</p>
<p>* The arrow keys won&#8217;t use horizontal speed<br />
* If the horizontal speed is different than 0 (an explosion is moving the character), I can&#8217;t use the arrow keys</p>
<p>To calculate the impulse, we will need to use trigonometry: </p>
<p><img src="/wp-content/uploads/2010/08/WormsPrototype_trigonometry.png"  /></p>
<p>I&#8217;ve also solved another bug: if the character was falling (without using the space bar), it could jump in the air. Here I removed the jumping variable and I check if the character is on the ground.</p>
<p>Pay attention!!! Sometimes I check if the character is ON the ground (<code>character.y+10</code>) and sometimes I check if the character is TOUCHING the ground (<code>character.y+9</code>).</p>
<p>KNOWN BUGS:</p>
<p>* The horizontal speed won&#8217;t decrease faster or more slowly if the character is on a slope.<br />
* The <code>for</code> loop isn&#8217;t exact when the horizontal speed is a decimal number (I think).</p>
<p>What should I do in the next part? I must do it before I start school, or I won&#8217;t have time.</p>
<p>While you think about the next part to request, here it is the script:<span id="more-3247"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
</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: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Bitmap</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">BitmapData</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">BlendMode</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span>.<span style="color: #004993;">Point</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span>.<span style="color: #004993;">Rectangle</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span>.<span style="color: #004993;">Matrix</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">MouseEvent</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">KeyboardEvent</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> worms extends <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> terrain_bmpd<span style="color: #000000; 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;">550</span>,<span style="color: #000000; font-weight:bold;">200</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,0xFF00FF00<span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> terrain_bmp<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Bitmap</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Bitmap</span><span style="color: #000000;">&#40;</span>terrain_bmpd<span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> character<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> x_speed<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">0</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> y_speed<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">0</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> hole<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> hole_matrix<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Matrix</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> left_key<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> right_key<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> space_key<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> x_diff<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;<span style="color: #009900;">//x_diff and y_diff will be the difference between the character and the explosion centre</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> y_diff<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> explosion_radius<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">100</span>;<span style="color: #009900;">//That's the radius of the explosion. If the character is inside the radius, it will move away.</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> explosion_intensity<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">10</span>;<span style="color: #009900;">//The explosion intensity is the speed (pixels/frame) that the character will</span>
		<span style="color: #009900;">//get if the distance between the explosion and the character is 0 (the closest one).</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">distance</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;<span style="color: #009900;">//We will use that variable to store the distance between the character and the explosion</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">angle</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;<span style="color: #009900;">//and that one to store the angle</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> applied_speed<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;<span style="color: #009900;">//That will be the total speed we need to apply (the vector length).</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> applied_x<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;<span style="color: #009900;">//Then, we will separate the applied_speed in applied_x</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> applied_y<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;<span style="color: #009900;">//and applied_y</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> ground_friction<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">0.2</span>;<span style="color: #009900;">//The ground has more friction than the air,</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> air_friction<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">0.05</span>;<span style="color: #009900;">//so I have used different variables</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> worms<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			draw_objects<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">ENTER_FRAME</span>,move_character<span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">MOUSE_UP</span>,mouse_up<span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">KeyboardEvent</span>.<span style="color: #004993;">KEY_DOWN</span>,key_down<span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">KeyboardEvent</span>.<span style="color: #004993;">KEY_UP</span>,key_up<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> move_character<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</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>left_key<span style="color: #000000; font-weight: bold;">&amp;&amp;</span>x_speed==<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">//If the player is moving, we won't be able to control it</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>; i<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">3</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span> terrain_bmpd.<span style="color: #004993;">hitTest</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>terrain_bmp.<span style="color: #004993;">x</span>,terrain_bmp.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>,0x01,<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span>character.x<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">6</span>,character.y<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">17</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>
						character.x<span style="color: #000000; font-weight: bold;">--</span>;
						<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>terrain_bmpd.<span style="color: #004993;">hitTest</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>terrain_bmp.<span style="color: #004993;">x</span>,terrain_bmp.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>,0x01,<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span>character.x<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">5</span>,character.<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">9</span>,<span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							character.y<span style="color: #000000; font-weight: bold;">--</span>;
						<span style="color: #000000;">&#125;</span>
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>right_key<span style="color: #000000; font-weight: bold;">&amp;&amp;</span>x_speed==<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">//Let's do the same with the right key...</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>; i<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">3</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span> terrain_bmpd.<span style="color: #004993;">hitTest</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>terrain_bmp.<span style="color: #004993;">x</span>,terrain_bmp.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>,0x01,<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span>character.<span style="color: #004993;">x</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">5</span>,character.y<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">17</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>
						character.<span style="color: #004993;">x</span><span style="color: #000000; font-weight: bold;">++</span>;
						<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>terrain_bmpd.<span style="color: #004993;">hitTest</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>terrain_bmp.<span style="color: #004993;">x</span>,terrain_bmp.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>,0x01,<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span>character.x<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">5</span>,character.<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">9</span>,<span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							character.y<span style="color: #000000; font-weight: bold;">--</span>;
						<span style="color: #000000;">&#125;</span>
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>x_speed<span style="color: #000000; 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: #009900;">//This block is similar; however, we don't know the speed,</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>; i<span style="color: #000000; font-weight: bold;">&lt;</span>Math.<span style="color: #004993;">abs</span><span style="color: #000000;">&#40;</span>x_speed<span style="color: #000000;">&#41;</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">//so the for loop will use x_speed (there's a bug, read KNOWN BUGS)</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span> terrain_bmpd.<span style="color: #004993;">hitTest</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>terrain_bmp.<span style="color: #004993;">x</span>,terrain_bmp.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>,0x01,<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span>character.x<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">6</span>,character.y<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">17</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>
						character.x<span style="color: #000000; font-weight: bold;">--</span>;
						<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>terrain_bmpd.<span style="color: #004993;">hitTest</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>terrain_bmp.<span style="color: #004993;">x</span>,terrain_bmp.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>,0x01,<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span>character.x<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">5</span>,character.<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">9</span>,<span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							character.y<span style="color: #000000; 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: #009900;">//If the player hits a wall, it must stop(!). Otherwise, when the wall is removed,</span>
						<span style="color: #009900;">//the player will continue moving</span>
						x_speed=<span style="color: #000000; font-weight:bold;">0</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;">else</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">//That's the same, but with left key</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>; i<span style="color: #000000; font-weight: bold;">&lt;</span>x_speed; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span> terrain_bmpd.<span style="color: #004993;">hitTest</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>terrain_bmp.<span style="color: #004993;">x</span>,terrain_bmp.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>,0x01,<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span>character.<span style="color: #004993;">x</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">5</span>,character.y<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">17</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>
						character.<span style="color: #004993;">x</span><span style="color: #000000; font-weight: bold;">++</span>;
						<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>terrain_bmpd.<span style="color: #004993;">hitTest</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>terrain_bmp.<span style="color: #004993;">x</span>,terrain_bmp.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>,0x01,<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span>character.x<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">5</span>,character.<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">9</span>,<span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							character.y<span style="color: #000000; 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>
						x_speed=<span style="color: #000000; font-weight:bold;">0</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>space_key<span style="color: #000000; font-weight: bold;">&amp;&amp;</span>terrain_bmpd.<span style="color: #004993;">hitTest</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>terrain_bmp.<span style="color: #004993;">x</span>,terrain_bmp.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>,0x01,<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span>character.x<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">5</span>,character.<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				y_speed=<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">10</span>;<span style="color: #009900;">//Instead of using the jumping variable, I check if the character is on the ground</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>terrain_bmpd.<span style="color: #004993;">hitTest</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>terrain_bmp.<span style="color: #004993;">x</span>,terrain_bmp.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>,0x01,<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span>character.x<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">5</span>,character.<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				x_speed<span style="color: #000000; font-weight: bold;">*</span>=<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000; font-weight: bold;">-</span>ground_friction;<span style="color: #009900;">//Again, I check if the character is on the ground (to apply ground or air friction)</span>
			<span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
				x_speed<span style="color: #000000; font-weight: bold;">*</span>=<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000; font-weight: bold;">-</span>air_friction;
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span>.<span style="color: #004993;">abs</span><span style="color: #000000;">&#40;</span>x_speed<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">0.1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				x_speed=<span style="color: #000000; font-weight:bold;">0</span>;
			<span style="color: #000000;">&#125;</span><span style="color: #3f5fbf;">/*I don't want the character to move at 0.0000000001 pixels/frame,
			so if the x_speed is less than 0.1 we will stop it*/</span>
			y_speed<span style="color: #000000; font-weight: bold;">++</span>;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>y_speed<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<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>; i<span style="color: #000000; font-weight: bold;">&lt;</span>y_speed; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span> terrain_bmpd.<span style="color: #004993;">hitTest</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>terrain_bmp.<span style="color: #004993;">x</span>,terrain_bmp.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>,0x01,<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span>character.x<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">5</span>,character.<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">//I changed character.y+9--&gt; character.y+10</span>
						character.<span style="color: #004993;">y</span><span style="color: #000000; 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>
						y_speed=<span style="color: #000000; font-weight:bold;">0</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;">else</span> <span style="color: #000000;">&#123;</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>; i<span style="color: #000000; font-weight: bold;">&lt;</span>Math.<span style="color: #004993;">abs</span><span style="color: #000000;">&#40;</span>y_speed<span style="color: #000000;">&#41;</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span> terrain_bmpd.<span style="color: #004993;">hitTest</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>terrain_bmp.<span style="color: #004993;">x</span>,terrain_bmp.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>,0x01,<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span>character.x<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">5</span>,character.y<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
						character.y<span style="color: #000000; 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>
						y_speed=<span style="color: #000000; font-weight:bold;">0</span>;
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> mouse_up<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			hole_matrix=<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>;
			hole_matrix.<span style="color: #004993;">translate</span><span style="color: #000000;">&#40;</span>e.stageX<span style="color: #000000; font-weight: bold;">-</span>terrain_bmp.<span style="color: #004993;">x</span>,e.stageY<span style="color: #000000; font-weight: bold;">-</span>terrain_bmp.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>;
			terrain_bmpd.<span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span>hole,hole_matrix,<span style="color: #0033ff; font-weight: bold;">null</span>,<span style="color: #004993;">BlendMode</span>.<span style="color: #004993;">ERASE</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">//Let's calculate the impulse. You'll have to understand trigonometric functions</span>
			x_diff=character.x<span style="color: #000000; font-weight: bold;">-</span>e.<span style="color: #004993;">stageX</span>;<span style="color: #009900;">//If we invert that, the character will move to the centre of the explosion instead of moving away</span>
			y_diff=character.y<span style="color: #000000; font-weight: bold;">-</span>e.<span style="color: #004993;">stageY</span>;
			<span style="color: #004993;">angle</span>=<span style="color: #004993;">Math</span>.<span style="color: #004993;">atan2</span><span style="color: #000000;">&#40;</span>y_diff,x_diff<span style="color: #000000;">&#41;</span>;<span style="color: #009900;">//We calculate the angle</span>
			<span style="color: #004993;">distance</span>=<span style="color: #004993;">Math</span>.<span style="color: #004993;">sqrt</span><span style="color: #000000;">&#40;</span>x_diff<span style="color: #000000; font-weight: bold;">*</span>x_diff<span style="color: #000000; font-weight: bold;">+</span>y_diff<span style="color: #000000; font-weight: bold;">*</span>y_diff<span style="color: #000000;">&#41;</span>;<span style="color: #009900;">//Then, we use Pythagorean theorem</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>distance<span style="color: #000000; font-weight: bold;">&lt;</span>explosion_radius<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				applied_speed = <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #004993;">distance</span> <span style="color: #000000; font-weight: bold;">/</span> explosion_radius<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">*</span> explosion_intensity;
				<span style="color: #009900;">//Maybe that's difficult to understand:</span>
				<span style="color: #009900;">//How_far_is_the_character = distance / explosion_radius</span>
				<span style="color: #009900;">//How_near_is_the_character = 1 - How_far_is_the_character</span>
				<span style="color: #009900;">//applied_speed = How_near_is_the_character * explosion_intensity</span>
&nbsp;
				applied_x=<span style="color: #004993;">Math</span>.<span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">*</span>applied_speed;<span style="color: #009900;">//We separate the applied_speed in x...</span>
				applied_y=<span style="color: #004993;">Math</span>.<span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">*</span>applied_speed;<span style="color: #009900;">//... and y</span>
				y_speed<span style="color: #000000; font-weight: bold;">+</span>=applied_y;
				x_speed<span style="color: #000000; font-weight: bold;">+</span>=applied_x;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> key_down<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">KeyboardEvent</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>e.<span style="color: #004993;">keyCode</span>==<span style="color: #000000; font-weight:bold;">37</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				left_key=<span style="color: #0033ff; font-weight: bold;">true</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #004993;">keyCode</span>==<span style="color: #000000; font-weight:bold;">39</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				right_key=<span style="color: #0033ff; font-weight: bold;">true</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #004993;">keyCode</span>==<span style="color: #000000; font-weight:bold;">32</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				space_key=<span style="color: #0033ff; font-weight: bold;">true</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> key_up<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">KeyboardEvent</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>e.<span style="color: #004993;">keyCode</span>==<span style="color: #000000; font-weight:bold;">37</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				left_key=<span style="color: #0033ff; font-weight: bold;">false</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #004993;">keyCode</span>==<span style="color: #000000; font-weight:bold;">39</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				right_key=<span style="color: #0033ff; font-weight: bold;">false</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #004993;">keyCode</span>==<span style="color: #000000; font-weight:bold;">32</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				space_key=<span style="color: #0033ff; font-weight: bold;">false</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> draw_objects<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			terrain_bmp.<span style="color: #004993;">y</span>=<span style="color: #000000; font-weight:bold;">200</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>terrain_bmp<span style="color: #000000;">&#41;</span>;
&nbsp;
			character.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span>0x0000FF<span style="color: #000000;">&#41;</span>;
			character.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">5</span>,<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000;">&#41;</span>;
			character.<span style="color: #004993;">x</span>=<span style="color: #000000; font-weight:bold;">250</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>character<span style="color: #000000;">&#41;</span>;
&nbsp;
			hole.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span>0x000000<span style="color: #000000;">&#41;</span>;
			hole.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">drawCircle</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">30</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>And this is the result:</p>
<p><embed src="/wp-content/uploads/2010/08/worms3.swf" allowscriptaccess="always" menu="false" quality="high" width="500" height="400" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>As usual, left and right to move the character, spacebar to make it jump and mouse click to create explosions.</p>
<p><a href="/wp-content/uploads/2010/08/worms3.zip">Download the source code</a> and don&#8217;t forget to request the next part.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/08/18/worms-like-destructible-terrain-in-flash-part-3/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Create Box2D levels in a quick with Bison Kick</title>
		<link>http://www.emanueleferonato.com/2010/08/16/create-box2d-levels-in-a-quick-with-bison-kick/</link>
		<comments>http://www.emanueleferonato.com/2010/08/16/create-box2d-levels-in-a-quick-with-bison-kick/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 21:41:38 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Box2D]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3235</guid>
		<description><![CDATA[Some time ago I published a Basic Box2D editor using Flash movieclips. Now it&#8217;s time to show you something way more interesting called Bison Kick by Jacob Schatz who runs the blog jacobschatz.com (bookmark it! It contains a lot of useful information). It&#8217;s an online Box2D editor with live preview. Besides it&#8217;s still under development, [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago I published a <a href="http://www.emanueleferonato.com/2010/07/12/basic-box2d-editor-using-flash-movieclips/">Basic Box2D editor using Flash movieclips</a>.</p>
<p>Now it&#8217;s time to show you something way more interesting called <strong><a target = "_blank" href="http://www.jacobschatz.com/bisonkick/">Bison Kick</a></strong> by <strong>Jacob Schatz</strong> who runs the blog <a href="http://jacobschatz.com/" target = "_blank">jacobschatz.com</a> (bookmark it! It contains a lot of useful information).</p>
<p><a target = "_blank" href="http://www.jacobschatz.com/bisonkick/"><img src="/wp-content/uploads/2010/08/bison.png" /></a></p>
<p>It&#8217;s an online Box2D editor with live preview.</p>
<p>Besides it&#8217;s still under development, with more options to be added and a few bugs to be removed, it&#8217;s very fun and simple to use.</p>
<p>I tried to design a level to be used in a game like Totem Destroyer and I managed to export it both in AS3:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900;">//order: x , y , height, width, rotation, isDynamic, shape, friction,density,restitution,ID </span>
 <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">map</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span>
<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">175</span>,<span style="color: #000000; font-weight:bold;">324</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'normal'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">325</span>,<span style="color: #000000; font-weight:bold;">325</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'normal'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">250</span>,<span style="color: #000000; font-weight:bold;">375</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">500</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">false</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'ground'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">250</span>,<span style="color: #000000; font-weight:bold;">275</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">300</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'normal'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">250</span>,<span style="color: #000000; font-weight:bold;">200</span>,<span style="color: #000000; font-weight:bold;">100</span>,<span style="color: #000000; font-weight:bold;">150</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'normal'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">125</span>,<span style="color: #000000; font-weight:bold;">225</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">2</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'heavy'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">250</span>,<span style="color: #000000; font-weight:bold;">125</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">2</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'heavy'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">375</span>,<span style="color: #000000; font-weight:bold;">225</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">2</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'heavy'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">250</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">100</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.25</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'totem'</span><span style="color: #000000;">&#93;</span>
<span style="color: #000000;">&#93;</span>;</pre></div></div>

<p>and in XML:<span id="more-3235"></span></p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;level&gt;
  &lt;completeShape&gt;
    &lt;xprop&gt;175&lt;/xprop&gt;
    &lt;yprop&gt;324&lt;/yprop&gt;
    &lt;height&gt;50&lt;/height&gt;
    &lt;width&gt;50&lt;/width&gt;
    &lt;rotation&gt;0&lt;/rotation&gt;
    &lt;isDynamic&gt;true&lt;/isDynamic&gt;
    &lt;shape&gt;SQUARE&lt;/shape&gt;
    &lt;physicsandID&gt;1,0.5,0.5,'normal'&lt;/physicsandID&gt;
  &lt;/completeShape&gt;
  &lt;completeShape&gt;
    &lt;xprop&gt;325&lt;/xprop&gt;
    &lt;yprop&gt;325&lt;/yprop&gt;
    &lt;height&gt;50&lt;/height&gt;
    &lt;width&gt;50&lt;/width&gt;
    &lt;rotation&gt;0&lt;/rotation&gt;
    &lt;isDynamic&gt;true&lt;/isDynamic&gt;
    &lt;shape&gt;SQUARE&lt;/shape&gt;
    &lt;physicsandID&gt;1,0.5,0.5,'normal'&lt;/physicsandID&gt;
  &lt;/completeShape&gt;
  &lt;completeShape&gt;
    &lt;xprop&gt;250&lt;/xprop&gt;
    &lt;yprop&gt;375&lt;/yprop&gt;
    &lt;height&gt;50&lt;/height&gt;
    &lt;width&gt;500&lt;/width&gt;
    &lt;rotation&gt;0&lt;/rotation&gt;
    &lt;isDynamic&gt;false&lt;/isDynamic&gt;
    &lt;shape&gt;SQUARE&lt;/shape&gt;
    &lt;physicsandID&gt;1,0.5,0.5,'ground'&lt;/physicsandID&gt;
  &lt;/completeShape&gt;
  &lt;completeShape&gt;
    &lt;xprop&gt;250&lt;/xprop&gt;
    &lt;yprop&gt;275&lt;/yprop&gt;
    &lt;height&gt;50&lt;/height&gt;
    &lt;width&gt;300&lt;/width&gt;
    &lt;rotation&gt;0&lt;/rotation&gt;
    &lt;isDynamic&gt;true&lt;/isDynamic&gt;
    &lt;shape&gt;SQUARE&lt;/shape&gt;
    &lt;physicsandID&gt;1,0.5,0.5,'normal'&lt;/physicsandID&gt;
  &lt;/completeShape&gt;
  &lt;completeShape&gt;
    &lt;xprop&gt;250&lt;/xprop&gt;
    &lt;yprop&gt;200&lt;/yprop&gt;
    &lt;height&gt;100&lt;/height&gt;
    &lt;width&gt;150&lt;/width&gt;
    &lt;rotation&gt;0&lt;/rotation&gt;
    &lt;isDynamic&gt;true&lt;/isDynamic&gt;
    &lt;shape&gt;SQUARE&lt;/shape&gt;
    &lt;physicsandID&gt;1,0.5,0.5,'normal'&lt;/physicsandID&gt;
  &lt;/completeShape&gt;
  &lt;completeShape&gt;
    &lt;xprop&gt;125&lt;/xprop&gt;
    &lt;yprop&gt;225&lt;/yprop&gt;
    &lt;height&gt;50&lt;/height&gt;
    &lt;width&gt;50&lt;/width&gt;
    &lt;rotation&gt;0&lt;/rotation&gt;
    &lt;isDynamic&gt;true&lt;/isDynamic&gt;
    &lt;shape&gt;SQUARE&lt;/shape&gt;
    &lt;physicsandID&gt;1,2,0.5,'heavy'&lt;/physicsandID&gt;
  &lt;/completeShape&gt;
  &lt;completeShape&gt;
    &lt;xprop&gt;250&lt;/xprop&gt;
    &lt;yprop&gt;125&lt;/yprop&gt;
    &lt;height&gt;50&lt;/height&gt;
    &lt;width&gt;50&lt;/width&gt;
    &lt;rotation&gt;0&lt;/rotation&gt;
    &lt;isDynamic&gt;true&lt;/isDynamic&gt;
    &lt;shape&gt;SQUARE&lt;/shape&gt;
    &lt;physicsandID&gt;1,2,0.5,'heavy'&lt;/physicsandID&gt;
  &lt;/completeShape&gt;
  &lt;completeShape&gt;
    &lt;xprop&gt;375&lt;/xprop&gt;
    &lt;yprop&gt;225&lt;/yprop&gt;
    &lt;height&gt;50&lt;/height&gt;
    &lt;width&gt;50&lt;/width&gt;
    &lt;rotation&gt;0&lt;/rotation&gt;
    &lt;isDynamic&gt;true&lt;/isDynamic&gt;
    &lt;shape&gt;SQUARE&lt;/shape&gt;
    &lt;physicsandID&gt;1,2,0.5,'heavy'&lt;/physicsandID&gt;
  &lt;/completeShape&gt;
  &lt;completeShape&gt;
    &lt;xprop&gt;250&lt;/xprop&gt;
    &lt;yprop&gt;50&lt;/yprop&gt;
    &lt;height&gt;100&lt;/height&gt;
    &lt;width&gt;50&lt;/width&gt;
    &lt;rotation&gt;0&lt;/rotation&gt;
    &lt;isDynamic&gt;true&lt;/isDynamic&gt;
    &lt;shape&gt;SQUARE&lt;/shape&gt;
    &lt;physicsandID&gt;1,0.25,0.5,'totem'&lt;/physicsandID&gt;
  &lt;/completeShape&gt;
&lt;/level&gt;</pre></div></div>

<p>Then, creating a Box2D world from these data was really easy thanks to the <a href="http://jacobschatz.com/?p=117">snippet of code</a> provided by Jacob:</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
</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.Dynamics.Joints.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">KeyboardEvent</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Dynamics.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Collision.Shapes.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D.Common.<span style="color: #004993;">Math</span>.<span style="color: #000000; font-weight: bold;">*</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main extends <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> world<span style="color: #000000; 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: #000000; font-weight:bold;">10.0</span><span style="color: #000000;">&#41;</span>,<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> world_scale<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">30</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> static const <span style="color: #004993;">SQUARE</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;SQUARE&quot;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> static const CIRCLE<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;CIRCLE&quot;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> fixtureDef<span style="color: #000000; 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>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> specialB2Body<span style="color: #000000; font-weight: bold;">:</span>b2Body;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> motorOn<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>;
&nbsp;
		<span style="color: #009900;">//order: x , y , height, width, rotation, isDynamic, shape, friction,density,restitution,ID </span>
 <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">map</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span>
<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">175</span>,<span style="color: #000000; font-weight:bold;">324</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'normal'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">325</span>,<span style="color: #000000; font-weight:bold;">325</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'normal'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">250</span>,<span style="color: #000000; font-weight:bold;">375</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">500</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">false</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'ground'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">250</span>,<span style="color: #000000; font-weight:bold;">275</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">300</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'normal'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">250</span>,<span style="color: #000000; font-weight:bold;">200</span>,<span style="color: #000000; font-weight:bold;">100</span>,<span style="color: #000000; font-weight:bold;">150</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'normal'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">125</span>,<span style="color: #000000; font-weight:bold;">225</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">2</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'heavy'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">250</span>,<span style="color: #000000; font-weight:bold;">125</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">2</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'heavy'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">375</span>,<span style="color: #000000; font-weight:bold;">225</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">2</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'heavy'</span><span style="color: #000000;">&#93;</span>
,<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">250</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">100</span>,<span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,<span style="color: #990000;">'SQUARE'</span> , <span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">0.25</span>,<span style="color: #000000; font-weight:bold;">0.5</span>,<span style="color: #990000;">'totem'</span><span style="color: #000000;">&#93;</span>
<span style="color: #000000;">&#93;</span>;		<span style="color: #009900;">//</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; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> 
		<span style="color: #000000;">&#123;</span>
			debug_draw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #004993;">map</span>.<span style="color: #004993;">length</span>; i<span style="color: #000000; 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> sx<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span>;
				<span style="color: #6699cc; font-weight: bold;">var</span> sy<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span>;
				<span style="color: #6699cc; font-weight: bold;">var</span> sizerh<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span>;
				<span style="color: #6699cc; font-weight: bold;">var</span> sizerw<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#93;</span>;
				<span style="color: #6699cc; font-weight: bold;">var</span> srot<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">4</span><span style="color: #000000;">&#93;</span>;
				<span style="color: #6699cc; font-weight: bold;">var</span> sIsDynamic<span style="color: #000000; font-weight: bold;">:*</span> = <span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">5</span><span style="color: #000000;">&#93;</span>;
				<span style="color: #6699cc; font-weight: bold;">var</span> sShape<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">6</span><span style="color: #000000;">&#93;</span>;
				<span style="color: #6699cc; font-weight: bold;">var</span> sFric<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">7</span><span style="color: #000000;">&#93;</span>;
				<span style="color: #6699cc; font-weight: bold;">var</span> sMass<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">8</span><span style="color: #000000;">&#93;</span>;
				<span style="color: #6699cc; font-weight: bold;">var</span> sRest<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">9</span><span style="color: #000000;">&#93;</span>;
				<span style="color: #6699cc; font-weight: bold;">var</span> boxId<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #004993;">map</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#93;</span>;
&nbsp;
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>sShape == <span style="color: #004993;">SQUARE</span><span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>	
					draw_box<span style="color: #000000;">&#40;</span>sx, sy, sizerw, sizerh, sIsDynamic,srot,sFric,sMass,sRest,boxId<span style="color: #000000;">&#41;</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>sShape == CIRCLE<span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					draw_circle<span style="color: #000000;">&#40;</span>sx, sy, sizerw <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span>, sIsDynamic,srot,sFric,sMass,sRest,boxId<span style="color: #000000;">&#41;</span>;
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">ENTER_FRAME</span>, update<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> draw_circle<span style="color: #000000;">&#40;</span>px<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, py<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, r<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, <span style="color: #004993;">d</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>, rot<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,
		fric<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,mass<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,rest<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,boxId<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> my_body<span style="color: #000000; 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>;
			my_body.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span>px <span style="color: #000000; font-weight: bold;">/</span> world_scale, py <span style="color: #000000; font-weight: bold;">/</span> world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">d</span><span style="color: #000000;">&#41;</span> 
			<span style="color: #000000;">&#123;</span>
				my_body.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #000000;">&#125;</span>
			my_body.<span style="color: #004993;">angle</span> = rot;
			<span style="color: #6699cc; font-weight: bold;">var</span> my_circle<span style="color: #000000; font-weight: bold;">:</span>b2CircleShape=<span style="color: #0033ff; font-weight: bold;">new</span> b2CircleShape<span style="color: #000000;">&#40;</span>r<span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> my_fixture<span style="color: #000000; 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>;
			my_fixture.density = mass;
			my_fixture.friction = fric;
			my_fixture.restitution = rest;
			my_fixture.shape=my_circle;
			<span style="color: #6699cc; font-weight: bold;">var</span> world_body<span style="color: #000000; font-weight: bold;">:</span>b2Body = world.CreateBody<span style="color: #000000;">&#40;</span>my_body<span style="color: #000000;">&#41;</span>;
			world_body.CreateFixture<span style="color: #000000;">&#40;</span>my_fixture<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> draw_box<span style="color: #000000;">&#40;</span>px<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, py<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, w<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, h<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, <span style="color: #004993;">d</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>, rot<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,
		fric<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,mass<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,rest<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>,boxId<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> my_body<span style="color: #000000; 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>;
&nbsp;
			my_body.<span style="color: #004993;">position</span>.Set<span style="color: #000000;">&#40;</span>px <span style="color: #000000; font-weight: bold;">/</span> world_scale, py <span style="color: #000000; font-weight: bold;">/</span> world_scale<span style="color: #000000;">&#41;</span>;
			my_body.<span style="color: #004993;">angle</span> = rot;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">d</span><span style="color: #000000;">&#41;</span> 
			<span style="color: #000000;">&#123;</span>
				my_body.<span style="color: #004993;">type</span>=b2Body.b2_dynamicBody;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> my_box<span style="color: #000000; 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>;
			my_box.SetAsBox<span style="color: #000000;">&#40;</span>w<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000; font-weight: bold;">/</span>world_scale, h<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000; font-weight: bold;">/</span>world_scale<span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> my_fixture<span style="color: #000000; 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>;
			my_fixture.density = mass;
			my_fixture.friction = fric;
			my_fixture.restitution = rest;
			my_fixture.shape=my_box;
			<span style="color: #6699cc; font-weight: bold;">var</span> world_body<span style="color: #000000; font-weight: bold;">:</span>b2Body=world.CreateBody<span style="color: #000000;">&#40;</span>my_body<span style="color: #000000;">&#41;</span>;
			world_body.CreateFixture<span style="color: #000000;">&#40;</span>my_fixture<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> debug_draw<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> debug_draw<span style="color: #000000; 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: #6699cc; font-weight: bold;">var</span> debug_sprite<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>debug_sprite<span style="color: #000000;">&#41;</span>;
			debug_draw.SetSprite<span style="color: #000000;">&#40;</span>debug_sprite<span style="color: #000000;">&#41;</span>;
			debug_draw.SetFillAlpha<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0.3</span><span style="color: #000000;">&#41;</span>;
			debug_draw.SetDrawScale<span style="color: #000000;">&#40;</span>world_scale<span style="color: #000000;">&#41;</span>;
			debug_draw.SetFlags<span style="color: #000000;">&#40;</span>b2DebugDraw.e_shapeBit<span style="color: #000000;">&#41;</span>;
			world.SetDebugDraw<span style="color: #000000;">&#40;</span>debug_draw<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> update<span style="color: #000000;">&#40;</span>e <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			world.Step<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">30</span>, <span style="color: #000000; font-weight:bold;">10</span>, <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span>;			
			world.ClearForces<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			world.DrawDebugData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>&#8230; and this is what you&#8217;ll get:</p>
<p><embed src="/wp-content/uploads/2010/08/bison.swf" allowscriptaccess="always" menu="false" quality="high" width="500" height="400" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>This the same scene of the screenshot you can see at the beginning of this post.</p>
<p>Next time, I&#8217;ll show you how to generate the same thing reading an external XML, and how to add more features.</p>
<p><a href="/wp-content/uploads/2010/08/bison.zip">Download the source code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/08/16/create-box2d-levels-in-a-quick-with-bison-kick/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Create your own tween manager class in AS3</title>
		<link>http://www.emanueleferonato.com/2010/08/09/create-your-own-tween-manager-class-in-as3/</link>
		<comments>http://www.emanueleferonato.com/2010/08/09/create-your-own-tween-manager-class-in-as3/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 19:40:53 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3220</guid>
		<description><![CDATA[I publish this tutorial with the permission of Krasimir Tsonev, from Bulgaria, who runs krasimirtsonev.com (take a look at the light bulbs: don&#8217;t you think it can be done using a basic Box2D rope?). It&#8217;s an amazing tutorial with clean and well commented code that will guide you through the process of the creation of [...]]]></description>
			<content:encoded><![CDATA[<p>I publish this tutorial with the permission of <strong>Krasimir Tsonev</strong>, from Bulgaria, who runs <a href="http://krasimirtsonev.com/" target = "_blank"><strong>krasimirtsonev.com</strong></a> (take a look at the light bulbs: don&#8217;t you think it can be done using a <a href="http://www.emanueleferonato.com/2009/10/05/basic-box2d-rope/">basic Box2D rope</a>?). It&#8217;s an amazing tutorial with clean and well commented code that will guide you through the process of the creation of a custom tween manager class with AS3.</p>
<p>There are some features in Flash that we can&#8217;t work without. Tween classes are among the most used ones. They give you ability to animate objects without using the timeline, to change the animation fast and easy. The idea of these classes is very simple. That&#8217;s why I think that it is a good idea to have your own tween manager that you can modify to fit into your needs.</p>
<p>The basic structure of our tween manager:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</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: #004993;">MovieClip</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> TweenManager extends <span style="color: #004993;">MovieClip</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _objectToModify<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _properties<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> TweenManager<span style="color: #000000;">&#40;</span>objectToModify<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span>, properties<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			_objectToModify = objectToModify;
			_properties = properties;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>We are going to pass the object that we want to modify and the properties that we want to change. The idea is to create a function that calls every frame. All the magic will be done there. As you can see in the code below I created a public function &#8211; start, which adds listener for ENTER_FRAME event. So now we have a repeated method, i.e. loop.<span id="more-3220"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</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: #004993;">MovieClip</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> TweenManager extends <span style="color: #004993;">MovieClip</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _objectToModify<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _properties<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> TweenManager<span style="color: #000000;">&#40;</span>objectToModify<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span>, properties<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			_objectToModify = objectToModify;
			_properties = properties;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">ENTER_FRAME</span>, <span style="color: #004993;">loop</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">loop</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>What are we going to pass as properties parameter? I think it is a good idea to use JSON object, because it&#8217;s really flexible and we can add/remove properties really fast without changing anything in our class. Here is an example of the creation of an object from our tween class.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</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: #004993;">MovieClip</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> App extends <span style="color: #004993;">MovieClip</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> clip<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MovieClip</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> App<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> properties<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = <span style="color: #000000;">&#123;</span><span style="color: #004993;">x</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000;">&#123;</span><span style="color: #004993;">start</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">50</span>,end<span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">390</span>,steps<span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> t<span style="color: #000000; font-weight: bold;">:</span>TweenManager = <span style="color: #0033ff; font-weight: bold;">new</span> TweenManager<span style="color: #000000;">&#40;</span>clip,properties<span style="color: #000000;">&#41;</span>;
			t.<span style="color: #004993;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>There are two things that you have to notice. The first one is that you should have a movie clip on the stage that you can use for the tween. The second thing is the properties object. As you can see we are going to change the &#8220;x&#8221; property of the clip from 50 to 390 for 100 steps, i.e. 100 frames. To be able to do that we need the value of &#8220;x&#8221; for each one of these 100 frames. The function &#8220;calculateValues&#8221; will do that for us:</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
</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: #004993;">MovieClip</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> TweenManager extends <span style="color: #004993;">MovieClip</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _objectToModify<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _properties<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> TweenManager<span style="color: #000000;">&#40;</span>objectToModify<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span>, properties<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			_objectToModify = objectToModify;
			_properties = properties;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:*</span> <span style="color: #0033ff; font-weight: bold;">in</span> _properties<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.values = calculateValues<span style="color: #000000;">&#40;</span>_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.<span style="color: #004993;">start</span>,_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.end,_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.steps<span style="color: #000000;">&#41;</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">ENTER_FRAME</span>, <span style="color: #004993;">loop</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">loop</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> calculateValues<span style="color: #000000;">&#40;</span>startPos<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, endPos<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, steps<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> values<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span>;
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">0</span>; i<span style="color: #000000; font-weight: bold;">&lt;</span>steps<span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				values.<span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>startPos <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>endPos <span style="color: #000000; font-weight: bold;">-</span> startPos<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">/</span> steps<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">*</span>i<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> values;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>As you can see we are adding dynamically a new array for every property in our properties object. &#8220;values&#8221; is an array with all the values of &#8220;x&#8221; for each of these 100 frames. The last thing that we should make is to pass the values to our clip, i.e. to write the content of the &#8220;loop&#8221; method.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #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: #004993;">MovieClip</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> TweenManager extends <span style="color: #004993;">MovieClip</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _objectToModify<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _properties<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> TweenManager<span style="color: #000000;">&#40;</span>objectToModify<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span>, properties<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			_objectToModify = objectToModify;
			_properties = properties;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:*</span> <span style="color: #0033ff; font-weight: bold;">in</span> _properties<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.values = calculateValues<span style="color: #000000;">&#40;</span>_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.<span style="color: #004993;">start</span>,_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.end,_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.steps<span style="color: #000000;">&#41;</span>;
				_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.valueIndex = <span style="color: #000000; font-weight:bold;">0</span>;
				_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.isItDone = <span style="color: #0033ff; font-weight: bold;">false</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">ENTER_FRAME</span>, <span style="color: #004993;">loop</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">loop</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">// looping through the properties  </span>
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:*</span> <span style="color: #0033ff; font-weight: bold;">in</span> _properties<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">// checking if the properties tween is done     </span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span> _properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.isItDone<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">// checking if the current value is the last one            </span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.valueIndex == _properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.steps <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">// marking the tween as a done </span>
						_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.isItDone = <span style="color: #0033ff; font-weight: bold;">true</span>;
					<span style="color: #000000;">&#125;</span>
					<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">// applying the value     </span>
						_objectToModify<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = _properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.values<span style="color: #000000;">&#91;</span>_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.valueIndex<span style="color: #000000;">&#93;</span>;<span style="color: #009900;">// incrementing the values' index </span>
						_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.valueIndex <span style="color: #000000; font-weight: bold;">+</span>=  <span style="color: #000000; font-weight:bold;">1</span>;
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span><span style="color: #009900;">// checking if all the tweens are done   </span>
			<span style="color: #6699cc; font-weight: bold;">var</span> areAllDone<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i <span style="color: #0033ff; font-weight: bold;">in</span> _properties<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span> _properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.isItDone<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					areAllDone = <span style="color: #0033ff; font-weight: bold;">false</span>;
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span><span style="color: #009900;">// if yes then remove the listener    </span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>areAllDone<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">ENTER_FRAME</span>, <span style="color: #004993;">loop</span><span style="color: #000000;">&#41;</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> calculateValues<span style="color: #000000;">&#40;</span>startPos<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, endPos<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, steps<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> values<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span>;
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">0</span>; i<span style="color: #000000; font-weight: bold;">&lt;</span>steps<span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				values.<span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>startPos <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>endPos <span style="color: #000000; font-weight: bold;">-</span> startPos<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">/</span> steps<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">*</span>i<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> values;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Please notice lines 18 and 19. We added a flag (isItDone) that indicates when the tween is finished and &#8220;valueIndex&#8221;, which we used to go through all the values.<br />
When you run the flash you will see that the circle is moving from x=50 to x=390 for 100 frames. Let&#8217;s add some other properties and see how it looks:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</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: #004993;">MovieClip</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> App extends <span style="color: #004993;">MovieClip</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> clip<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MovieClip</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> App<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> properties<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = <span style="color: #000000;">&#123;</span><span style="color: #004993;">x</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000;">&#123;</span><span style="color: #004993;">start</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">50</span>,end<span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">390</span>,steps<span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">70</span><span style="color: #000000;">&#125;</span>,<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000;">&#123;</span><span style="color: #004993;">start</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">50</span>,end<span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">390</span>,steps<span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">70</span><span style="color: #000000;">&#125;</span>,<span style="color: #004993;">rotation</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000;">&#123;</span><span style="color: #004993;">start</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">0</span>,end<span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">180</span>,steps<span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">30</span><span style="color: #000000;">&#125;</span>,<span style="color: #004993;">alpha</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000;">&#123;</span><span style="color: #004993;">start</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">1</span>,end<span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">0.5</span>,steps<span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> t<span style="color: #000000; font-weight: bold;">:</span>TweenManager = <span style="color: #0033ff; font-weight: bold;">new</span> TweenManager<span style="color: #000000;">&#40;</span>clip,properties<span style="color: #000000;">&#41;</span>;
			t.<span style="color: #004993;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>We can change as many properties as we want and obviously to set different steps for each one of them.</p>
<p>Ok, the Tween class looks good so far but it isn&#8217;t as cool as we wanted. It&#8217;s because there is no easing. We used only a linear type of motion. To add other types we&#8217;re going to use some maths by <a href="http://robertpenner.com/" target = "_blank">Robert Penner</a>. We will just change the calculateValues method and it will support different types of motions. Here is the final version of the class:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
</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: #004993;">MovieClip</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> TweenManager extends <span style="color: #004993;">MovieClip</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _objectToModify<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _properties<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> TweenManager<span style="color: #000000;">&#40;</span>objectToModify<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span>, properties<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			_objectToModify = objectToModify;
			_properties = properties;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:*</span> <span style="color: #0033ff; font-weight: bold;">in</span> _properties<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.values = calculateValues<span style="color: #000000;">&#40;</span>_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.<span style="color: #004993;">start</span>,_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.end,_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.steps,_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.<span style="color: #004993;">method</span><span style="color: #000000;">&#41;</span>;
				_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.valueIndex = <span style="color: #000000; font-weight:bold;">0</span>;
				_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.isItDone = <span style="color: #0033ff; font-weight: bold;">false</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">ENTER_FRAME</span>, <span style="color: #004993;">loop</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">loop</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">// looping through the properties          </span>
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:*</span> <span style="color: #0033ff; font-weight: bold;">in</span> _properties<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">// checking if the properies twee it's done </span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span> _properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.isItDone<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">// checking if the current value is the last one    </span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.valueIndex == _properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.steps <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">// marking the tween as a done          </span>
						_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.isItDone = <span style="color: #0033ff; font-weight: bold;">true</span>;
					<span style="color: #000000;">&#125;</span>
					<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">// applying the value </span>
						_objectToModify<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = _properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.values<span style="color: #000000;">&#91;</span>_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.valueIndex<span style="color: #000000;">&#93;</span>;<span style="color: #009900;">// incrementing the values' index     </span>
						_properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.valueIndex <span style="color: #000000; font-weight: bold;">+</span>=  <span style="color: #000000; font-weight:bold;">1</span>;
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span><span style="color: #009900;">// checking if all the tweens are done </span>
			<span style="color: #6699cc; font-weight: bold;">var</span> areAllDone<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i <span style="color: #0033ff; font-weight: bold;">in</span> _properties<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span> _properties<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.isItDone<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					areAllDone = <span style="color: #0033ff; font-weight: bold;">false</span>;
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span><span style="color: #009900;">// if yes then remove the listener  </span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>areAllDone<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">ENTER_FRAME</span>, <span style="color: #004993;">loop</span><span style="color: #000000;">&#41;</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> calculateValues<span style="color: #000000;">&#40;</span>startPos<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, endPos<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, steps<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>, mtd<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> arr<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> calcEndPos<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>;
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">0</span>; i<span style="color: #000000; font-weight: bold;">&lt;</span>=steps; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				calcEndPos = <span style="color: #000000;">&#40;</span>endPos<span style="color: #000000; font-weight: bold;">-</span>startPos<span style="color: #000000;">&#41;</span>;
				<span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>mtd<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;InBack&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.InBack<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps,<span style="color: #000000; font-weight:bold;">1.70158</span><span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;OutBack&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.OutBack<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps,<span style="color: #000000; font-weight:bold;">1.70158</span><span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;InOutBack&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.InOutBack<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps,<span style="color: #000000; font-weight:bold;">1.70158</span><span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;OutBounce&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.OutBounce<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;InBounce&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.InBounce<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;InOutBounce&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.InOutBounce<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;InCirc&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.InCirc<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;OutCirc&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.OutCirc<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;InOutCirc&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.InOutCirc<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;In&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.In<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;Out&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.Out<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;InOut&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.InOut<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;InElastic&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.InElastic<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;OutElastic&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.OutElastic<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;InOutElastic&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.InOutElastic<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;InExpo&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.InExpo<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;OutExpo&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.OutExpo<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;InOutExpo&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.InOutExpo<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;Linear&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.Linear<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;InLinear&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.InLinear<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;OutLinear&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.OutLinear<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;InOutLinear&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.InOutLinear<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;InQuad&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.InQuad<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;OutQuad&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.OutQuad<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;InOutQuad&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.InOutQuad<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;InQuart&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.InQuart<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;OutQuart&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.OutQuart<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;InOutQuart&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.InOutQuart<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;InQuint&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.InQuint<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;OutQuint&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.OutQuint<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;InOutQuint&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.InOutQuint<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;InSine&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.InQuint<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;OutSine&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.OutQuint<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;InOutSine&quot;</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.InOutQuint<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
					<span style="color: #0033ff; font-weight: bold;">default</span> <span style="color: #000000; font-weight: bold;">:</span>
						arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = Ease.Linear<span style="color: #000000;">&#40;</span>i,startPos,calcEndPos,steps<span style="color: #000000;">&#41;</span>;
						<span style="color: #0033ff; font-weight: bold;">break</span>;
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> arr;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>And the usage:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</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: #004993;">MovieClip</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> App extends <span style="color: #004993;">MovieClip</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> clip<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MovieClip</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> App<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> properties<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = <span style="color: #000000;">&#123;</span><span style="color: #004993;">x</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000;">&#123;</span><span style="color: #004993;">start</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">50</span>,end<span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">390</span>,steps<span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">170</span>,<span style="color: #004993;">method</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #990000;">&quot;OutBack&quot;</span><span style="color: #000000;">&#125;</span>,<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000;">&#123;</span><span style="color: #004993;">start</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">50</span>,end<span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">390</span>,steps<span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">170</span>,<span style="color: #004993;">method</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #990000;">&quot;OutBounce&quot;</span><span style="color: #000000;">&#125;</span>,<span style="color: #004993;">rotation</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000;">&#123;</span><span style="color: #004993;">start</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">0</span>,end<span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">180</span>,steps<span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">300</span>,<span style="color: #004993;">method</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #990000;">&quot;OutElastic&quot;</span><span style="color: #000000;">&#125;</span>,<span style="color: #004993;">alpha</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000;">&#123;</span><span style="color: #004993;">start</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">1</span>,end<span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">0.5</span>,steps<span style="color: #000000; font-weight: bold;">:</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> t<span style="color: #000000; font-weight: bold;">:</span>TweenManager = <span style="color: #0033ff; font-weight: bold;">new</span> TweenManager<span style="color: #000000;">&#40;</span>clip,properties<span style="color: #000000;">&#41;</span>;
			t.<span style="color: #004993;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Together with &#8220;start&#8221;, &#8220;end&#8221; and &#8220;steps&#8221; we are passing a new property &#8220;method&#8221; which is used by the &#8220;calculateValues&#8221; function. The class &#8220;Ease&#8221; contains mathematics methods that calculate the values. No need to understand it, just have to know how to use it.</p>
<p>And this is an example:</p>
<p><embed src="/wp-content/uploads/2010/08/tween.swf" allowscriptaccess="always" menu="false" quality="high" width="500" height="390" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>You may need to reload the page to see it in action.</p>
<p>Of course the class is not fully functional. I mean there are no checks if some of the properties like &#8220;start&#8221; or &#8220;end&#8221; are missing. We can also add an ability to call a callback method when some of the tweens finish. It&#8217;s just a basic manager that you can develop.</p>
<p><a href="/wp-content/uploads/2010/08/tween.zip">Download the source code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/08/09/create-your-own-tween-manager-class-in-as3/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Worms-like destructible terrain in Flash &#8211; Part 2</title>
		<link>http://www.emanueleferonato.com/2010/08/05/worms-like-destructible-terrain-in-flash-part-2/</link>
		<comments>http://www.emanueleferonato.com/2010/08/05/worms-like-destructible-terrain-in-flash-part-2/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 21:49:30 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3213</guid>
		<description><![CDATA[After having some troubles with the email, I am finally able to post Jordi Sanglas Molist&#8216;s second step of Worms-like destructible terrain in Flash. Now the character can jump and move. I&#8217;ve also solved a bug: in the last script I checked a collision using the feet, so if the terrain was between both feet [...]]]></description>
			<content:encoded><![CDATA[<p>After having some troubles with the email, I am finally able to post <strong>Jordi Sanglas Molist</strong>&#8216;s second step of <a href="http://www.emanueleferonato.com/2010/06/25/worms-like-destructible-terrain-in-flash/">Worms-like destructible terrain in Flash</a>.</p>
<p>Now the character can jump and move. I&#8217;ve also solved a bug: in the last script I checked a collision using the feet, so if the terrain was between both feet the character would fall.</p>
<p><img src="/wp-content/uploads/2010/08/WormsPrototype_bugSolved.png" /></p>
<p>Now, instead of using a hitTest between a BitmapData and a point I use a hitTest between a BitmapData and a Rectangle.</p>
<p>We have to check more collisions, so I used four rectangles:</p>
<p><img src="/wp-content/uploads/2010/08/WormsPrototype_rectangles.png" /></p>
<p>* The rectangle below the character is used to check if the character must fall</p>
<p>* The rectangle above the character is used to check if the character hit the ground (while he was jumping)</p>
<p>* The rectangles at the sides are used to check if the character can move.</p>
<p>These rectangles aren&#8217;t as long as the character, they&#8217;re 17 pixels height instead of 20. That&#8217;s because, if the character wants to move left and the obstacle isn&#8217;t high enough (high enough to reach the rectangle), the character will be able to move. A similar strategy is used in &#8220;<a href="http://www.emanueleferonato.com/2007/03/31/create-a-flash-draw-game-like-line-rider-or-others-part-5/">Create a flash draw game like line rider or others &#8211; part 5</a>&#8220;, where a point (the knee point) is used to check if the character can move.</p>
<p>I renamed the function &#8220;fall&#8221;: now it&#8217;s &#8220;move_character&#8221;. I only commented the new lines. Now I&#8217;m working on part 3, but I still don&#8217;t know how to calculate the explosion impulse. I looked for some information, but now I&#8217;m thinking about maths (an explosion is a growing circle).<span id="more-3213"></span></p>
<p>This is the 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
</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: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Bitmap</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">BitmapData</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">BlendMode</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span>.<span style="color: #004993;">Point</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span>.<span style="color: #004993;">Rectangle</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span>.<span style="color: #004993;">Matrix</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">MouseEvent</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">KeyboardEvent</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> worms extends <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> terrain_bmpd<span style="color: #000000; 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;">550</span>,<span style="color: #000000; font-weight:bold;">200</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,0xFF00FF00<span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> terrain_bmp<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Bitmap</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Bitmap</span><span style="color: #000000;">&#40;</span>terrain_bmpd<span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> character<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span>  ;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> character_speed<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span>=<span style="color: #000000; font-weight:bold;">0</span>;<span style="color: #009900;">//That number is the y speed that the character has</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> hole<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span>  ;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> hole_matrix<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Matrix</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> left_key<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> right_key<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> space_key<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> jumping<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">true</span>;<span style="color: #009900;">//When that variable is true, the character is in the air</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>;<span style="color: #009900;">//We will use this variable to make a loop</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> worms<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			draw_objects<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">ENTER_FRAME</span>,move_character<span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">MOUSE_UP</span>,mouse_up<span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">KeyboardEvent</span>.<span style="color: #004993;">KEY_DOWN</span>,key_down<span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">KeyboardEvent</span>.<span style="color: #004993;">KEY_UP</span>,key_up<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> move_character<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #009900;">//If left key is pressed, we'll move the character to the left</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>left_key<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>i=<span style="color: #000000; font-weight:bold;">0</span>; i<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">3</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">//Do you remember when we made the character fall? We had to move the character pixel by pixel</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span> terrain_bmpd.<span style="color: #004993;">hitTest</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>terrain_bmp.<span style="color: #004993;">x</span>,terrain_bmp.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>,0x01,<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span>character.x<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">6</span>,character.y<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">17</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>
						character.x<span style="color: #000000; font-weight: bold;">--</span>;	<span style="color: #3f5fbf;">/*If the character doesn't hit the ground, we can move left. However,
										the character may be sunk under the ground. We have to lift it*/</span>
						<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>terrain_bmpd.<span style="color: #004993;">hitTest</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>terrain_bmp.<span style="color: #004993;">x</span>,terrain_bmp.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>,0x01,<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span>character.x<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">5</span>,character.<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">9</span>,<span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							character.y<span style="color: #000000; font-weight: bold;">--</span>;
						<span style="color: #000000;">&#125;</span>
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>right_key<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">//Well, that's the same for the right key</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>; i<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">3</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span> terrain_bmpd.<span style="color: #004993;">hitTest</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>terrain_bmp.<span style="color: #004993;">x</span>,terrain_bmp.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>,0x01,<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span>character.<span style="color: #004993;">x</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">5</span>,character.y<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">1</span>,<span style="color: #000000; font-weight:bold;">17</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>
						character.<span style="color: #004993;">x</span><span style="color: #000000; font-weight: bold;">++</span>;
						<span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>terrain_bmpd.<span style="color: #004993;">hitTest</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>terrain_bmp.<span style="color: #004993;">x</span>,terrain_bmp.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>,0x01,<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span>character.x<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">5</span>,character.<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">9</span>,<span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
							character.y<span style="color: #000000; font-weight: bold;">--</span>;
						<span style="color: #000000;">&#125;</span>
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>space_key<span style="color: #000000; font-weight: bold;">&amp;&amp;!</span> jumping<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">//That's easy: if he isn't jumping and you press space, his speed will be negative and he'll jump</span>
				character_speed=<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">10</span>;
				jumping=<span style="color: #0033ff; font-weight: bold;">true</span>;<span style="color: #009900;">//Now the character can't jump again</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			character_speed<span style="color: #000000; font-weight: bold;">++</span>;<span style="color: #009900;">//Every frame we will increase character's speed</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>character_speed<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #009900;">//If the speed is positive, we will check a collision between the terrain and the rectangle below the character</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>; i<span style="color: #000000; font-weight: bold;">&lt;</span>character_speed; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">//We check the collision pixel by pixel...</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span> terrain_bmpd.<span style="color: #004993;">hitTest</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>terrain_bmp.<span style="color: #004993;">x</span>,terrain_bmp.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>,0x01,<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span>character.x<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">5</span>,character.<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">9</span>,<span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
						character.<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">++</span>;<span style="color: #009900;">//If there isn't a collision, the character will fall</span>
					<span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
						jumping=<span style="color: #0033ff; font-weight: bold;">false</span>;<span style="color: #009900;">//If there's a collision with the ground, the character isn't jumping</span>
						character_speed=<span style="color: #000000; font-weight:bold;">0</span>;<span style="color: #009900;">//The speed is 0, because the character hit the ground</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;">else</span> <span style="color: #000000;">&#123;</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>; i<span style="color: #000000; font-weight: bold;">&lt;</span>Math.<span style="color: #004993;">abs</span><span style="color: #000000;">&#40;</span>character_speed<span style="color: #000000;">&#41;</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">//If the speed is negative, the for loop won't work. We have to use Math.abs().</span>
				<span style="color: #009900;">//Now we will check the collision between the terrain and the rectangle above the character</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span> terrain_bmpd.<span style="color: #004993;">hitTest</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>terrain_bmp.<span style="color: #004993;">x</span>,terrain_bmp.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>,0x01,<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span>character.x<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">5</span>,character.y<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
						character.y<span style="color: #000000; 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>
						character_speed=<span style="color: #000000; font-weight:bold;">0</span>;<span style="color: #009900;">//Well, that's the same: the character hit the ground</span>
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> mouse_up<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			hole_matrix=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Matrix</span>  ;
			hole_matrix.<span style="color: #004993;">translate</span><span style="color: #000000;">&#40;</span>e.stageX<span style="color: #000000; font-weight: bold;">-</span>terrain_bmp.<span style="color: #004993;">x</span>,e.stageY<span style="color: #000000; font-weight: bold;">-</span>terrain_bmp.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>;
			terrain_bmpd.<span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span>hole,hole_matrix,<span style="color: #0033ff; font-weight: bold;">null</span>,<span style="color: #004993;">BlendMode</span>.<span style="color: #004993;">ERASE</span><span style="color: #000000;">&#41;</span>;
&nbsp;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> key_down<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">KeyboardEvent</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>e.<span style="color: #004993;">keyCode</span>==<span style="color: #000000; font-weight:bold;">37</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				left_key=<span style="color: #0033ff; font-weight: bold;">true</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #004993;">keyCode</span>==<span style="color: #000000; font-weight:bold;">39</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				right_key=<span style="color: #0033ff; font-weight: bold;">true</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #004993;">keyCode</span>==<span style="color: #000000; font-weight:bold;">32</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				space_key=<span style="color: #0033ff; font-weight: bold;">true</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> key_up<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">KeyboardEvent</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>e.<span style="color: #004993;">keyCode</span>==<span style="color: #000000; font-weight:bold;">37</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				left_key=<span style="color: #0033ff; font-weight: bold;">false</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #004993;">keyCode</span>==<span style="color: #000000; font-weight:bold;">39</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				right_key=<span style="color: #0033ff; font-weight: bold;">false</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #004993;">keyCode</span>==<span style="color: #000000; font-weight:bold;">32</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				space_key=<span style="color: #0033ff; font-weight: bold;">false</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> draw_objects<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			terrain_bmp.<span style="color: #004993;">y</span>=<span style="color: #000000; font-weight:bold;">200</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>terrain_bmp<span style="color: #000000;">&#41;</span>;
&nbsp;
			character.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span>0x0000FF<span style="color: #000000;">&#41;</span>;
			character.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">5</span>,<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000;">&#41;</span>;
			character.<span style="color: #004993;">x</span>=<span style="color: #000000; font-weight:bold;">250</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>character<span style="color: #000000;">&#41;</span>;
&nbsp;
			hole.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span>0x000000<span style="color: #000000;">&#41;</span>;
			hole.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">drawCircle</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">30</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>And this is the result:</p>
<p><embed src="/wp-content/uploads/2010/08/worms.swf" allowscriptaccess="always" menu="false" quality="high" width="500" height="400" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>Move the player with left &#8211; right arrow keys and click on the terrain to create an explosion.</p>
<p><a href="/wp-content/uploads/2010/08/worms.zip">Download the source code</a>. Now Jordi is trying to manage explosion impulse but he&#8217;s having some problems. Any blog-bomber reader willing to read?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/08/05/worms-like-destructible-terrain-in-flash-part-2/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Create a Flash racing game &#8211; Flex version</title>
		<link>http://www.emanueleferonato.com/2010/07/30/create-a-flash-racing-game-flex-version/</link>
		<comments>http://www.emanueleferonato.com/2010/07/30/create-a-flash-racing-game-flex-version/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 15:12:51 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3191</guid>
		<description><![CDATA[Hamilton Lombardi is a brazilian Flex programmer who decided to rewrite the code you can find in the original post for Flex 4. Moreover he added a splash screen, as you can see: The source code is clearly formatted and commented as you can see from Level class: 1 2 3 4 5 6 7 [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Hamilton Lombardi</strong> is a brazilian Flex programmer who decided to rewrite the code you can find in the <a href="http://www.emanueleferonato.com/2007/05/15/create-a-flash-racing-game-tutorial/">original post</a> for Flex 4.</p>
<p>Moreover he added a splash screen, as you can see:</p>
<p><embed src="/wp-content/uploads/2010/07/FlexRacer.swf" allowscriptaccess="always" menu="false" quality="high" width="510" height="410" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>The source code is clearly formatted and commented as you can see from <code>Level</code> class:<span id="more-3191"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
</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.geom</span>.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.media</span>.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span>.<span style="color: #000000; font-weight: bold;">*</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.utils</span>.<span style="color: #000000; font-weight: bold;">*</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> mx.containers.Canvas;
	<span style="color: #0033ff; font-weight: bold;">import</span> mx.controls.Alert;
	<span style="color: #0033ff; font-weight: bold;">import</span> mx.controls.Label;
	<span style="color: #0033ff; font-weight: bold;">import</span> mx.controls.Text;
	<span style="color: #0033ff; font-weight: bold;">import</span> mx.core.<span style="color: #000000; font-weight: bold;">*</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Level
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">protected</span> static <span style="color: #6699cc; font-weight: bold;">var</span> instance<span style="color: #000000; font-weight: bold;">:</span>Level = <span style="color: #0033ff; font-weight: bold;">null</span>;	
		<span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #6699cc; font-weight: bold;">var</span> player<span style="color: #000000; font-weight: bold;">:</span>Player = <span style="color: #0033ff; font-weight: bold;">null</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">track</span><span style="color: #000000; font-weight: bold;">:</span>Track = <span style="color: #0033ff; font-weight: bold;">null</span>;
&nbsp;
		<span style="color: #009900;">//this is the max number of laps</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> const totalLaps<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">3</span>;
&nbsp;
		<span style="color: #009900;">// Moment the race started</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> initialTime<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Date</span>;
		<span style="color: #009900;">// Current lap time</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> lapTime<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Date</span>;
		<span style="color: #009900;">// Current fastest lap</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> bestLap<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span>;
		<span style="color: #009900;">// Current lap number</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> currentLap<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span>;
		<span style="color: #009900;">// Current checkpoint - 1 Start Line , 2 - Mid track</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> currentCheckpoint<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">1</span>;
		<span style="color: #009900;">// History of all the lap times</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> raceHistory<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>;
&nbsp;
		static <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> Instance<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span>Level
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> instance == <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000000;">&#41;</span>
				instance = <span style="color: #0033ff; font-weight: bold;">new</span> Level<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">return</span> instance;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Level<span style="color: #000000;">&#40;</span>caller<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Function</span> = <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> Level.instance <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000000;">&#41;</span>
			<span style="color: #0033ff; font-weight: bold;">throw</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Error</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;Only one Singleton instance should be instantiated&quot;</span> <span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> startup<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #009900;">// Start all clock timers</span>
			startupTimeClocks<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #009900;">// Start time display</span>
			startupTimeDisplay<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #009900;">// Creates the race track</span>
			<span style="color: #004993;">track</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Track<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">track</span>.startupTrack<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;	
&nbsp;
			<span style="color: #009900;">// Creates the racer</span>
			player = <span style="color: #0033ff; font-weight: bold;">new</span> Player<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			player.startupPlayer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;			
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> shutdown<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>			
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">enterFrame</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #009900;">// Check if the lap had been completed</span>
			checkPoints<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #009900;">// Update total race time display</span>
			setTimes<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;				
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> setTimes<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> timeElapsed<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">milliseconds</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">seconds</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">minutes</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span>;
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> minutesTXT<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> secondsTXT<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> tensTXT<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span>;
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> totalTXT<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>;
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> totalTimeLabel<span style="color: #000000; font-weight: bold;">:</span>Label;
			<span style="color: #6699cc; font-weight: bold;">var</span> timeCanvas<span style="color: #000000; font-weight: bold;">:</span>Canvas;
&nbsp;
			<span style="color: #009900;">// Only starts the timer if the car cross the start line for the first time</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span>.currentLap <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #009900;">//we calculate the time elapsed from the moment the race started in millisecond</span>
				<span style="color: #6699cc; font-weight: bold;">var</span> thisTime<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Date</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
				timeElapsed = <span style="color: #000000;">&#40;</span>thisTime.<span style="color: #004993;">getTime</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">-</span> initialTime.<span style="color: #004993;">getTime</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
				<span style="color: #009900;">//we calculate the minutes, seconds and tens of seconds and set them to their respective variables</span>
				<span style="color: #004993;">milliseconds</span> = timeElapsed;
				<span style="color: #004993;">seconds</span> = <span style="color: #004993;">Math</span>.<span style="color: #004993;">floor</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">milliseconds</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">1000</span><span style="color: #000000;">&#41;</span>;
				<span style="color: #004993;">minutes</span> = <span style="color: #004993;">Math</span>.<span style="color: #004993;">floor</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">seconds</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000;">&#41;</span>;
				minutesTXT = <span style="color: #004993;">minutes</span>;
				secondsTXT = seconds<span style="color: #000000; font-weight: bold;">-</span><span style="color: #004993;">minutes</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">60</span>;
				tensTXT = <span style="color: #004993;">Math</span>.<span style="color: #004993;">round</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>milliseconds<span style="color: #000000; font-weight: bold;">-</span><span style="color: #004993;">seconds</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">1000</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span>;
				<span style="color: #009900;">//if the minutes, seconds or the tens of seconds number has only one character we add a &quot;0&quot; before it - that's just because we want the time to look good ;)</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>minutesTXT<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span> totalTXT = <span style="color: #990000;">&quot;0&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> minutesTXT;
				<span style="color: #0033ff; font-weight: bold;">else</span> totalTXT = <span style="color: #990000;">&quot;&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> minutesTXT;
&nbsp;
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>secondsTXT<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span> totalTXT = totalTXT <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;.&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;0&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> secondsTXT;
				<span style="color: #0033ff; font-weight: bold;">else</span> totalTXT = totalTXT <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;.&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> secondsTXT;
&nbsp;
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>tensTXT<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span> totalTXT = totalTXT <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;.&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;0&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> tensTXT;
				<span style="color: #0033ff; font-weight: bold;">else</span> totalTXT = totalTXT <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;.&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> tensTXT;
&nbsp;
				<span style="color: #009900;">//Update total time label </span>
				timeCanvas = FlexGlobals.topLevelApplication.timeDisplay;
				totalTimeLabel = <span style="color: #000000;">&#40;</span>Label<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#40;</span>timeCanvas.<span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;totalTimeTXT&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;			
				totalTimeLabel.<span style="color: #004993;">text</span> = totalTXT;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #009900;">//and the second function</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> setBestLap<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
			<span style="color: #009900;">//this function does the exact same thing as the first one, only here we will use the time elapsed from the last time the car has passed the finish line</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> currentTime<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Date</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> currentLap<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span>;
			currentLap = currentTime.<span style="color: #004993;">getTime</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">-</span> <span style="color: #0033ff; font-weight: bold;">this</span>.lapTime.<span style="color: #004993;">getTime</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">seconds</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">minutes</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span>;			
			<span style="color: #6699cc; font-weight: bold;">var</span> minutesTXT<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> secondsTXT<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> tensTXT<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span>;			
			<span style="color: #6699cc; font-weight: bold;">var</span> bestLapTXT<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> bestLapLabel<span style="color: #000000; font-weight: bold;">:</span>Label;
			<span style="color: #6699cc; font-weight: bold;">var</span> timeCanvas<span style="color: #000000; font-weight: bold;">:</span>Canvas;			
&nbsp;
			<span style="color: #004993;">seconds</span> = <span style="color: #004993;">Math</span>.<span style="color: #004993;">floor</span><span style="color: #000000;">&#40;</span>currentLap<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">1000</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">minutes</span> = <span style="color: #004993;">Math</span>.<span style="color: #004993;">floor</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">seconds</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000;">&#41;</span>;
			minutesTXT = <span style="color: #004993;">minutes</span>;
			secondsTXT = seconds<span style="color: #000000; font-weight: bold;">-</span><span style="color: #004993;">minutes</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">60</span>;
			tensTXT = <span style="color: #004993;">Math</span>.<span style="color: #004993;">round</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>currentLap<span style="color: #000000; font-weight: bold;">-</span><span style="color: #004993;">seconds</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">1000</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">//if the minutes, seconds or the tens of seconds number has only one character we add a &quot;0&quot; before it - that's just because we want the time to look good ;)</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>minutesTXT<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span> bestLapTXT = <span style="color: #990000;">&quot;0&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> minutesTXT;
			<span style="color: #0033ff; font-weight: bold;">else</span> bestLapTXT = <span style="color: #990000;">&quot;&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> minutesTXT;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>secondsTXT<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span> bestLapTXT = bestLapTXT <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;.&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;0&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> secondsTXT;
			<span style="color: #0033ff; font-weight: bold;">else</span> bestLapTXT = bestLapTXT <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;.&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> secondsTXT;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>tensTXT<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span> bestLapTXT = bestLapTXT <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;.&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;0&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> tensTXT;
			<span style="color: #0033ff; font-weight: bold;">else</span> bestLapTXT = bestLapTXT <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;.&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> tensTXT;
&nbsp;
			<span style="color: #009900;">//we don't calculate the lap time if the car passes the finish/start line for the first time</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span>.bestLap<span style="color: #000000; font-weight: bold;">&gt;</span>currentLap<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span>.bestLap == <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
				<span style="color: #0033ff; font-weight: bold;">this</span>.bestLap = currentLap;
				<span style="color: #009900;">//Update best lap time label </span>
				timeCanvas = FlexGlobals.topLevelApplication.timeDisplay;
				bestLapLabel = <span style="color: #000000;">&#40;</span>Label<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#40;</span>timeCanvas.<span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;bestLapTXT&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;			
				bestLapLabel.<span style="color: #004993;">text</span> = bestLapTXT;
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #009900;">// Save race history</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span>.raceHistory == <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">this</span>.raceHistory = <span style="color: #990000;">&quot;Lap: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #0033ff; font-weight: bold;">this</span>.currentLap <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; - &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> bestLapTXT <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\n</span>&quot;</span>;
			<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">this</span>.raceHistory = <span style="color: #0033ff; font-weight: bold;">this</span>.raceHistory  <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;Lap: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #0033ff; font-weight: bold;">this</span>.currentLap <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; - &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> bestLapTXT <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\n</span>&quot;</span>; 
&nbsp;
			<span style="color: #009900;">//we set the initial time to the moment the car passed the finish line </span>
			<span style="color: #0033ff; font-weight: bold;">this</span>.lapTime = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> checkPoints<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> 
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> currentLapTXT<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> currentLapLabel<span style="color: #000000; font-weight: bold;">:</span>Label;
			<span style="color: #6699cc; font-weight: bold;">var</span> timeCanvas<span style="color: #000000; font-weight: bold;">:</span>Canvas;
			<span style="color: #6699cc; font-weight: bold;">var</span> levelEndCanvas<span style="color: #000000; font-weight: bold;">:</span>Canvas;
			<span style="color: #6699cc; font-weight: bold;">var</span> historyText<span style="color: #000000; font-weight: bold;">:</span>Text;
&nbsp;
			<span style="color: #009900;">//we check to see if the car &quot;touches&quot; the checkpoint1 - start/finish line)</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>FlexGlobals.topLevelApplication.finishLine.<span style="color: #004993;">hitTestPoint</span><span style="color: #000000;">&#40;</span>player.<span style="color: #004993;">position</span>.<span style="color: #004993;">x</span>, player.<span style="color: #004993;">position</span>.<span style="color: #004993;">y</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>
				<span style="color: #009900;">// </span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span>.currentLap == <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;">this</span>.initialTime = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
					<span style="color: #0033ff; font-weight: bold;">this</span>.lapTime = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
					<span style="color: #0033ff; font-weight: bold;">this</span>.currentLap = <span style="color: #000000; font-weight:bold;">1</span>;
				<span style="color: #000000;">&#125;</span>
				<span style="color: #009900;">//if the current checkpoint is the mid track line - increase the lap number				</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span>.currentCheckpoint === <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #009900;">//check if this is the best lap</span>
					<span style="color: #0033ff; font-weight: bold;">this</span>.setBestLap<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;					
					<span style="color: #009900;">//if this is the final lap, move to the &quot;finish&quot; frame </span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span>.currentLap == totalLaps<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
						historyText = <span style="color: #0033ff; font-weight: bold;">new</span> Text<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
						historyText.<span style="color: #004993;">text</span> = <span style="color: #0033ff; font-weight: bold;">this</span>.raceHistory;
						historyText.<span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">10</span>; historyText.<span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">115</span>;	
						FlexGlobals.topLevelApplication.currentState = <span style="color: #990000;">&quot;LevelEnd&quot;</span>;
						FlexGlobals.topLevelApplication.levelEndCanvas.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>historyText<span style="color: #000000;">&#41;</span>;
&nbsp;
					<span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
						<span style="color: #009900;">//if the current checkpoint is the start line - increase the lap number					</span>
						<span style="color: #0033ff; font-weight: bold;">this</span>.currentLap<span style="color: #000000; font-weight: bold;">++</span>;
					<span style="color: #000000;">&#125;</span>					
					currentLapTXT = <span style="color: #0033ff; font-weight: bold;">this</span>.currentLap <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;/&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> totalLaps;
&nbsp;
					<span style="color: #009900;">//Update cuurent lap label </span>
					timeCanvas = FlexGlobals.topLevelApplication.timeDisplay;
					currentLapLabel = <span style="color: #000000;">&#40;</span>Label<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#40;</span>timeCanvas.<span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;currentLapTXT&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;			
					currentLapLabel.<span style="color: #004993;">text</span> = currentLapTXT;
&nbsp;
					<span style="color: #009900;">//we set to checkpoint to be checked to the next checkpoint </span>
					<span style="color: #0033ff; font-weight: bold;">this</span>.currentCheckpoint = <span style="color: #000000; font-weight:bold;">1</span>;					
				<span style="color: #000000;">&#125;</span>				
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #009900;">//we check to see if the car &quot;touches&quot; the checkpoint2 - mid track line)</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>FlexGlobals.topLevelApplication.checkpoint.<span style="color: #004993;">hitTestPoint</span><span style="color: #000000;">&#40;</span>player.<span style="color: #004993;">position</span>.<span style="color: #004993;">x</span>, player.<span style="color: #004993;">position</span>.<span style="color: #004993;">y</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>
				<span style="color: #009900;">//if the current checkpoint is the start line - reached the mid track point				</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span>.currentCheckpoint === <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>					
					<span style="color: #009900;">//we set to checkpoint to be checked is the next checkpoint </span>
					<span style="color: #0033ff; font-weight: bold;">this</span>.currentCheckpoint = <span style="color: #000000; font-weight:bold;">2</span>;					
				<span style="color: #000000;">&#125;</span>				
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> startupTimeClocks<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> 
		<span style="color: #000000;">&#123;</span>			
			<span style="color: #0033ff; font-weight: bold;">this</span>.initialTime = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;			
			<span style="color: #0033ff; font-weight: bold;">this</span>.lapTime = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">this</span>.bestLap = <span style="color: #000000; font-weight:bold;">0</span>;
			<span style="color: #0033ff; font-weight: bold;">this</span>.currentLap = <span style="color: #000000; font-weight:bold;">0</span>;
			<span style="color: #0033ff; font-weight: bold;">this</span>.currentCheckpoint = <span style="color: #000000; font-weight:bold;">1</span>;			
			<span style="color: #0033ff; font-weight: bold;">this</span>.raceHistory = <span style="color: #990000;">&quot;&quot;</span>;			
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> startupTimeDisplay<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> 
		<span style="color: #000000;">&#123;</span>
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> timeCanvas<span style="color: #000000; font-weight: bold;">:</span>Canvas;
			<span style="color: #6699cc; font-weight: bold;">var</span> currentLapLabel<span style="color: #000000; font-weight: bold;">:</span>Label;
			<span style="color: #6699cc; font-weight: bold;">var</span> bestLapLabel<span style="color: #000000; font-weight: bold;">:</span>Label;
			<span style="color: #6699cc; font-weight: bold;">var</span> totalTimeLabel<span style="color: #000000; font-weight: bold;">:</span>Label;
&nbsp;
			<span style="color: #009900;">//Update time display labels </span>
			timeCanvas = FlexGlobals.topLevelApplication.timeDisplay;
			currentLapLabel = <span style="color: #000000;">&#40;</span>Label<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#40;</span>timeCanvas.<span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;currentLapTXT&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;			
			currentLapLabel.<span style="color: #004993;">text</span> = <span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span>.currentLap <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;/&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> totalLaps;
			bestLapLabel = <span style="color: #000000;">&#40;</span>Label<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#40;</span>timeCanvas.<span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;bestLapTXT&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;			
			bestLapLabel.<span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;00.00.00&quot;</span>;
			totalTimeLabel = <span style="color: #000000;">&#40;</span>Label<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#40;</span>timeCanvas.<span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;totalTimeTXT&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;			
			totalTimeLabel.<span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;00.00.00&quot;</span>;			
&nbsp;
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Really a nice conversion.</p>
<p><a href="/wp-content/uploads/2010/07/FlexRacer.zip">Download the full source code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/07/30/create-a-flash-racing-game-flex-version/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Claytus Hood Tower Defense case study</title>
		<link>http://www.emanueleferonato.com/2010/07/26/claytus-hood-tower-defense-case-study/</link>
		<comments>http://www.emanueleferonato.com/2010/07/26/claytus-hood-tower-defense-case-study/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 21:54:45 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3180</guid>
		<description><![CDATA[I always loved games that revive an old concept with new features, and Claytus Hood Tower Defense is one of them. Based on the old &#8220;tower defense&#8221; theme, it introduces new strategy options with large, scrollable maps and the capability to block some paths to make enemies take a larger route to attack you base. [...]]]></description>
			<content:encoded><![CDATA[<p>I always loved games that revive an old concept with new features, and <a href="http://www.claytus-towerdefense.com/" target = "_blank">Claytus Hood Tower Defense</a> is one of them.</p>
<p><a href="http://www.claytus-towerdefense.com/" target = "_blank"><img src="/wp-content/uploads/2010/07/Screen-shot-2010-07-26-at-11.44.12-PM.jpg" /></a></p>
<p>Based on the old &#8220;tower defense&#8221; theme, it introduces new strategy options with large, scrollable maps and the capability to block some paths to make enemies take a larger route to attack you base.</p>
<p><strong>Roux Raphaël</strong>, the author, shares with us his experience:</p>
<p>&laquo; <strong>Why did I decide to work on Claytus?</strong></p>
<p>Before that, I used to be a developer for a web agency, coding online shops or institutional communication websites&#8230; not that fun!</p>
<p>After I lost my job at the end of 2009, I decided to increase my knowledges in AS3, to code funny stuff like games for example!</p>
<p>I always learnt programming by myself (the geekish way), with books, resources found on the web and personal experience&#8230;</p>
<p>I thus decided to read Keith Peters&#8217; book &#8220;<a href="http://www.amazon.com/Foundation-Actionscript-3-0-Animation-Making/dp/1590597915" target = "_blank">AS3 animation &#8211; Making Things Move</a>&#8221; to fill my gaps in maths, and I saw lots of quite useful things to code games I had forgotten.</p>
<p>After reading this book, I managed to learn AI and Pathfinding, I thus studied A* algorithm.</p>
<p>Here are the examples I inspired myself of to learn A* :<br />
<a href="http://www.remixtechnology.com/view/AStar-haXe" target = "_blank">http://www.remixtechnology.com/view/AStar-haXe</a>.</p>
<p>Well, I reviewed trigonometry, I know A*, what can I do with it? A Tower Defense game! Let&#8217;s code!<span id="more-3180"></span></p>
<p>Claytus is thus my very first game, and I learnt lots of things about AS3 best practices while developing it.</p>
<p>Here are a few technical informations about Claytus&#8217; realization and technics I used for its design :</p>
<p>- it&#8217;s a full AS3 project developed with Flex Builder 3, a great software that allows to gain plenty of time as soon as you master it (spelling, auto import, debugging, profiling, etc.).</p>
<p>- I had to establish a good workflow between Flash for graphic assets and Flex for AS3 coding (do you Flax??). With the Embed tag, I succeeded into compiling the game in a single swf and I didn&#8217;t have to load external assets.</p>
<p>- Setting up the AS3 project in FlexBuilder 3 so that the MochiAds works well is really very tricky, with the add of a Preloader class before the Main class and compiler arguments (-frame 2 Main) so that the Main class is added to stage only on the second frame!</p>
<p>- I managed to set up optimization strategies for AS3, thanks to G Skinner tricks and benchmarks. (<a href="http://gskinner.com/talks/quick/" target = "_blank">http://gskinner.com/talks/quick/</a>)</p>
<p>For the first level, the use of A* isn&#8217;t so blatant; it&#8217;s gonna be much more in the following levels where you can block your enemies&#8217; way.</p>
<p>Today, my challenge is to avoid cheaters on my leader boards :&#8217;(</p>
<p><strong>About the TD wannamake</strong></p>
<p>I didn&#8217;t use the easiest way to code a TD game, it&#8217;s thus quite hard to give you basic tips. Here is a list of a few basics for coding TD :</p>
<p>- The game takes place on a Tilemap, with a Boolean for each tile which holds isWalkable for the A* and isBuildable for the turret build.</p>
<p>- When an Enemy spwans, it asks its path to A* and I put its reference on an Array (enemyArray).</p>
<p>- The turrets go through the enemyArray in search of an enemy on its range and then open fire if their Boolean isReloaded == true.</p>
<p>- To estimate the distances and so check the range, I use Manhattan distance formula, less accurate but faster than Euclidian distance.</p>
<p>- The non-reloaded turrets reload during a few frames to simulate the firerate and then start again to look for a potential target.</p>
<p>Of course the process is far more complex, if you need more information about a precise point, don&#8217;t hesitate to ask me!</p>
<p>Easier methods than A* exist to build a TD, if the level has only a single way, no need for A* but to give an information about the direction to take when going out of the tile, such as hard coded waypoints.</p>
<p><strong>Claytus&#8217; graphism</strong></p>
<p>In the beginning, Claytus used to be quite ugly, as a game skeleton with circles for the turrets and triangles for enemies, as for any experimental game skeleton I guess!</p>
<p>I thus offered to friends of mine who are illustrators to work with me on the project, to give life to my circles and triangles ! They were just finishing their studies and I think Claytus has been a good opportunity for them to increase their knowledges in Flash and add a valuable project to their portfolio. They learnt a lot about technical constraints that represents the integration of a drawing into a video game.</p>
<p>All of the Claytus&#8217; artworks were so designed on a graphics tablet coupled to Photoshop. I didn&#8217;t wanna use vectorial drawing to economize resources and keep an artistic look. Only using bitmaps, I get very good performances on an old computer on which Bloons TD 4 freezes =D.</p>
<p><strong>Claytus&#8217; music</strong></p>
<p>The music for Claytus TD was exclusively composed by friends of mine! The musicians didn&#8217;t know video games field that well, and they brought their point of view and an acoustic soundtrack. I love it!</p>
<p><strong>How to give freshness to an old concept</strong></p>
<p>It&#8217;s true it&#8217;s difficult to create something new in TD game because lots of things have already been done.</p>
<p>Lots of TD only send lots of waves and lots of enemies with a huge arsenal&#8230;</p>
<p>Finally, this gameplay type is much more of a massacre timekiller that you win whatever you do!</p>
<p>I wanted to create a much more challenging game with Claytus TD. I agree it can raise an issue to some of the players, but the fact that is challenging makes others happy!</p>
<p>The game begins with a single way, and only three different turrets, which poses Claytus as a real strategy and positioning game, you have to think every move you make!</p>
<p>In the other levels, we bring each time a novelty in gameplay : stage with other possibilities as multiple ways possible, new turrets and new upgrades in addition to gameplay elements of the stage.</p>
<p>I wanted every turret unique with a precise goal, that&#8217;s why you can&#8217;t do anything if you wanna win.</p>
<p><strong>About the funding</strong></p>
<p>Claytus wasn&#8217;t made to raise money at first thought, it was more of a project to help me learning to code in AS3 and manage a project with high quality standards.</p>
<p>I&#8217;m thus just incoming into flash game field and Mochimedia helps broadcasting the game on tenths of the websites of their partners.</p>
<p><strong>Website</strong></p>
<p>Claytus TD have its own website at <a href="www.claytus-towerdefense.com">http://www.claytus-towerdefense.com</a>.</p>
<p>I made it to showcase the game in a nice looking website with drawn background.</p>
<p>The website introduce the team, the French version have a forum (I will add an english forum asap), and people can mail me via the contact form.</p>
<p>I also upload preview pictures of the next levels and the next soundtracks because Claytus TD intend to have six levels and more, but its takes a lot of time to create all of this stuff!</p>
<p>To stay tuned, players can become fan on Facebook and subscribe to my<br />
newsletter.</p>
<p><strong>Level Editor</strong></p>
<p>I have build a level editor to help me making level and learning tool programming, coded in Flex, MXML &#038; AS3, great technology to deploy rich applications (RIA).</p>
<p><img src="/wp-content/uploads/2010/07/editor.jpg" /></p>
<p>It&#8217;s not released for the public at this day, but if I have time i&#8217;ll code a friendly user version for the people can make their own level and why not create a level contest? &raquo;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/07/26/claytus-hood-tower-defense-case-study/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>PHP face detection class</title>
		<link>http://www.emanueleferonato.com/2010/07/06/php-face-detection-class/</link>
		<comments>http://www.emanueleferonato.com/2010/07/06/php-face-detection-class/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 15:04:30 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Php]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3095</guid>
		<description><![CDATA[Face detection is a computer technology that determines the locations and sizes of human faces in arbitrary (digital) images. It detects facial features and ignores anything else, such as buildings, trees and bodies. (source: Wikipedia) There is so much to say about face detection and all its algorithms&#8230; I am planning a step by step [...]]]></description>
			<content:encoded><![CDATA[<p>Face detection is a computer technology that determines the locations and sizes of human faces in arbitrary (digital) images.</p>
<p>It detects facial features and ignores anything else, such as buildings, trees and bodies.</p>
<p>(source: <a href="http://en.wikipedia.org/wiki/Face_detection" target = "_blank">Wikipedia</a>)</p>
<p>There is so much to say about face detection and all its algorithms&#8230; I am planning a step by step tutorial about every branch of object detection in digital images, but first I want to publish <strong>Maurice Svay</strong>&#8216;s PHP class.</p>
<p>Maurice, in his blog <a href="http://svay.com/" target = "_blank">svay.com</a>, explains he was looking for a face detection script for PHP, but wasn&#8217;t able to find one working without <a href="http://opencv.willowgarage.com/wiki/" target = "_blank">OpenCV</a> (Open Source Computer Vision), an opensource lib that was originally developed by Intel.</p>
<p>OpenCV seems to perform well but you need to be able to install it on your server.</p>
<p>So he coded his own pure PHP solution, that does not require any library to be installed on the server.</p>
<p>And, obviously, that can be easily ported into any language. His class itself has been translated from a javascript code that actually is no longer available online</p>
<p>So this is the class:<span id="more-3095"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// </span>
<span style="color: #666666; font-style: italic;">// This program is free software; you can redistribute it and/or</span>
<span style="color: #666666; font-style: italic;">// modify it under the terms of the GNU General Public License</span>
<span style="color: #666666; font-style: italic;">// as published by the Free Software Foundation; either version 2</span>
<span style="color: #666666; font-style: italic;">// of the License, or (at your option) any later version.</span>
<span style="color: #666666; font-style: italic;">// </span>
<span style="color: #666666; font-style: italic;">// This program is distributed in the hope that it will be useful,</span>
<span style="color: #666666; font-style: italic;">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span style="color: #666666; font-style: italic;">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span style="color: #666666; font-style: italic;">// GNU General Public License for more details.</span>
<span style="color: #666666; font-style: italic;">// </span>
<span style="color: #666666; font-style: italic;">// You should have received a copy of the GNU General Public License</span>
<span style="color: #666666; font-style: italic;">// along with this program; if not, write to the Free Software</span>
<span style="color: #666666; font-style: italic;">// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.     </span>
<span style="color: #666666; font-style: italic;">// </span>
<span style="color: #666666; font-style: italic;">// @Author Karthik Tharavaad </span>
<span style="color: #666666; font-style: italic;">//         karthik_tharavaad@yahoo.com</span>
<span style="color: #666666; font-style: italic;">// @Contributor Maurice Svay</span>
<span style="color: #666666; font-style: italic;">//              maurice@svay.Com</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Face_Detector <span style="color: #009900;">&#123;</span>
&nbsp;
    protected <span style="color: #000088;">$detection_data</span><span style="color: #339933;">;</span>
    protected <span style="color: #000088;">$canvas</span><span style="color: #339933;">;</span>
    protected <span style="color: #000088;">$face</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$reduced_canvas</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$detection_file</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'detection.dat'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$detection_file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">detection_data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">unserialize</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$detection_file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Couldn't load detection data&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #666666; font-style: italic;">//$this-&gt;detection_data = json_decode(file_get_contents('data.js'));</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> face_detect<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Can not load <span style="color: #006699; font-weight: bold;">$file</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">canvas</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefromjpeg</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$im_width</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagesx</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">canvas</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$im_height</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagesy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">canvas</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//Resample before detection?</span>
        <span style="color: #000088;">$ratio</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$diff_width</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">320</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$im_width</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$diff_height</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">240</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$im_height</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$diff_width</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$diff_height</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$ratio</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$im_width</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">320</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$ratio</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$im_height</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">240</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ratio</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">reduced_canvas</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im_width</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$ratio</span><span style="color: #339933;">,</span> <span style="color: #000088;">$im_height</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$ratio</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #990000;">imagecopyresampled</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">reduced_canvas</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">canvas</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$im_width</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$ratio</span><span style="color: #339933;">,</span> <span style="color: #000088;">$im_height</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$ratio</span><span style="color: #339933;">,</span> <span style="color: #000088;">$im_width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$im_height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000088;">$stats</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_img_stats</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">reduced_canvas</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">face</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">do_detect_greedy_big_to_small</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stats</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ii'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stats</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ii2'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stats</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'width'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stats</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'height'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">face</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'x'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">*=</span> <span style="color: #000088;">$ratio</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">face</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'y'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">*=</span> <span style="color: #000088;">$ratio</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">face</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">*=</span> <span style="color: #000088;">$ratio</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$stats</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_img_stats</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">canvas</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">face</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">do_detect_greedy_big_to_small</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stats</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ii'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stats</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ii2'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stats</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'width'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stats</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'height'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">face</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> toJpeg<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$color</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">canvas</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//red</span>
        <span style="color: #990000;">imagerectangle</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">canvas</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">face</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'x'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">face</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'y'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">face</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'x'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">face</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">face</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'y'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">face</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$color</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: image/jpeg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">imagejpeg</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">canvas</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> toJson<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;{'x':&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">face</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'x'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;, 'y':&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">face</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'y'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;, 'w':&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">face</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;}&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getFace<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">face</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    protected <span style="color: #000000; font-weight: bold;">function</span> get_img_stats<span style="color: #009900;">&#40;</span><span style="color: #000088;">$canvas</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$image_width</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagesx</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$canvas</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$image_height</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagesy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$canvas</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     
        <span style="color: #000088;">$iis</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">compute_ii</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$canvas</span><span style="color: #339933;">,</span> <span style="color: #000088;">$image_width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$image_height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'width'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$image_width</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'height'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$image_height</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'ii'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$iis</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ii'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'ii2'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$iis</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ii2'</span><span style="color: #009900;">&#93;</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>         
    <span style="color: #009900;">&#125;</span>
&nbsp;
    protected <span style="color: #000000; font-weight: bold;">function</span> compute_ii<span style="color: #009900;">&#40;</span><span style="color: #000088;">$canvas</span><span style="color: #339933;">,</span> <span style="color: #000088;">$image_width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$image_height</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$ii_w</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$image_width</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$ii_h</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$image_height</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$ii</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$ii2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>      
&nbsp;
        <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$ii_w</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$ii</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$ii2</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>                        
&nbsp;
        <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$ii_w</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>  
            <span style="color: #000088;">$ii</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #339933;">*</span><span style="color: #000088;">$ii_w</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>       
            <span style="color: #000088;">$ii2</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #339933;">*</span><span style="color: #000088;">$ii_w</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> 
            <span style="color: #000088;">$rowsum</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$rowsum2</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$j</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$j</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$ii_h</span><span style="color: #339933;">;</span> <span style="color: #000088;">$j</span><span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$rgb</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ImageColorAt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$canvas</span><span style="color: #339933;">,</span> <span style="color: #000088;">$j</span><span style="color: #339933;">,</span> <span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$red</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rgb</span> <span style="color: #339933;">&gt;&gt;</span> <span style="color: #cc66cc;">16</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0xFF</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$green</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rgb</span> <span style="color: #339933;">&gt;&gt;</span> <span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0xFF</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$blue</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rgb</span> <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0xFF</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$grey</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color:#800080;">0.2989</span><span style="color: #339933;">*</span><span style="color: #000088;">$red</span> <span style="color: #339933;">+</span> <span style="color:#800080;">0.587</span><span style="color: #339933;">*</span><span style="color: #000088;">$green</span> <span style="color: #339933;">+</span> <span style="color:#800080;">0.114</span><span style="color: #339933;">*</span><span style="color: #000088;">$blue</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// this is what matlab uses</span>
                <span style="color: #000088;">$rowsum</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$grey</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$rowsum2</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$grey</span><span style="color: #339933;">*</span><span style="color: #000088;">$grey</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #000088;">$ii_above</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #000088;">$ii_w</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$j</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$ii_this</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$i</span><span style="color: #339933;">*</span><span style="color: #000088;">$ii_w</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$j</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #000088;">$ii</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$ii_this</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ii</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$ii_above</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$rowsum</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$ii2</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$ii_this</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ii2</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$ii_above</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$rowsum2</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ii'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$ii</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ii2'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$ii2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    protected <span style="color: #000000; font-weight: bold;">function</span> do_detect_greedy_big_to_small<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$ii</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ii2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$s_w</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$width</span><span style="color: #339933;">/</span><span style="color:#800080;">20.0</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$s_h</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$height</span><span style="color: #339933;">/</span><span style="color:#800080;">20.0</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$start_scale</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$s_h</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$s_w</span> ? <span style="color: #000088;">$s_h</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$s_w</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$scale_update</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span> <span style="color: #339933;">/</span> <span style="color:#800080;">1.2</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$scale</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$start_scale</span><span style="color: #339933;">;</span> <span style="color: #000088;">$scale</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$scale</span> <span style="color: #339933;">*=</span> <span style="color: #000088;">$scale_update</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$w</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">*</span><span style="color: #000088;">$scale</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$endx</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$w</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$endy</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$height</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$w</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$step</span> <span style="color: #339933;">=</span> <span style="color: #990000;">max</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$scale</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$inv_area</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$w</span><span style="color: #339933;">*</span><span style="color: #000088;">$w</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$y</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$y</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$endy</span> <span style="color: #339933;">;</span> <span style="color: #000088;">$y</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$step</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$endx</span> <span style="color: #339933;">;</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$step</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$passed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">detect_on_sub_image</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #000088;">$scale</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ii</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ii2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$w</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$inv_area</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$passed</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'x'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'y'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'w'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$w</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// end x</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// end y</span>
        <span style="color: #009900;">&#125;</span>  <span style="color: #666666; font-style: italic;">// end scale</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    protected <span style="color: #000000; font-weight: bold;">function</span> detect_on_sub_image<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #000088;">$scale</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ii</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ii2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$w</span><span style="color: #339933;">,</span> <span style="color: #000088;">$iiw</span><span style="color: #339933;">,</span> <span style="color: #000088;">$inv_area</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$mean</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$ii</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$y</span><span style="color: #339933;">+</span><span style="color: #000088;">$w</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #000088;">$iiw</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$w</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$ii</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$y</span><span style="color: #339933;">*</span><span style="color: #000088;">$iiw</span><span style="color: #339933;">+</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$ii</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$y</span><span style="color: #339933;">+</span><span style="color: #000088;">$w</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #000088;">$iiw</span><span style="color: #339933;">+</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$ii</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$y</span><span style="color: #339933;">*</span><span style="color: #000088;">$iiw</span><span style="color: #339933;">+</span><span style="color: #000088;">$x</span><span style="color: #339933;">+</span><span style="color: #000088;">$w</span><span style="color: #009900;">&#93;</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #000088;">$inv_area</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$vnorm</span> <span style="color: #339933;">=</span>  <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$ii2</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$y</span><span style="color: #339933;">+</span><span style="color: #000088;">$w</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #000088;">$iiw</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$w</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$ii2</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$y</span><span style="color: #339933;">*</span><span style="color: #000088;">$iiw</span><span style="color: #339933;">+</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$ii2</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$y</span><span style="color: #339933;">+</span><span style="color: #000088;">$w</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #000088;">$iiw</span><span style="color: #339933;">+</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$ii2</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$y</span><span style="color: #339933;">*</span><span style="color: #000088;">$iiw</span><span style="color: #339933;">+</span><span style="color: #000088;">$x</span><span style="color: #339933;">+</span><span style="color: #000088;">$w</span><span style="color: #009900;">&#93;</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #000088;">$inv_area</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$mean</span><span style="color: #339933;">*</span><span style="color: #000088;">$mean</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    
        <span style="color: #000088;">$vnorm</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$vnorm</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span> ? <span style="color: #990000;">sqrt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$vnorm</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$passed</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i_stage</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i_stage</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">detection_data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i_stage</span><span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$stage</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">detection_data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i_stage</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>  
            <span style="color: #000088;">$trees</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$stage</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>  
&nbsp;
            <span style="color: #000088;">$stage_thresh</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$stage</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$stage_sum</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i_tree</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i_tree</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trees</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i_tree</span><span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$tree</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$trees</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i_tree</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$current_node</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tree</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>    
                <span style="color: #000088;">$tree_sum</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$current_node</span> <span style="color: #339933;">!=</span> <span style="color: #009900; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$vals</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$current_node</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                    <span style="color: #000088;">$node_thresh</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$vals</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                    <span style="color: #000088;">$leftval</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$vals</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                    <span style="color: #000088;">$rightval</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$vals</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                    <span style="color: #000088;">$leftidx</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$vals</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                    <span style="color: #000088;">$rightidx</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$vals</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                    <span style="color: #000088;">$rects</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$current_node</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #000088;">$rect_sum</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$i_rect</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i_rect</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rects</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i_rect</span><span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                        <span style="color: #000088;">$s</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$scale</span><span style="color: #339933;">;</span>
                        <span style="color: #000088;">$rect</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rects</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i_rect</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                        <span style="color: #000088;">$rx</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rect</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span><span style="color: #000088;">$s</span><span style="color: #339933;">+</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
                        <span style="color: #000088;">$ry</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rect</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span><span style="color: #000088;">$s</span><span style="color: #339933;">+</span><span style="color: #000088;">$y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
                        <span style="color: #000088;">$rw</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rect</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>  
                        <span style="color: #000088;">$rh</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rect</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
                        <span style="color: #000088;">$wt</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rect</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
                        <span style="color: #000088;">$r_sum</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$ii</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ry</span><span style="color: #339933;">+</span><span style="color: #000088;">$rh</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #000088;">$iiw</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$rx</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$rw</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$ii</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$ry</span><span style="color: #339933;">*</span><span style="color: #000088;">$iiw</span><span style="color: #339933;">+</span><span style="color: #000088;">$rx</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$ii</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ry</span><span style="color: #339933;">+</span><span style="color: #000088;">$rh</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #000088;">$iiw</span><span style="color: #339933;">+</span><span style="color: #000088;">$rx</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$ii</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$ry</span><span style="color: #339933;">*</span><span style="color: #000088;">$iiw</span><span style="color: #339933;">+</span><span style="color: #000088;">$rx</span><span style="color: #339933;">+</span><span style="color: #000088;">$rw</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #000088;">$wt</span><span style="color: #339933;">;</span>
                        <span style="color: #000088;">$rect_sum</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$r_sum</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span> 
&nbsp;
                    <span style="color: #000088;">$rect_sum</span> <span style="color: #339933;">*=</span> <span style="color: #000088;">$inv_area</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #000088;">$current_node</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$rect_sum</span> <span style="color: #339933;">&gt;=</span> <span style="color: #000088;">$node_thresh</span><span style="color: #339933;">*</span><span style="color: #000088;">$vnorm</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$rightidx</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span> 
                            <span style="color: #000088;">$tree_sum</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rightval</span><span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">else</span>
                            <span style="color: #000088;">$current_node</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tree</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$rightidx</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$leftidx</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span>
                            <span style="color: #000088;">$tree_sum</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$leftval</span><span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">else</span>
                            <span style="color: #000088;">$current_node</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tree</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$leftidx</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span> 
                <span style="color: #000088;">$stage_sum</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$tree_sum</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> 
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$stage_sum</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$stage_thresh</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span> 
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Using it is very easy, just write</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$detector</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Face_Detector<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'detection.dat'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$detector</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">face_detect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'your_file.jpg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$detector</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">toJpeg</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>once you unpacked and included <a href="/wp-content/uploads/2010/07/detection.zip">detection.dat</a> and the image in the same path as your class.</p>
<p>Do you want to see a result?</p>
<p><img src="/wp-content/uploads/2010/07/fc.jpg" /></p>
<p>This was generated by the script, just changing the frame color from red to green, to make it more visible.</p>
<p>The class does not work that well on every photo, but it&#8217;s a good start for a journey into face detection</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/07/06/php-face-detection-class/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Worms-like destructible terrain in Flash</title>
		<link>http://www.emanueleferonato.com/2010/06/25/worms-like-destructible-terrain-in-flash/</link>
		<comments>http://www.emanueleferonato.com/2010/06/25/worms-like-destructible-terrain-in-flash/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 10:58:54 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3065</guid>
		<description><![CDATA[Do you remember Worms game and its destructible terrain? Jordi Sanglas Molist explains us how to create a basic destructible terrain with AS3 &#171; Today, browsing the &#8220;most popular&#8221; posts, I found &#8220;Create a flash artillery game &#8211; step 1&#8220;, where you talked about making a game similar to Worms. Then, I thought: &#8220;How will [...]]]></description>
			<content:encoded><![CDATA[<p>Do you remember Worms game and its destructible terrain?</p>
<p><img src="/wp-content/uploads/2010/06/worms.jpg" /></p>
<p><strong>Jordi Sanglas Molist</strong> explains us how to create a basic destructible terrain with AS3</p>
<p>&laquo; Today, browsing the &#8220;most popular&#8221; posts, I found &#8220;<a href="http://www.emanueleferonato.com/2007/04/28/create-a-flash-artillery-game-step-1/">Create a flash artillery game &#8211; step 1</a>&#8220;, where you talked about making a game similar to Worms.</p>
<p>Then, I thought: &#8220;How will I make a destructible terrain?&#8221;</p>
<p>After looking for some information, I realized I should use a Bitmap. So I started with a really basic prototype:</p>
<p>- The character falls if he doesn&#8217;t touch the ground<br />
- You can press at any point of the terrain to make a hole (because I don&#8217;t still have weapons)</p>
<p>The code is fully commented (and there are only 59 miserable lines), so you won&#8217;t have any problem to understand it.</p>
<p>I&#8217;ll be three days on holiday, so on Sunday I&#8217;ll start writing the next part, which I think it may talk about moving the character.</p>
<p>I think I&#8217;ll do it in that way: if you press the right arrow and in the right the obstacle is less than X<br />
pixels height, you can move. I&#8217;ll try if that works. &raquo;</p>
<p>I am looking forward for character movement, meanwhile this is the script:<span id="more-3065"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
</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: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Bitmap</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">BitmapData</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">BlendMode</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span>.<span style="color: #004993;">Point</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span>.<span style="color: #004993;">Matrix</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">MouseEvent</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> worms extends <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> terrain_bmpd=<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;">550</span>,<span style="color: #000000; font-weight:bold;">200</span>,<span style="color: #0033ff; font-weight: bold;">true</span>,0xFF00FF00<span style="color: #000000;">&#41;</span>;<span style="color: #009900;">//This is the Bitmap of the terrain</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> terrain_bmp=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Bitmap</span><span style="color: #000000;">&#40;</span>terrain_bmpd<span style="color: #000000;">&#41;</span>;<span style="color: #009900;">//and this the BitmapData</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> character=<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: #009900;">//The character will work as a worm</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> hole=<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: #009900;">//That's the hole we need</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> hole_matrix<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Matrix</span>;<span style="color: #009900;">//The hole_matrix is used to set the position of the hole</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> left_foot<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Point</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> right_foot<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Point</span>;<span style="color: #009900;">//These are the feet of the character. We will use it to check collisions</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> worms<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			draw_objects<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<span style="color: #009900;">//This function draws the character, the terrain and the hole.</span>
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">ENTER_FRAME</span>,fall<span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">MOUSE_UP</span>,mouse_up<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> fall<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #3f5fbf;">/*This function will move down the character if there isn't a collision
			between the terrain and the &quot;feet&quot; of the character*/</span>
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">0</span>; i<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">10</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #009900;">//We want to check every pixel if there's acollision, so we won't move the character 10 pixels all at once</span>
				left_foot=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>character.x<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">5</span>,character.<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span>;
				right_foot=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>character.<span style="color: #004993;">x</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">5</span>,character.<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span>;
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span><span style="color: #000000;">&#40;</span>terrain_bmpd.<span style="color: #004993;">hitTest</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span>
				<span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>terrain_bmp.<span style="color: #004993;">x</span>,terrain_bmp.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>,0x01,left_foot<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">&amp;&amp;!</span><span style="color: #000000;">&#40;</span>terrain_bmpd.<span style="color: #004993;">hitTest</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span>terrain_bmp.<span style="color: #004993;">x</span>,terrain_bmp.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>,0x01,right_foot<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					character.<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">++</span>;<span style="color: #009900;">//If there aren't any collisions, make the character fall one pixel</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;">public</span> <span style="color: #339966; font-weight: bold;">function</span> mouse_up<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			hole_matrix=<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: #009900;">//We need to reset the matrix each new hole</span>
			hole_matrix.<span style="color: #004993;">translate</span><span style="color: #000000;">&#40;</span>e.stageX<span style="color: #000000; font-weight: bold;">-</span>terrain_bmp.<span style="color: #004993;">x</span>,e.stageY<span style="color: #000000; font-weight: bold;">-</span>terrain_bmp.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span>;<span style="color: #009900;">//and setthe coordinates of the hole</span>
			terrain_bmpd.<span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span>hole,hole_matrix,<span style="color: #0033ff; font-weight: bold;">null</span>,<span style="color: #004993;">BlendMode</span>.<span style="color: #004993;">ERASE</span><span style="color: #000000;">&#41;</span>;<span style="color: #009900;">//Then, we can draw the hole in the BitmapData</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> draw_objects<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			terrain_bmp.<span style="color: #004993;">y</span>=<span style="color: #000000; font-weight:bold;">200</span>;<span style="color: #009900;">//The terrain shouldn't be at the top of the stage!</span>
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>terrain_bmp<span style="color: #000000;">&#41;</span>;<span style="color: #009900;">//We can make the terrain visible</span>
			character.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span>0x0000FF<span style="color: #000000;">&#41;</span>;<span style="color: #009900;">//Let's draw the character. It will be a blue rectangle.</span>
			character.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">5</span>,<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">10</span>,<span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000;">&#41;</span>;
			character.<span style="color: #004993;">x</span>=<span style="color: #000000; font-weight:bold;">250</span>;
			<span style="color: #004993;">stage</span>.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>character<span style="color: #000000;">&#41;</span>;
			hole.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span>0x000000<span style="color: #000000;">&#41;</span>;<span style="color: #009900;">//Now we draw the hole. It doesn't matter the colour.</span>
			hole.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">drawCircle</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">30</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>And this is the result:</p>
<p><embed src="/wp-content/uploads/2010/06/worms.swf" allowscriptaccess="always" menu="false" quality="high" width="500" height="400" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>Click on the terrain to create holes and watch your &#8220;worm&#8221; falling down.</p>
<p><a href="/wp-content/uploads/2010/06/worms.zip">Download the source code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/06/25/worms-like-destructible-terrain-in-flash/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Integrate Mochi games in your custom arcade website</title>
		<link>http://www.emanueleferonato.com/2010/05/21/integrate-mochi-games-in-your-custom-arcade-website/</link>
		<comments>http://www.emanueleferonato.com/2010/05/21/integrate-mochi-games-in-your-custom-arcade-website/#comments</comments>
		<pubDate>Fri, 21 May 2010 08:40:04 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Monetize]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=2928</guid>
		<description><![CDATA[Do you want to create your custom arcade website without using popular arcade scripts or WordPress plugins? Maybe with a Mochi integration? That&#8217;s what Gabriel Bianconi did, and he wants to share his script with us. It&#8217;s a simple, interesting script dedicated to all developers looking for a quick way to integrate Mochi games into [...]]]></description>
			<content:encoded><![CDATA[<p>Do you want to create your custom arcade website without using popular arcade scripts or WordPress plugins? Maybe with a Mochi integration?</p>
<p>That&#8217;s what <a href="http://www.gabrielbianconi.com/" target = "_blank"><strong>Gabriel Bianconi</strong></a> did, and he wants to share his script with us.</p>
<p>It&#8217;s a simple, interesting script dedicated to all developers looking for a quick way to integrate Mochi games into their custom arcade sites.</p>
<p>&laquo; Hello. My name is Gabriel Bianconi. I’m a 16 years old Brazilian student and I’m interested in game and web development.<br />
 I’ve recently launched my first arcade website, <a href="http://www.plugb.com/" target = "_blank"><strong>PlugB.com</strong></a>.  I decided to create my own script for two reasons: to improve my PHP skills and to have a more customizable website.</p>
<p>One of the features I integrated to my admin was the <a href="https://www.mochimedia.com/r/972ae333a3c92a2a" target = "_blank">MochiAds</a> ‘Post Game to my Site’ button. Since I add games manually (I don’t want to import all Mochi games), this saves me a lot of time.</p>
<p>When I tried to search about this feature, I realized that there is no tutorial about this online (at least, I couldn’t find one).  I searched a little more and found a few scripts about this.<span id="more-2928"></span></p>
<p>They were integrated to some arcade scripts, so I couldn’t just copy and paste them. But it was a start. </p>
<p>The script that I most used was from <a href="http://timarcher.com/blog/" target = "_blank">Timothy E. Archer</a>.</p>
<p>After a few tests, I’ve created a working script:</p>
<p>Firstly, you’ll need a <a href="https://www.mochimedia.com/r/972ae333a3c92a2a" target = "_blank">MochiAds</a> publisher account.</p>
<p>After registering and adding your website, go to the <a href="https://www.mochimedia.com/pub/settings" target = "_blank">Settings</a> page.</p>
<p>In the bottom of the page, below ‘Auto Post Settings’, set the ‘Auto Post Method’ to ‘Custom built script’ and the ‘Auto Post URL’ to the URL of your script.</p>
<p>Now the PHP part:</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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000088;">$game_tag</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'game_tag'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Sample tag to fake a mochi request... Remove this line in final version...</span>
<span style="color: #000088;">$game_tag</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'cd698a06f727e887'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$game_tag</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No gametag.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// This can be found in the settings page.</span>
<span style="color: #000088;">$mochi_pub_id</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'xxxxxxxxxxxxxxxxxxxxx'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$game_feed_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://www.mochiads.com/feeds/games/<span style="color: #006699; font-weight: bold;">$mochi_pub_id</span>/<span style="color: #006699; font-weight: bold;">$game_tag</span>/?format=json&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Retrieves and parses the JSON data of the game.	</span>
<span style="color: #000088;">$json_feed</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$game_feed_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$json_items</span> <span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$json_feed</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$game</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$json_items</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'games'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Now you can access all variables about the game with $game['variable_name'];
 * For example: $game['name'] or $game['swf_url']
 * The full list of the variables can be found here: https://www.mochimedia.com/support/pub_docs#feed_3
 * I did not add how to save in a database because it changes from script to script.
 */</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// Sample: (can be removed in final version)</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$game</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' - '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$game</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'swf_url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* You should get: Sokobones - http://games.mochiads.com/c/g/sokobones_v1/Sokobones-MochiAds_Secure.swf
 * if you used the sample tag.
 * Remove that line in the final version.
 */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><strong>Remember to remove the sample game tag in the final version</strong>.</p>
<p>Thank you for reading the tutorial. I hope this helps you. Please let me know what you think about this and visit my <a href="http://www.plugb.com/" target = "_blank">arcade website</a>. &raquo;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/05/21/integrate-mochi-games-in-your-custom-arcade-website/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Flash games and religion</title>
		<link>http://www.emanueleferonato.com/2010/04/23/games-and-religion/</link>
		<comments>http://www.emanueleferonato.com/2010/04/23/games-and-religion/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 04:06:15 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=2737</guid>
		<description><![CDATA[I am used to see Flash educational games, but I don&#8217;t remember any Flash game based on religion. And I don&#8217;t mean something like &#8220;you are God and must obliterate a village&#8221;, but a game entirely based on the Bible. Now Gabriel Walter talks about Verse Vessel &#171; The working demo of Verse Vessel is [...]]]></description>
			<content:encoded><![CDATA[<p>I am used to see Flash educational games, but I don&#8217;t remember any Flash game based on religion.</p>
<p>And I don&#8217;t mean something like &#8220;you are God and must obliterate a village&#8221;, but a game entirely based on the Bible.</p>
<p>Now <strong>Gabriel Walter</strong> talks about <a href="http://www.versevessel.com/" target = "_blank"><strong>Verse Vessel</strong></a></p>
<p>&laquo; The working demo of <a href="http://www.versevessel.com/" target = "_blank"><strong>Verse Vessel</strong></a> is ready now!</p>
<p>The idea now is to promote it and I&#8217;m open to suggestions as its a “casual-to-hardcore-rpg-word-matching-bible-game”, which is not the easiest “category” in the world to get across!</p>
<p>The technology used is mainly flash (css for text) because of its range of output for Pc, Mac, portable, and (most) browsers. It&#8217;s also the simplest to set up and export (no sdks).</p>
<p>But why did I select the bible? Before I explain here&#8217;s how I came up with the concept.<span id="more-2737"></span></p>
<p>I have made games in the past of varying themes. One game I did for Neutrogena was a “clear the pores” mini-game! Another game I made revolved around a construction sim with Rts elements.</p>
<p>I have created other games I&#8217;d like to post in the future that are educational (which is a popular theme). But right now I felt there is a major subject missing.</p>
<p>I&#8217;ve played all types of games ranging from sports to music based, but the one factor I&#8217;d like to see more of has to do with the bible. One day my father suggested why don&#8217;t I do one based on the bible, and I thought &#8220;yes, I&#8217;d like to have a game representing the bible in these modern times&#8221;.</p>
<p>And I don&#8217;t mean a five minute kids game, or a wink-wink humorous satire thereof! I&#8217;d like to see a fully featured, accurate representation of the bible that&#8217;s done right.</p>
<p>This is important to me and making a game you like is always fun (even if others don&#8217;t like it) but only for one person- the game creator! At least “officially”, hopefully others will like it too. But that&#8217;s not just the focus in the case of Verse Vessel.</p>
<p>Even though I have one religion and the person helping with duel player code has another (coming soon God willing), and the qa tester has another, it all comes down to the bible going BEYOND religion.</p>
<p>And even beyond that, it reaches everyone in one way or another.</p>
<p>In other words, everyone has an opinion either for or against the bible. </p>
<p>The game is not set up to “preach at you”. There&#8217;s no “moral meter” (although I personally think that could be exciting if done well). Playing from a “non religious” view can be enjoyed as much as someone with religious background because there is no “interpretations”of the bible, it&#8217;s straight bible text.</p>
<p>If you know what your particular religion teaches about a particular verse that&#8217;s all well and good but different religions teach different views.</p>
<p>Here, the verse can&#8217;t be adapted differently- its still the same verse! So its “system independent” (hey its better than saying “religious agnostic”) and can reach not only certain religions, but as mentioned, someone with no religion at all.</p>
<p>You don&#8217;t have to know certain doctrines that comes with religion to select the right choices. Some of it is just common sense. You could be playing this from a scholarly standpoint or out of curiosity and not have to be concerned with anything but enjoying the game.</p>
<p>The fun of being an independent game developer is no one is going to dictate that the game has to appeal to certain religious leaders or take out certain things because some non/religious people don&#8217;t want it there. There are no advertisers to worry about having to please or any other specific group for that matter!</p>
<p>Another reason I wanted to focus in on the bible and not religion is that anyone can own a bible and I&#8217;m sure there are some in your/your parents house.</p>
<p>But how often is someone going to actually read it is another thing altogether! I know we live in a digital age and picking up a huge book is not going be at the top of the attention-getting list when there&#8217;s so much media available.</p>
<p>If there was some way to be able to pick up the bible digitally and be able to read it from any point AND have some in game goals then I figured it would be fun AND informative.</p>
<p>So far some of the immediate goals are to collect experience points by getting the most correct answers as well as collect inventory. Soon there will be options to trade and compete against another person.</p>
<p>Another is having the animals get off of Noah&#8217;s ark first and there are some unusual animals in that particular version! This is only the beginning. </p>
<p>More chapters will come soon hopefully. Of course I&#8217;ll always be open to feedback from suggestions for things I may not have thought of.</p>
<p>So I&#8217;m glad I could share a bit about the purpose behind verse vessel. Check out the demo at <a href="http://www.versevessel.com/" target = "_blank"><strong>www.versevessel.com</strong></a> if you are interested or email zartan917 [at] aol [dot] com for feedback. &raquo;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/04/23/games-and-religion/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
