<?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; Game design</title>
	<atom:link href="http://www.emanueleferonato.com/category/game-design/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>Flash Games Market Survey &#8211; 2010 edition</title>
		<link>http://www.emanueleferonato.com/2010/08/27/flash-games-market-survey-2010-edition/</link>
		<comments>http://www.emanueleferonato.com/2010/08/27/flash-games-market-survey-2010-edition/#comments</comments>
		<pubDate>Fri, 27 Aug 2010 19:49:08 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Monetize]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3270</guid>
		<description><![CDATA[After the huge success of Flash Games Market Survey, Mochi Media in partnership with Flash Game License and Adobe present 2010 Flash Games Market Survey. Last year&#8217;s survey showed just how vibrant the space is, it&#8217;s time to give some information again to help Mochi and partners to improve Flash gaming world. In addition, you [...]]]></description>
			<content:encoded><![CDATA[<p>After the huge success of <a href="http://www.emanueleferonato.com/2009/07/08/flash-games-market-survey/">Flash Games Market Survey</a>, <a href="https://www.mochimedia.com/r/972ae333a3c92a2a" target = "_blank">Mochi Media</a> in partnership with <a href="http://www.flashgamelicense.com/" target = "_blank">Flash Game License</a> and <a href="http://www.adobe.com/" target ="_blank">Adobe</a> present <strong><a target = "_blank" href="http://www.surveymonkey.com/s/fgms2010">2010 Flash Games Market Survey</a></strong>.</p>
<p><a target = "_blank" href="http://www.surveymonkey.com/s/fgms2010"><img src="/wp-content/uploads/2010/08/c7bef074-60d4-4179-b581-991c1b1a7013.png" /></a></p>
<p>Last year&#8217;s survey showed just how vibrant the space is, it&#8217;s time to give some information again to help Mochi and partners to improve Flash gaming world. In addition, you can also win one of two $50 Amazon gift cards.</p>
<p>This survey is completely anonymous. Thanks for your time!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/08/27/flash-games-market-survey-2010-edition/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tic Tac Toe Artificial Intelligence</title>
		<link>http://www.emanueleferonato.com/2010/08/26/tic-tac-toe-artificial-intelligence/</link>
		<comments>http://www.emanueleferonato.com/2010/08/26/tic-tac-toe-artificial-intelligence/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 09:29:51 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Game design]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3260</guid>
		<description><![CDATA[During these days I played a bit with Artificial Intelligence for a project I am working on (big news on the horizon) and I&#8217;m coming with a brief introduction to the simplest game you can use to test artificial intelligence. Tic Tac Toe. It&#8217;s a pencil-and-paper game for two players, O and X, who take [...]]]></description>
			<content:encoded><![CDATA[<p>During these days I played a bit with Artificial Intelligence for a project I am working on (big news on the horizon) and I&#8217;m coming with a brief introduction to the simplest game you can use to test artificial intelligence. Tic Tac Toe.</p>
<p>It&#8217;s a pencil-and-paper game for two players, O and X, who take turns marking the spaces in a 3×3 grid, usually X  going first. The player who succeeds in placing three respective marks in a horizontal, vertical, or diagonal row wins the game. (source: <a href="http://en.wikipedia.org/wiki/Tic-tac-toe" target = "_blank">Wikipedia</a>).</p>
<p>But most of all, it&#8217;s a good playground to apply artificial intelligence for four reasons:</p>
<p>It&#8217;s a <strong>perfect information game</strong>: all players know all moves that have taken place.</p>
<p>It&#8217;s a <strong>sequential game</strong>: when a player moves, the other player waits. And have the waiting player see the moves of the playing one.</p>
<p>It&#8217;s a <strong>zero sum game</strong>: if one player wins, the ohter loses. No cooperation. </p>
<p>It&#8217;s a <strong>non-random game</strong>: there isn&#8217;t any randomizing element such as dices, dealing of cards, and so on. Non-random games are pure strategy.</p>
<p><strong>How many board configurations?</strong></p>
<p>Now, we need to know how many boards configurations can exist in a Tic Tac Toe game. We&#8217;ll do it using php. We&#8217;ll code an empty board like a string with nine points (<code>.........</code>). Every point represents an empty cell. Then, with a recursive function, we&#8217;ll generate all possible board combinations, assuming the first player puts an <code>X</code> and the second player uses the <code>O</code>.</p>
<p>Here it is the script:<span id="more-3260"></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>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> place_move<span style="color: #009900;">&#40;</span><span style="color: #000088;">$board</span><span style="color: #339933;">,</span><span style="color: #000088;">$player</span><span style="color: #339933;">,</span><span style="color: #000088;">$turn</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$boards</span><span style="color: #339933;">,</span><span style="color: #000088;">$symbols</span><span style="color: #339933;">;</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: #cc66cc;">9</span><span style="color: #339933;">;</span><span style="color: #000088;">$x</span><span style="color: #339933;">++</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;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
               <span style="color: #000088;">$app</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$board</span><span style="color: #339933;">;</span>
               <span style="color: #000088;">$app</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">=</span><span style="color: #000088;">$symbols</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$player</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
               <span style="color: #000088;">$boards</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">substr_count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$app</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">++;</span>
               place_move<span style="color: #009900;">&#40;</span><span style="color: #000088;">$app</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #000088;">$player</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: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$symbols</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;XO&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$boards</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: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
place_move<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.........&quot;</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: #000088;">$end</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</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: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$boards</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$empty_spots</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$values</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt;Combinations with &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">9</span><span style="color: #339933;">-</span><span style="color: #000088;">$empty_spots</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; symbol(s): <span style="color: #006699; font-weight: bold;">$values</span>&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt;Elapsed time: &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$end</span><span style="color: #339933;">-</span><span style="color: #000088;">$start</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>And the result is:</p>
<p>Combinations with <strong>1</strong> symbol(s): <strong>9</strong> &#8211; easy to see, in an empty board you can place an <code>X</code> in any of the nine spots</p>
<p>Combinations with <strong>2</strong> symbol(s): <strong>72</strong> &#8211; for each of the 9 different combinations with one symbol, you can place a <code>O</code> in any of the remaining eight spots. 9*8 =72.</p>
<p>Combinations with <strong>3</strong> symbol(s): <strong>504</strong> &#8211; for each of the 72 previous combinations, you can place an X in any of the remaining seven spots. 72*7 = 504.</p>
<p>Combinations with <strong>4</strong> symbol(s): <strong>3024</strong> &#8211; 504*6</p>
<p>Combinations with <strong>5</strong> symbol(s): <strong>15120</strong> &#8211; 3024*5</p>
<p>Combinations with <strong>6</strong> symbol(s): <strong>60480</strong> &#8211; 15120*4 </p>
<p>Combinations with <strong>7</strong> symbol(s): <strong>181440</strong> &#8211; 60480*3</p>
<p>Combinations with <strong>8</strong> symbol(s): <strong>362880</strong> &#8211; 181440*2</p>
<p>Combinations with <strong>9</strong> symbol(s): <strong>362880</strong> &#8211; 362880*1. Same number as the combinations with 8 symbols, because when there are 8 symbols in game, you can only place an <code>O</code> in just one spot.</p>
<p>Elapsed time: <strong>6.0569689273834</strong> &#8211; six seconds to calculate <strong>986409</strong> different combinations. So the total possible board configurations are <strong>986410</strong>, including the empty board.</p>
<p>According to these results, we can say the number of possible combinations in a board with n symbols is <strong>9!/(9-n)!</strong>.</p>
<p><strong>How many REAL board configurations?</strong></p>
<p>Obviously there&#8217;s something wrong with this script because it does not consider when a player wins. If a player wins, the game is over and there are no more moves. So a lot of board configurations are impossible to reach.</p>
<p>So let&#8217;s modify a bit the script to check for victories and the number of necessary moves to win:</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
</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: #000000; font-weight: bold;">function</span> place_move<span style="color: #009900;">&#40;</span><span style="color: #000088;">$board</span><span style="color: #339933;">,</span><span style="color: #000088;">$player</span><span style="color: #339933;">,</span><span style="color: #000088;">$turn</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$boards</span><span style="color: #339933;">,</span><span style="color: #000088;">$wins</span><span style="color: #339933;">,</span><span style="color: #000088;">$symbols</span><span style="color: #339933;">;</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: #cc66cc;">9</span><span style="color: #339933;">;</span><span style="color: #000088;">$x</span><span style="color: #339933;">++</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;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
               <span style="color: #000088;">$app</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$board</span><span style="color: #339933;">;</span>
               <span style="color: #000088;">$app</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">=</span><span style="color: #000088;">$symbols</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$player</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
               <span style="color: #000088;">$boards</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">substr_count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$app</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">++;</span>
               <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>winning_board<span style="color: #009900;">&#40;</span><span style="color: #000088;">$app</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    place_move<span style="color: #009900;">&#40;</span><span style="color: #000088;">$app</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #000088;">$player</span><span style="color: #339933;">,</span><span style="color: #000088;">$turn</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: #009900;">&#125;</span>
               <span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$wins</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$turn</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: #009900;">&#125;</span>	
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> winning_board<span style="color: #009900;">&#40;</span><span style="color: #000088;">$board</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: #009900;">&#40;</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">&quot;.&quot;</span> and <span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">==</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#125;</span> and <span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">==</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>or
		<span style="color: #009900;">&#40;</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">&quot;.&quot;</span> and <span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">==</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#125;</span> and <span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">==</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>or
		<span style="color: #009900;">&#40;</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">&quot;.&quot;</span> and <span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">==</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">7</span><span style="color: #009900;">&#125;</span> and <span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">7</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">==</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>or
		<span style="color: #009900;">&#40;</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">&quot;.&quot;</span> and <span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">==</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#125;</span> and <span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">==</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>or
		<span style="color: #009900;">&#40;</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">&quot;.&quot;</span> and <span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">==</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#125;</span> and <span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">==</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">7</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>or
		<span style="color: #009900;">&#40;</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">&quot;.&quot;</span> and <span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">==</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#125;</span> and <span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">==</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>or
		<span style="color: #009900;">&#40;</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">&quot;.&quot;</span> and <span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">==</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#125;</span> and <span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">==</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>or
		<span style="color: #009900;">&#40;</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">&quot;.&quot;</span> and <span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">==</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#125;</span> and <span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">==</span><span style="color: #000088;">$board</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
			<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: #b1b100;">else</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>
&nbsp;
<span style="color: #000088;">$symbols</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;XO&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$boards</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;">$wins</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;">$c</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
place_move<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.........&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</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;">$end</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</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: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$boards</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$empty_spots</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$values</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt;Combinations with &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">9</span><span style="color: #339933;">-</span><span style="color: #000088;">$empty_spots</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; symbol(s): <span style="color: #006699; font-weight: bold;">$values</span>&lt;/p&gt;&quot;</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;">$x</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span><span style="color: #000088;">$x</span><span style="color: #339933;">&lt;=</span><span style="color: #cc66cc;">9</span><span style="color: #339933;">;</span><span style="color: #000088;">$x</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt;Wins in &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$x</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; moves: <span style="color: #006699; font-weight: bold;">$wins</span>[<span style="color: #006699; font-weight: bold;">$x</span>]&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt;Elapsed time: &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$end</span><span style="color: #339933;">-</span><span style="color: #000088;">$start</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>And the result is:</p>
<p>Combinations with <strong>1</strong> symbol(s): <strong>9</strong></p>
<p>Combinations with <strong>2</strong> symbol(s): <strong>72</strong></p>
<p>Combinations with <strong>3</strong> symbol(s): <strong>504</strong></p>
<p>Combinations with <strong>4</strong> symbol(s): <strong>3024</strong></p>
<p>Combinations with <strong>5</strong> symbol(s): <strong>15120</strong></p>
<p>Combinations with <strong>6</strong> symbol(s): <strong>54720</strong></p>
<p>Combinations with <strong>7</strong> symbol(s): <strong>148176</strong></p>
<p>Combinations with <strong>8</strong> symbol(s): <strong>200448</strong></p>
<p>Combinations with <strong>9</strong> symbol(s): <strong>127872</strong></p>
<p>Wins in <strong>5</strong> moves: <strong>1440</strong></p>
<p>Wins in <strong>6</strong> moves: <strong>5328</strong></p>
<p>Wins in <strong>7</strong> moves: <strong>47952</strong></p>
<p>Wins in <strong>8</strong> moves: <strong>72576</strong></p>
<p>Wins in <strong>9</strong> moves: <strong>81792</strong></p>
<p>Elapsed time: <strong>4.7160170078278</strong> &#8211; Less than five seconds to generate all possible Tic Tac Toe combinations.</p>
<p>This means <strong><code>X</code> will win</strong> 1440+47952+81792 = <strong>131184 times</strong> while <strong><code>O</code> will win</strong> 5328+72576 = <strong>77904 times</strong>. The first player has more chances to win.</p>
<p>How can we determine the drawn games? They are represented by the number of possible boards with nine symbols (127872) minus the number of wins at the 9th move (81792) = <strong>46080 draws</strong>.</p>
<p>According to these results, next time we&#8217;ll introduce an algorithm to make the computer play Tic Tac Toe.</p>
<p>Meanwhile enjoy these results.</p>
<p>PS: anyone willing to translate this into AS3 or other languages?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/08/26/tic-tac-toe-artificial-intelligence/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Create a Flash game like Blockage &#8211; Movement prototype</title>
		<link>http://www.emanueleferonato.com/2010/08/21/create-a-flash-game-like-blockage-movement-prototype/</link>
		<comments>http://www.emanueleferonato.com/2010/08/21/create-a-flash-game-like-blockage-movement-prototype/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 17:55:10 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3254</guid>
		<description><![CDATA[This is one of those days when you want to make a thing work that way FULLSTOP. And that&#8217;s it&#8230; this is the typical Blockage movement: I wanted to do it without any timeline tween or tricks to change registration point on the fly, just using localToGlobal method. If you aren&#8217;t familiar with this method, [...]]]></description>
			<content:encoded><![CDATA[<p>This is one of those days when you want to make a thing work that way FULLSTOP.</p>
<p>And that&#8217;s it&#8230; this is the typical <a href="http://www.emanueleferonato.com/2010/08/11/create-a-flash-game-like-blockage/">Blockage</a> movement:</p>
<p><embed src="/wp-content/uploads/2010/08/blkg.swf" allowscriptaccess="always" menu="false" quality="high" width="500" height="100" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>I wanted to do it without any timeline tween or tricks to <a href="http://www.emanueleferonato.com/2010/08/04/changing-a-movieclip-registration-point-on-the-fly-with-as3/">change registration point on the fly</a>, just using localToGlobal method. If you aren&#8217;t familiar with this method, read <a href="http://www.emanueleferonato.com/2010/06/22/understanding-as3-localtoglobal-method/">understanding AS3 localToGlobal method</a> first.</p>
<p>So here it is the uncommented and unoptimized prototype. While comments and tutorial will come when I&#8217;ll integrate it into the making of the game, I think this can be useful to someone of you to have a sneak peak of what&#8217;s going on.</p>
<p>This is the main 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;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> blkg extends <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> block<span style="color: #000000; font-weight: bold;">:</span>block_mc=<span style="color: #0033ff; font-weight: bold;">new</span> block_mc<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> blkg<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			block.<span style="color: #004993;">x</span>=<span style="color: #000000; font-weight:bold;">0</span>;
			block.<span style="color: #004993;">y</span>=<span style="color: #000000; font-weight:bold;">50</span>;
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>block<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 <code>block_mc</code> class:<span id="more-3254"></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
</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.events</span>.<span style="color: #004993;">Event</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;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> block_mc 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> point<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Point</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">50</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> defpoint<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Point</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">100</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> rotation_dir=<span style="color: #000000; font-weight:bold;">5</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> steps<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span>=<span style="color: #000000; font-weight:bold;">0</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> block_mc<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</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>,on_enter_frame<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> on_enter_frame<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: #004993;">rotation</span><span style="color: #000000; font-weight: bold;">+</span>=rotation_dir;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>rotation<span style="color: #000000; font-weight: bold;">%</span>90==<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #004993;">rotation</span>=<span style="color: #000000; font-weight:bold;">0</span>;
				steps<span style="color: #000000; font-weight: bold;">++</span>;
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>steps==<span style="color: #000000; font-weight:bold;">9</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					steps=<span style="color: #000000; font-weight:bold;">0</span>;
					rotation_dir<span style="color: #000000; font-weight: bold;">*</span>=<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span>;
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>rotation_dir<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>
						point=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">50</span><span style="color: #000000;">&#41;</span>;
					<span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
						point=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span>,<span style="color: #000000; font-weight:bold;">50</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;">else</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>rotation_dir<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>
						defpoint=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span>defpoint<span style="color: #000000;">&#41;</span>;
					<span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
						defpoint=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">50</span>,<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">add</span><span style="color: #000000;">&#40;</span>defpoint<span style="color: #000000;">&#41;</span>;
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> tmp_point<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Point</span>=<span style="color: #004993;">localToGlobal</span><span style="color: #000000;">&#40;</span>point<span style="color: #000000;">&#41;</span>;
			tmp_point=defpoint.<span style="color: #004993;">subtract</span><span style="color: #000000;">&#40;</span>tmp_point<span style="color: #000000;">&#41;</span>;
			<span style="color: #004993;">x</span><span style="color: #000000; font-weight: bold;">+</span>=tmp_point.<span style="color: #004993;">x</span>;
			<span style="color: #004993;">y</span><span style="color: #000000; font-weight: bold;">+</span>=tmp_point.<span style="color: #004993;">y</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>Just remember I am using a 50 pixel sided square with origin at <code>0,0</code> and that <code>steps==9</code> at <strong>line 18</strong> is used only to make the square go back and forth.</p>
<p><a href="/wp-content/uploads/2010/08/blkg.zip">Download the source code</a> and solve the mystery&#8230; or wait for next step.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/08/21/create-a-flash-game-like-blockage-movement-prototype/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<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 a Flash game like Blockage</title>
		<link>http://www.emanueleferonato.com/2010/08/11/create-a-flash-game-like-blockage/</link>
		<comments>http://www.emanueleferonato.com/2010/08/11/create-a-flash-game-like-blockage/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 16:24:27 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3228</guid>
		<description><![CDATA[Did you play Blockage? It&#8217;s a perfect game to make a tutorial series because at every level it introduces a new feature, so level after level you will see something new both in the game and in the prototype. Other than that, it&#8217;s a tile based puzzle. This first part will focus on level data. [...]]]></description>
			<content:encoded><![CDATA[<p>Did you play <strong><a href="http://www.triqui.com/2010/08/03/blockage/" target = "_blank">Blockage</a></strong>?</p>
<p><a href="http://www.triqui.com/2010/08/03/blockage/" target = "_blank"><img src="/wp-content/uploads/2010/08/blockage.png" /></a></p>
<p>It&#8217;s a perfect game to make a tutorial series because at every level it introduces a new feature, so level after level you will see something new both in the game and in the prototype.</p>
<p>Other than that, it&#8217;s a tile based puzzle.</p>
<p>This first part will focus on level data. Since it&#8217;s a tile based game, you know we should create a bidimensional array, map all levels assigning each tile type a value such as zero for the empty space and one for the walls, and start creating the array tile after tile, just like in <a href="http://www.emanueleferonato.com/2010/05/10/create-a-flash-game-like-rebuild-chile/">Create a Flash game like Rebuild Chile</a>.</p>
<p>In this prototype I will try to &#8220;compress&#8221; the level packing it in a string containing comma separated values.</p>
<p>Let me explain the idea: count, from left to right, from upper to bottom corners, the number of contiguous walls.</p>
<p>There are 49 walls. Then, 14 empty spaces. Then, two walls. And so on. Exluding the actors (the square and the goal), create a string like this one:</p>
<p><code>49,1,14,0,2,1,14,0,2,1,14,0,8,1,1,0,56,1</code></p>
<p>That means the level has 49 walls (marked with <code>1</code>), 14 empty spaces (marked with <code>0</code>), then 2 walls, 14 spaces and so on.</p>
<p>So this code:<span id="more-3228"></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
</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;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> blockage extends <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> const LEVEL_WIDTH<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">16</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> const LEVEL_HEIGHT<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">10</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> leveldata<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>=<span style="color: #990000;">&quot;49,1,14,0,2,1,14,0,2,1,14,0,8,1,1,0,56,1&quot;</span>;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> tmp_level<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: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">level</span><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: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> wall<span style="color: #000000; font-weight: bold;">:</span>wall_mc;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> blockage<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			tmp_level=leveldata.<span style="color: #004993;">split</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;,&quot;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #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>tmp_level.<span style="color: #004993;">length</span>; i<span style="color: #000000; font-weight: bold;">+</span>=<span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> j=<span style="color: #000000; font-weight:bold;">1</span>; j<span style="color: #000000; font-weight: bold;">&lt;</span>=tmp_level<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>; j<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					<span style="color: #004993;">level</span>.<span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>tmp_level<span style="color: #000000;">&#91;</span>i<span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>;
					<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>tmp_level<span style="color: #000000;">&#91;</span>i<span style="color: #000000; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span>==<span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
						wall = <span style="color: #0033ff; font-weight: bold;">new</span> wall_mc<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
						<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>wall<span style="color: #000000;">&#41;</span>;
						wall.<span style="color: #004993;">x</span>=<span style="color: #000000; font-weight:bold;">32</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">level</span>.length<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>LEVEL_WIDTH<span style="color: #000000;">&#41;</span>;
						wall.<span style="color: #004993;">y</span>=<span style="color: #000000; font-weight:bold;">32</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #004993;">Math</span>.<span style="color: #004993;">floor</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">level</span>.length<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>LEVEL_WIDTH<span style="color: #000000;">&#41;</span>;
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Draws the level and stores it in <code>level</code> array, starting from <code>leveldata</code> that is the &#8220;compressed&#8221; level data.</p>
<p><strong>Line 11</strong>: splits <code>leveldata</code> into <code>tmp_level</code> array. It&#8217;s just as if I did</p>
<p><code>tmp_level = [49,1,14,0,2,1,14,0,2,1,14,0,8,1,1,0,56,1];</code></p>
<p>But starting with a string I can easily import levels from an external editor.</p>
<p><strong>Line 12</strong>: loops through all <code>tmp_level</code> <strong>even</strong> elements.</p>
<p><strong>Lines 13-21</strong>: creating the level itself in <code>level</code> array pushing <code>i</code> times <code>i+1</code> value, and if such value is a wall (<code>1</code>), then adding the wall movieclip.</p>
<p>This is the result:</p>
<p><embed src="/wp-content/uploads/2010/08/blockage.swf" allowscriptaccess="always" menu="false" quality="high" width="512" height="320" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>The same old thing made in a different way. Does it make any sense to you?</p>
<p><a href="/wp-content/uploads/2010/08/blockage.zip">Download the source code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/08/11/create-a-flash-game-like-blockage/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>The perfect swf file size of your Flash games</title>
		<link>http://www.emanueleferonato.com/2010/07/23/the-perfect-swf-file-size-of-your-flash-games/</link>
		<comments>http://www.emanueleferonato.com/2010/07/23/the-perfect-swf-file-size-of-your-flash-games/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 11:08:31 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3163</guid>
		<description><![CDATA[When you are making a Flash game, do you worry about the final size of your swf? I had a look at 17.666 games with known filesize actually stored in Triqui.com, parsed from MochiMedia, and that&#8217;s what I found Average swf file size: 0.99MB swf file size # of games % 5MB 499 2.82 Finally, [...]]]></description>
			<content:encoded><![CDATA[<p>When you are making a Flash game, do you worry about the final size of your swf?</p>
<p>I had a look at <strong>17.666</strong> games with known filesize actually stored in <a target ="_blank" href="http://www.triqui.com/">Triqui.com</a>, parsed from <a href="https://www.mochimedia.com/r/972ae333a3c92a2a" target = "_blank">MochiMedia</a>, and that&#8217;s what I found</p>
<p><strong>Average swf file size</strong>: 0.99MB</p>
<table cellpadding="4" cellspacing="1" border="0">
<tr bgcolor = "#e5e5e5">
<td width="100"><strong>swf file size</strong></td>
<td width = "100"><strong># of games</strong></td>
<td width = "100"><strong>%</strong></td>
</tr>
<tr>
<td><100KB</td>
<td>2512</td>
<td>14.22</td>
</tr>
<tr>
<td>100 &#8211; 250KB</td>
<td>3311</td>
<td>18.74</td>
</tr>
<tr>
<td>250 &#8211; 500KB</td>
<td>3477</td>
<td>19.68</td>
</tr>
<tr>
<td>500KB &#8211; 1Mb</td>
<td>3271</td>
<td>18.52</td>
</tr>
<tr>
<td>1MB &#8211; 5MB</td>
<td>4596</td>
<td>26.02</td>
</tr>
<tr>
<td>>5MB</td>
<td>499</td>
<td>2.82</td>
</tr>
</table>
<hr />
<p>Finally, this is a chart representing the number of games (horizontal) for at any size (vertical) with a 250KB step</p>
<p><img src="/wp-content/uploads/2010/07/size.png" /></p>
<p>What&#8217;s your average swf size?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/07/23/the-perfect-swf-file-size-of-your-flash-games/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>More mobile Flash game contests &#8211; $80,000 in prizes!!</title>
		<link>http://www.emanueleferonato.com/2010/07/16/more-mobile-flash-game-contests-80000-in-prizes/</link>
		<comments>http://www.emanueleferonato.com/2010/07/16/more-mobile-flash-game-contests-80000-in-prizes/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 10:31:19 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Contests]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3133</guid>
		<description><![CDATA[If you think $30,000 in prizes aren&#8217;t enough, here they come $50,000 more in prizes from Kongregate&#8216;s Mobile Flash Game Contest and MochiMedia&#8216;s Made for Mobile Contest, for a grand total of $80,000!!! This is the first time in Flash gaming history that three big sites host contests with the same topic, this means you [...]]]></description>
			<content:encoded><![CDATA[<p>If you think $30,000 in prizes aren&#8217;t enough, here they come $50,000 more in prizes from <a href="http://www.kongregate.com/?ref=triqui" target = "_blank">Kongregate</a>&#8216;s Mobile Flash Game Contest and <a href="https://www.mochimedia.com/r/972ae333a3c92a2a" target ="_blank">MochiMedia</a>&#8216;s Made for Mobile Contest, for a grand total of <strong>$80,000</strong>!!!</p>
<p>This is the first time in Flash gaming history that three big sites host contests with the same topic, this means you could enter all contest with the same game&#8230; let&#8217;s make a recap:</p>
<p><strong>Cell Your Flash Game</strong> by <a href="http://www.flashgamelicense.com/" target ="_blank">FlashGameLicense</a></p>
<p><strong>Prizes</strong>: from $2,600 + Adobe Creative Suite 5 Master Collection to $100 (150 places elegible)<br />
<strong>Deadline</strong>: September 6, 2010<br />
<strong>Criteria</strong>: The Game must be able to be played on an Android 2.2 smart phone (the &#8220;Device&#8221;) &#8211; The Game must be of a high quality level and enjoyable to players &#8211; The Game must scale appropriately to multiple screen resolutions, keeping buttons and interactive elements at a usable size &#8211; The Game&#8217;s rescaled user interfaces must work with game logic. For example, hunt-the-pixel games must not become unacceptably difficult &#8211; Game input events that aren&#8217;t supported on the Device &#8211; like mouse-over and mouse-move events &#8211; must not be important to gameplay<br />
<strong>Official page</strong>: <a target = "_blank" href="http://www.flashgamelicense.com/sponsor_pages/adobe/">http://www.flashgamelicense.com/sponsor_pages/adobe/</a> </p>
<p><strong>Mobile Flash Game Contest</strong> by <a href="http://www.kongregate.com/?ref=triqui" target = "_blank">Kongregate</a></p>
<p><strong>Prizes</strong>: from $5,000 + Adobe Creative Suite 5 Web Premium to $750 (15 places elegible)<br />
<strong>Deadline</strong>: August 23, 2010<br />
<strong>Criteria</strong>:Graphics optimized for mobile device; Text/Instructions/scores, clearly legible; buttons large enough to use on touch screen &#8211; Game works regardless of input options (keyboard, touch screen, accelerometer, etc), easy to navigate and play; pause/save options; intuitive; seamless landscape, portrait, and full screen display; leverage and understand the device -Loads fast, built at 25-30 frames/second, fast start up time &#8211; Addictive, unique, can be adopted across multiple audiences &#8211; Built with standards in mind; easy to adapt to other displays quickly with minimal recoding effort; device and player detection, opportunity to integrate with social media.<br />
<strong>Official page</strong>: <a target ="_blank" href="http://www.kongregate.com/pages/mobile-game-contest">http://www.kongregate.com/pages/mobile-game-contest</a></p>
<p><strong>Made for Mobile</strong> by <a href="https://www.mochimedia.com/r/972ae333a3c92a2a" target ="_blank">MochiMedia</a></p>
<p><strong>Prizes</strong>: from $7,000 + Adobe CS5 Master Suite to $50 (105 places elegible)<br />
<strong>Deadline</strong>: September 24, 2010<br />
<strong>Criteria</strong>: Must incorporate Mochi Live Updates &#8211; Must use the Mochi Ads API advertisements &#8211; Must be formatted and performance tested for mobile devices (see rules for more info) &#8211; Must be tagged/keyworded with the phrase &#8220;adobe2010&#8243; &#8211; Highly encouraged to use at least one of several mobile specific features<br />
<strong>Official page</strong>:<a target = "_blank" href=" http://www.mochimedia.com/contest/jul10"> http://www.mochimedia.com/contest/jul10</a></p>
<p>Hope this recap helps. Now, it&#8217;s REALLY time to write some tutorial about mobile developing&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/07/16/more-mobile-flash-game-contests-80000-in-prizes/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
