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

<channel>
	<title>Emanuele Feronato &#187; Actionscript 2</title>
	<atom:link href="http://www.emanueleferonato.com/category/actionscript-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.emanueleferonato.com</link>
	<description>italian geek and PROgrammer</description>
	<lastBuildDate>Mon, 06 Feb 2012 14:28:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>AS2 Games Pack released: source code of 12 commercial AS2 Flash games ready to be downloaded</title>
		<link>http://www.emanueleferonato.com/2011/09/30/as2-games-pack-released-source-code-of-12-commercial-as2-flash-games-ready-to-be-downloaded/</link>
		<comments>http://www.emanueleferonato.com/2011/09/30/as2-games-pack-released-source-code-of-12-commercial-as2-flash-games-ready-to-be-downloaded/#comments</comments>
		<pubDate>Fri, 30 Sep 2011 10:59:25 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 2]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Monetize]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=4710</guid>
		<description><![CDATA[AS2 Games Pack: 12 commercial and successful AS2 Flash games ready to be downloaded, improved, and used for your own projects.]]></description>
			<content:encoded><![CDATA[<p>Although I am not talking about AS2 for almost trhee years, I am receiving continuous requests to keep on posting AS2 tutorials.</p>
<p>While I have no plans about AS2 tutorials, there&#8217;s an interesting deal you can enjoy:</p>
<p>The <strong>AS2 Games Pack</strong>, that is the collection of the 12 Flash games I released during AS2 years, whith more than <strong>50 million loads</strong>!</p>
<p>I am not talking about prototypes, but the full, complete games with source codes. The same games I published, are included here.</p>
<p>Getting the <strong>AS2 Games Pack</strong> is a must if you are Flash game developer because you can grab the source code of successful games, improve the gameplay, change the graphics and you will have a brand new game with a genuine addicting gameplay ready to be published.</p>
<p>Even if you abandoned AS2, you can easily convert the games on AS3 and publish them as AS3 games, or mobile games.</p>
<p>Since I am giving you the games exactly how I made them, in most games you will find more versions, with different APIs which could be outdated, but the source code is fully working.</p>
<p>Let&#8217;s have a look at the games:</p>
<p><strong>1 &#8211; <a href="http://www.emanueleferonato.com/2007/10/28/experiment-monetizing-a-flash-game/">Circle Chain</a></strong></p>
<p><img src="http://www.emanueleferonato.com/images/circlechain.jpg" alt="" /></p>
<p>The game which started it all. My first Flash game, the opener of the experiment which still continues. Reviewed on <a href="http://jayisgames.com/archives/2007/10/circle_chain.php" target="_blank">Jay is Games</a>.</p>
<p><strong>2 &#8211; <a href="http://www.emanueleferonato.com/2007/11/28/christmas-couples-the-finished-poux-prototype/">Christmas Couples</a></strong></p>
<p><img src="http://www.emanueleferonato.com/images/ccouples.jpg" alt="" /></p>
<p>Christmas themed game which can easily ported into mobile devices.</p>
<p><strong>3 &#8211; <a href="http://www.emanueleferonato.com/2007/12/17/tileball-the-first-game-made-with-my-tile-ball-engine/">Tileball</a></strong></p>
<p><img src="http://www.emanueleferonato.com/images/tileball.jpg" alt="" /></p>
<p>A space running game inspired by the classic C64 game <a href="http://c64-wiki.com/index.php/Trailblazer" target="_blank">Trailblazer</a>. There are some sites selling the source code of a prototype of this game at an irrational amount of money.</p>
<p><strong>4 &#8211; <a href="http://www.emanueleferonato.com/2007/12/30/guessnext-complete-flash-game-with-highscores/">GuessNext</a></strong></p>
<p><img src="http://www.emanueleferonato.com/images/guessnextkong.jpg" alt="" /></p>
<p>Card game which have been recently ported into an <a href="http://www.emanueleferonato.com/2011/08/17/play-guessnext-for-iphone-a-web-app-game-powered-by-jquery-mobile/">iPhone Web App</a></p>
<p><strong>5 &#8211; <a href="http://www.emanueleferonato.com/2008/01/12/glomb-the-first-flash-game-to-use-mochiads-leaderboards/">Glomb</a></strong></p>
<p><img src="http://www.emanueleferonato.com/images/glomb.jpg" alt="" /></p>
<p>Grow-avoider game, the very first game to use <a href="https://www.mochimedia.com/r/972ae333a3c92a2a" target="_blank">MochiMedia</a>&#8216;s <a href="http://www.emanueleferonato.com/2011/09/08/guide-to-mochi-media-services-leaderboards/">leaderboards</a>.</p>
<p><strong>6 &#8211; <a href="http://www.emanueleferonato.com/2008/03/04/experiment-monetizing-a-flash-game-part-8/">BallBalance</a></strong></p>
<p><img src="http://www.emanueleferonato.com/images/ballbalance.jpg" alt="" /></p>
<p>Addicting puzzle game sponsored by <a href="http://www.kongregate.com/?referrer=triqui" target="_blank">Kongregate</a>, also featured in <a href="http://www.emanueleferonato.com/2011/03/24/flash-game-development-by-example-my-book-is-on-the-shelves/">my book</a>.</p>
<p><strong>7 &#8211; <a href="http://www.emanueleferonato.com/2008/05/03/experiment-monetizing-a-flash-game-part-9/">Bees n&#8217; Flowers</a></strong></p>
<p><img src="http://www.emanueleferonato.com/images/beez.jpg" alt="" /></p>
<p>Puzzle game with experimental gameplay, interesting for a mobile porting</p>
<p><strong>8 &#8211; <a href="http://www.emanueleferonato.com/2008/05/20/jamag-a-flash-game-youd-better-master/">Jamag</a></strong></p>
<p><img src="http://www.emanueleferonato.com/images/jamag.jpg" alt="" /></p>
<p>Jamag = Just Another Mouse Avoider Game, but with a twist.</p>
<p><strong>9 &#8211; <a href="http://www.emanueleferonato.com/2008/07/07/summer-couples-a-game-made-in-an-airplane/">Summer Couples</a></strong></p>
<p><img src="http://www.emanueleferonato.com/images/summercouples.jpg" alt="" /></p>
<p>Drawing/matching game, I&#8217;d love to see a mobile version of it</p>
<p><strong>10 &#8211; <a href="http://www.emanueleferonato.com/2008/07/23/rrode-the-second-one-week-game/">Rrode</a></strong></p>
<p><img src="http://www.emanueleferonato.com/images/rrodejpg.jpg" alt="" /></p>
<p>One-button game with 2 game modes and 51 levels, sponsored by <a href="http://www.hallpass.com/" target="_blank">Hallpass</a></p>
<p><strong>11 &#8211; <a href="http://www.emanueleferonato.com/2008/11/01/halloween-couples/">Halloween Couples</a></strong></p>
<p><img src="http://www.emanueleferonato.com/images/halloween_couples.jpg" alt="" /></p>
<p>Drawing/matching game on an hexagonal playground</p>
<p><strong>12 &#8211; <a href="http://www.emanueleferonato.com/2008/12/21/play-red-flowers/">Red Flowers</a></strong></p>
<p><img src="http://www.emanueleferonato.com/images/redflowers.jpg" alt="" /></p>
<p>Touch and switch puzzle game with 28 levels</p>
<p>Today, you can have this complete collection of real commercial games for as low as <strong>$9.99</strong></p>
<p>Selling full games source codes is another way to monetize a Flash game in its aftermath, and there are portals looking for source codes to buy, but I wanted to extend the deal to every reader/developer/fan at an extremely low price.</p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="T7ZNBZ3CR6GTW">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG_global.gif" border="0" name="submit" alt="PayPal — The safer, easier way to pay online."><img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"></form>
<p>If you make money out of this package, share your experience and I will happy to publish it on the blog.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2011/09/30/as2-games-pack-released-source-code-of-12-commercial-as2-flash-games-ready-to-be-downloaded/feed/</wfw:commentRss>
		<slash:comments>61</slash:comments>
		</item>
		<item>
		<title>Protect your work from ActionScript code theft with SWF Protector</title>
		<link>http://www.emanueleferonato.com/2010/03/05/protect-your-work-from-actionscript-code-theft-with-swf-protector/</link>
		<comments>http://www.emanueleferonato.com/2010/03/05/protect-your-work-from-actionscript-code-theft-with-swf-protector/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 10:03:32 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 2]]></category>
		<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Reviews]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=2480</guid>
		<description><![CDATA[&#171; I&#8217;ve just found a site that won a top international online advertising award &#8211; and it&#8217;s been blatantly lifted from me! Its a flash application that has the same vectors and almost certainly the same AS code. Is there anything I can do? I&#8217;m in the UK &#8211; they&#8217;re in Brazil. &#187; The guy [...]]]></description>
			<content:encoded><![CDATA[<p>&laquo; I&#8217;ve just found a site that won a top international online advertising award &#8211; and it&#8217;s been blatantly lifted from me!</p>
<p>Its a flash application that has the same vectors and <strong>almost certainly the same AS code</strong>. Is there anything I can do? I&#8217;m in the UK &#8211; they&#8217;re in Brazil. &raquo;</p>
<p>The guy who opened <a href="http://www.webmasterworld.com/webmaster/3033990.htm" target = "_blank">this thread</a> looks quite desperate&#8230; now imagine this happening to your latest Flash game.</p>
<p>That&#8217;s why you <strong>must</strong> protect your code. You don&#8217;t want someone else stealing your work.</p>
<p>I am going to review <a href="http://www.dcomsoft.com/" target = "_blank">DCOM Soft</a>&#8216;s SWF Protector.</p>
<p><a href="http://www.dcomsoft.com/" target = "_blank"><img src="/wp-content/uploads/2010/03/swfpro01.jpg" /></a></p>
<p><strong>SWF Protector</strong></p>
<p><a href="http://www.dcomsoft.com/" target = "_blank">SWF Protector</a> is an swf protector software working through actionscript encryption to secure your actionscript content. This means decompilers won&#8217;t be able to read your actionscript.<span id="more-2480"></span></p>
<p>The most interesting <a href="http://www.dcomsoft.com/" target = "_blank">SWF Protector</a> features are:</p>
<p>* Inexpensive: only $59.95 for a Business License. <a href="http://www.emanueleferonato.com/2009/12/07/milestone-reached-100-with-mochiads/">You can earn twice in just one day with a single game</a>.</p>
<p>* Simple and fast. You can encrypt your SWF with a couple of clicks.</p>
<p>* Cross-platform. Available for Windows, Mac and Linux.</p>
<p>* Mass protection. You can protect several SWFs at once.</p>
<p>This is the interface you&#8217;ll see when you are about to secure your flash content: </p>
<p><img src="/wp-content/uploads/2010/03/swfpro02.jpg" /></p>
<p>I am testing the software on the file created on <a href="http://www.emanueleferonato.com/2010/02/25/box2d-flash-game-creation-tutorial-part-2/">Box2D Flash game creation tutorial – part 2</a> tutorial.</p>
<p>This is the original content of the <code>custom_contact_listener.as</code> file:</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
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D<span style="color: #000066; font-weight: bold;">.</span>Dynamics<span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D<span style="color: #000066; font-weight: bold;">.</span>Collision<span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D<span style="color: #000066; font-weight: bold;">.</span>Collision<span style="color: #000066; font-weight: bold;">.</span>Shapes<span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D<span style="color: #000066; font-weight: bold;">.</span>Dynamics<span style="color: #000066; font-weight: bold;">.</span>Joints<span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D<span style="color: #000066; font-weight: bold;">.</span>Dynamics<span style="color: #000066; font-weight: bold;">.</span>Contacts<span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D<span style="color: #000066; font-weight: bold;">.</span>Common<span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> Box2D<span style="color: #000066; font-weight: bold;">.</span>Common<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #9900cc; font-weight: bold;">class</span> custom_contact_listener <span style="color: #0033ff; font-weight: bold;">extends</span> b2ContactListener <span style="color: #000000;">&#123;</span>
		override <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> BeginContact<span style="color: #000000;">&#40;</span>contact<span style="color: #000066; font-weight: bold;">:</span>b2Contact<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #009900; font-style: italic;">// getting the fixtures that collided</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> fixtureA<span style="color: #000066; font-weight: bold;">:</span>b2Fixture=contact<span style="color: #000066; font-weight: bold;">.</span>GetFixtureA<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> fixtureB<span style="color: #000066; font-weight: bold;">:</span>b2Fixture=contact<span style="color: #000066; font-weight: bold;">.</span>GetFixtureB<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #009900; font-style: italic;">// if the fixture is a sensor, mark the parent body to be removed</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>fixtureB<span style="color: #000066; font-weight: bold;">.</span>IsSensor<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				fixtureB<span style="color: #000066; font-weight: bold;">.</span>GetBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>SetUserData<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;remove&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>fixtureA<span style="color: #000066; font-weight: bold;">.</span>IsSensor<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				fixtureA<span style="color: #000066; font-weight: bold;">.</span>GetBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>SetUserData<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;remove&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Now, I will use a Flash decompiler to extract the same file from an unprotected version of the swf&#8230; here it is:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">//class custom_contact_listener</span>
<span style="color: #9900cc; font-weight: bold;">package</span> 
<span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> Box2D<span style="color: #000066; font-weight: bold;">.</span>Dynamics<span style="color: #000066; font-weight: bold;">.*;</span>
    <span style="color: #0033ff; font-weight: bold;">import</span> Box2D<span style="color: #000066; font-weight: bold;">.</span>Dynamics<span style="color: #000066; font-weight: bold;">.</span>Contacts<span style="color: #000066; font-weight: bold;">.*;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">internal</span> <span style="color: #9900cc; font-weight: bold;">class</span> custom_contact_listener <span style="color: #0033ff; font-weight: bold;">extends</span> Box2D<span style="color: #000066; font-weight: bold;">.</span>Dynamics<span style="color: #000066; font-weight: bold;">.</span>b2ContactListener
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> custom_contact_listener<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> override <span style="color: #339966; font-weight: bold;">function</span> BeginContact<span style="color: #000000;">&#40;</span>arg1<span style="color: #000066; font-weight: bold;">:</span>Box2D<span style="color: #000066; font-weight: bold;">.</span>Dynamics<span style="color: #000066; font-weight: bold;">.</span>Contacts<span style="color: #000066; font-weight: bold;">.</span>b2Contact<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> loc1<span style="color: #000066; font-weight: bold;">:*</span>=arg1<span style="color: #000066; font-weight: bold;">.</span>GetFixtureA<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> loc2<span style="color: #000066; font-weight: bold;">:*</span>=arg1<span style="color: #000066; font-weight: bold;">.</span>GetFixtureB<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>loc2<span style="color: #000066; font-weight: bold;">.</span>IsSensor<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> 
            <span style="color: #000000;">&#123;</span>
                loc2<span style="color: #000066; font-weight: bold;">.</span>GetBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>SetUserData<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;remove&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>loc1<span style="color: #000066; font-weight: bold;">.</span>IsSensor<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> 
            <span style="color: #000000;">&#123;</span>
                loc1<span style="color: #000066; font-weight: bold;">.</span>GetBody<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>SetUserData<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;remove&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>The code is amost more polished&#8230; and obviously it works.</p>
<p>Now let&#8217;s try to do the same on the obfuscated swf made by <a href="http://www.dcomsoft.com/" target = "_blank">SWF Protector</a>&#8230; that&#8217;s what I got (sorry for the italian screenshot: I&#8217;m currently running an italian version of Windows7)</p>
<p><img src="/wp-content/uploads/2010/03/swfpro03.jpg" /></p>
<p>The decompiler crashed&#8230; probably the amount of weird characters inserted by the flash obfuscator made it crash.</p>
<p>In the end, <a href="http://www.dcomsoft.com/" target = "_blank">SWF Protector</a> is simple to use and very fast. It has shown lightning-fast speeds of SWF files loading, processing and saving and uses four reliable protection algorithms.</p>
<p>You can download a trial version on the official site or <strong>win one of three business licenses</strong> I am giving away being the first to reply &#8220;I want one&#8221; when this post will be published on my <a href="http://www.facebook.com/pages/Emanuele-Feronato/50374255154">Facebook Fanpage</a>. This is a special giveaway for three of my Facebook fans. And won&#8217;t be the only one.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/03/05/protect-your-work-from-actionscript-code-theft-with-swf-protector/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>Goodbye AS2&#8230;</title>
		<link>http://www.emanueleferonato.com/2008/11/26/goodbye-as2/</link>
		<comments>http://www.emanueleferonato.com/2008/11/26/goodbye-as2/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 11:02:22 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 2]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=672</guid>
		<description><![CDATA[If you noticed, my last post about AS2 coding is New tile based platform engine &#8211; part 11 &#8211; slopes part b, almost a month ago. I decided to quit talking about AS2 because I am not using it anymore, excluding a couple of games I am about to complete. I am not that happy [...]]]></description>
			<content:encoded><![CDATA[<p>If you noticed, my last post about AS2 coding is <a href="http://www.emanueleferonato.com/2008/10/24/new-tile-based-platform-engine-part-11-slopes-part-b/">New tile based platform engine &#8211; part 11 &#8211; slopes part b</a>, almost a month ago.</p>
<p>I decided to quit talking about AS2 because I am not using it anymore, excluding a couple of games I am about to complete.</p>
<p><img src="/images/my_tombstone.jpg" alt="" /></p>
<p>I am not that happy I had to learn a language I won&#8217;t use anymore, but this happened a lot of times in my life&#8230; from Commodore Basic to AS2, including AMOS, Pascal and some more.</p>
<p>When a programmer quits a language, it&#8217;s not a big problem, but when a blogger does it, he should think about his readers that don&#8217;t want to migrate to a new language.</p>
<p>While I don&#8217;t want to force anybody, let me share some thoughts:</p>
<p><strong>You can get the latest Flash version</strong>, the so called CS4, for <a href="http://www.adobe.com/products/flash/?promoid=BPDEE" target = "_blank">$699</a>, and you can <a href="http://www.adobe.com/downloads/" target = "_blank">download</a> a complete trial working for 30 days.</p>
<p>Even if you don&#8217;t have the money, I suggest you to download the trial, make a couple of simple games in a month and raise the funds to buy the license.</p>
<p><strong>All new cool libraries</strong> are written in AS3, just think about <a href="http://www.emanueleferonato.com/2008/11/20/dragging-objects-with-box2d-flash/">BOX2D</a> and the games you can make with it.</p>
<p><strong>A PROgrammer **must** know the latest languages</strong>, not the old ones. Soon you won&#8217;t find any AS2 tutorial around the web.</p>
<p>Last but not least, you can <strong>make your own custom tombstone</strong> at <a href="http://www.tombstonebuilder.com/" target = "_blank">tombstonebuilder.com</a>.</p>
<p><strong>What about old AS2 tutorials</strong>? Well, the most successful ones will be translated into AS3 using classes. Which one would you like to see first?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2008/11/26/goodbye-as2/feed/</wfw:commentRss>
		<slash:comments>37</slash:comments>
		</item>
		<item>
		<title>Platform engine variation with hangable tiles</title>
		<link>http://www.emanueleferonato.com/2008/11/24/platform-engine-variation-with-hangable-tiles/</link>
		<comments>http://www.emanueleferonato.com/2008/11/24/platform-engine-variation-with-hangable-tiles/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 11:36:49 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 2]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=666</guid>
		<description><![CDATA[This is another version of my platform engine made by Bryan Devlin introducing some graphics, a visual death and hangable roofs. Bryan spread out the code to follow and understand it a bit better. This is what you&#8217;ll get: Notice the hangable tiles, that&#8217;s the major improvement. You can download source code here. Also, Bryan [...]]]></description>
			<content:encoded><![CDATA[<p>This is another version of my platform engine made by <strong>Bryan Devlin</strong> introducing some graphics, a visual death and hangable roofs.</p>
<p>Bryan spread out the code to follow and understand it a bit better.</p>
<p>This is what you&#8217;ll get:</p>
<p><embed src="/downloads/newplat_bryan.swf" menu="false" quality="high" width="500" height="200" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>Notice the hangable tiles, that&#8217;s the major improvement.</p>
<p>You can download source code <a href="/downloads/newplat_bryan.zip">here</a>.</p>
<p>Also, Bryan is working on a game probably started from my engine but with some new features like climbable walls, scrolling maps and timer, and would like some feedback&#8230; here it is the game:</p>
<p><embed src="/downloads/MONKEY_BOY.swf" menu="false" quality="high"  width="300" height="410" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>Thanks Bryan!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2008/11/24/platform-engine-variation-with-hangable-tiles/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>How to ask for help: the Philippines example</title>
		<link>http://www.emanueleferonato.com/2008/11/09/how-to-ask-for-help-the-philippines-example/</link>
		<comments>http://www.emanueleferonato.com/2008/11/09/how-to-ask-for-help-the-philippines-example/#comments</comments>
		<pubDate>Sun, 09 Nov 2008 19:32:37 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 2]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=639</guid>
		<description><![CDATA[Normally everyday I receive about 10 emails asking for help. They all seem to be made with a template, something like this: &#8220;hey this script does not work. Can you fix it?&#8221; Obviously I cannot fix someone else&#8217;s scripts, but sometimes I got really impressed by an help request. It happened about one year ago [...]]]></description>
			<content:encoded><![CDATA[<p>Normally everyday I receive about 10 emails asking for help.</p>
<p>They all seem to be made with a template, something like this: &#8220;hey this script does not work. Can you fix it?&#8221;</p>
<p>Obviously I cannot fix someone else&#8217;s scripts, but sometimes I got really impressed by an help request.</p>
<p>It happened about <a href="http://www.emanueleferonato.com/2007/06/24/i-had-to-do-it/">one year ago</a> and it&#8217;s happening today.</p>
<p>This is an email from <strong>Jv Caalim</strong> from Philippines, in trouble with his computer science thesis&#8230;</p>
<p><img src="/images/museum.jpg" alt="" /></p>
<p>&laquo; Hello Sir, and Good day.</p>
<p>Im Jv Caalim from the Philippines and im a computer science student from AMA computer college (a really crappy school if you ask me..), recently ive been basing my entire Thesis heavily on your tile-based tutorials (which is really really great btw im a fanboy of your site now lol).</p>
<p>My thesis entitled &#8220;Asian Museum&#8221; is an eduactional game aim for highschool students about, some limited scopes on a few Asian countries, it will be like a clone of castlevania (the player defeats an enemy using a linear weapon not by jumping on them) and along the way the player will recieve hints on how to open the door leading to the next level like ex:&#8221;Player battles a monster and gets<br />
Chrysanthemun which is also a name for the national flower of Japan&#8221;, the door will be asking questions about asian countries like, &#8220;what is the national flower of Japan?&#8221;. the boss battle is a turn base system (which is only shown graphically) where random questions about asian history appears on the screen if the player answer it correctly the boss monster gets damaged</p>
<p>As of now i can only say that im still learning on what engine to use, ive also been reading about tonypa&#8217;s tile-based tutorials and it was quite helpfull but still there is one thing thats always leaving me confuse, the Collision engine that was used on tile based platforms engine, and if ever i tried experimenting with the collision engines it always ends messing up the collisions&#8230; sure the collision works if the &#8220;player&#8221; is smaller than the tiles but,</p>
<p>What if the player is bigger than the tiles?? lets say i have a 50&#215;50 tile and the player is 49 pixels in width and 98 pixels in height (so that right = 24, left = -24, top = -49, bottom = 49) so its like the player is 2 tiles high and 1 tile wide, or what if the tile size is 25&#215;25 meaning the player is 4 tiles high and 2 tiles wide? how can i make a collision engine for that?</p>
<p>i already know how all the basic movements of the character works and already applied that to a non tile based platform engine that i made (which has a lot of frustrating collision bugs). im not at all a beginner on programming nor a pro but, i have background on programing on VB and C++ on simple programs, and the basics on programming on AS2 (but im still confuse on AS3).</p>
<p>so i would like to ask for some help or at least a detailed explenantion on how i can fix my collision problems. i know that you are a very busy person and im sorry if i have to ask too much of a favor, im still a student i dont have a job yet so im sorry if i cant pay you anything but, i could at least give you all the rights on the game(thesis), most specially the &#8220;player sprite&#8221; i made by hand (its still not finish but i will give you all of it if its finished), you can also ask me to make you some sprites on your game for free if you like, so pls im begging for help&#8230; the submission for the thesis will be on Dec 6, and i havent really made anything that could be usefull to the game except the sprites.</p>
<p>P.S sorry if my sentences sounds as if i was demanding (or commanding you), my english is a bit bad.</p>
<p>Hoping for your relpy and more power to your site<br />
(some of my recent experiments on .fla is attach on this email pls do scan it first for precausions) &raquo;</p>
<p>You will find the files <a href="/downloads/jv.rar">here</a>.</p>
<p>I hope Jv (I am really curious to know does it sound this name) can get some help, maybe someone can save his thesis.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2008/11/09/how-to-ask-for-help-the-philippines-example/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ActionScript 2.0 to 3.0 Migration Cheatsheet</title>
		<link>http://www.emanueleferonato.com/2008/11/02/actionscript-20-to-30-migration-cheatsheet/</link>
		<comments>http://www.emanueleferonato.com/2008/11/02/actionscript-20-to-30-migration-cheatsheet/#comments</comments>
		<pubDate>Sun, 02 Nov 2008 12:08:26 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 2]]></category>
		<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Links]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=615</guid>
		<description><![CDATA[If you are worried about the changes introduced by AS3 and would like a cheatsheet for a quick reference of most of them, then you should take a look at http://actionscriptcheatsheet.com/ This site provides some interesting printable quick reference cards for the ActionScript language. AS3, Flex, AIR, Papervision, and more. Unfortunately the site seems to [...]]]></description>
			<content:encoded><![CDATA[<p>If you are worried about the changes introduced by AS3 and would like a cheatsheet for a quick reference of most of them, then you should take a look at <a href="http://actionscriptcheatsheet.com/" target = "_blank">http://actionscriptcheatsheet.com/</a></p>
<p>This site provides some interesting printable quick reference cards for the ActionScript language. AS3, Flex, AIR, Papervision, and more.</p>
<p>Unfortunately the site seems to be inactive for almost a year, so I suggest you to download them quickly.</p>
<p>This is the ActionScript 2.0 to 3.0 migration cheatsheet</p>
<p><iframe src = "/stuff/cheatsheet/as3cs_migration.pdf" width = "500" height = "400"></iframe></p>
<p>In the <a href="http://actionscriptcheatsheet.com/blog/quick-referencecheatsheet-for-actionscript-20/" target = "_blank">downloads page</a> you will find more.</p>
<p>Hope this will help you in the migration.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2008/11/02/actionscript-20-to-30-migration-cheatsheet/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New tile based platform engine &#8211; part 11 &#8211; slopes part b</title>
		<link>http://www.emanueleferonato.com/2008/10/24/new-tile-based-platform-engine-part-11-slopes-part-b/</link>
		<comments>http://www.emanueleferonato.com/2008/10/24/new-tile-based-platform-engine-part-11-slopes-part-b/#comments</comments>
		<pubDate>Fri, 24 Oct 2008 11:44:23 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 2]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=594</guid>
		<description><![CDATA[As said in New tile based platform engine &#8211; part 11 &#8211; slopes part a, the game needed a fix for the jump from/on slope bug. In part b the bug becomes a glitch&#8230; now you can jump from/on the slope but sometimes there is a &#8220;rebounce&#8221; glitch. It&#8217;s very easy to determine why it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>As said in <a href="http://www.emanueleferonato.com/2008/10/19/new-tile-banew-tile-based-platform-engine-part-11-slopes-part-ased-platform-engine-part-11-slopes/">New tile based platform engine &#8211; part 11 &#8211; slopes part a</a>, the game needed a fix for the jump from/on slope bug.</p>
<p>In part b the bug becomes a glitch&#8230; now you can jump from/on the slope but sometimes there is a &#8220;rebounce&#8221; glitch.</p>
<p>It&#8217;s very easy to determine why it&#8217;s happening and fix it&#8230; I am just leaving the explication for next time because I just got my <a href="http://www.emanueleferonato.com/2008/10/21/when-you-realize-you-know-nothing/">computer repaired</a> and need to do a lot of things.</p>
<p>I just wanted to answer a question about senseless slopes and <a href="http://www.thewayoftheninja.org/index.html" target ="_blank">N game</a> mechanics.</p>
<p>There is a lot of difference between my tile based engine and a <a href="http://www.harveycartel.org/metanet/tutorials/tutorialB.html" target = "_blank">raycasting</a> one.</p>
<p>Maybe I&#8217;ll cover it in next future.</p>
<p>Meanwhile, you are invited to take a look at the source code and fix the glitch at <strong>line 338</strong><span id="more-594"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
</pre></td><td class="code"><pre class="actionscript2" style="font-family:monospace;">walkable_tiles = Array(0, 5, 6, 7, 10, 11);
tile_size = 20;
ground_acceleration = 1;
ground_friction = 0.8;
air_acceleration = 0.5;
air_friction = 0.7;
ice_acceleration = 0.15;
ice_friction = 0.95;
treadmill_speed = 2;
max_speed = 3;
xspeed = 0;
yspeed = 0;
falling = false;
jumping = false;
on_slope = false;
gravity = 0.5;
jump_speed = 6;
climbing = false;
climb_speed = 0.8;
level = new Array();
enemy = new Array();
coin = new Array();
key = new Array();
level[0] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
level[1] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1];
level[2] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 1, 0, 0, 0, 0, 1];
level[3] = [1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 1];
level[4] = [1, 0, 1, 2, 2, 1, 0, 4, 4, 8, 3, 3, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 1];
level[5] = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 6, 0, 0, 0, 0, 0, 1];
level[6] = [1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 1, 0, 0, 0, 0, 0, 1];
level[7] = [1, 1, 1, 0, 0, 1, 0, 0, 0, 10, 1, 11, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 1];
level[8] = [1, 1, 1, 1, 0, 9, 0, 0, 10, 1, 1, 1, 11, 0, 7, 0, 0, 6, 0, 0, 0, 0, 7, 0, 1];
level[9] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 1, 4, 4, 1, 8, 1, 8, 1];
player = [10, 6];
enemy[0] = [10, 3, -2];
enemy[1] = [3, 3, -2];
coin[0] = [2, 2];
coin[1] = [23, 4];
key[0] = [1, 5, 5, 8];
function create_level(l) {
	_root.createEmptyMovieClip(&quot;level_container&quot;,1);
	level_height = l.length;
	level_width = l[0].length;
	for (y=0; y&lt;level_height; y++) {
		for (x=0; x&lt;level_width; x++) {
			if (l[y][x] != 0) {
				t = level_container.attachMovie(&quot;tile&quot;, &quot;t&quot;+y+&quot;_&quot;+x, _root.level_container.getNextHighestDepth(), {_x:x*tile_size, _y:y*tile_size});
				t.gotoAndStop(l[y][x]);
			}
		}
	}
	place_player();
	for (x=0; x&lt;coin.length; x++) {
		coin_mc = level_container.attachMovie(&quot;coin&quot;, &quot;coin_&quot;+_root.level_container.getNextHighestDepth(), _root.level_container.getNextHighestDepth(), {_x:coin[x][0]*tile_size+tile_size/2, _y:coin[x][1]*tile_size+tile_size/2+1});
		coin_mc.onEnterFrame = function() {
			if (this.hitTest(level_container.hero._x, level_container.hero._y, true)) {
				this.removeMovieClip();
			}
		};
	}
	for (x=0; x&lt;key.length; x++) {
		key_mc = level_container.attachMovie(&quot;key&quot;, &quot;key&quot;+_root.level_container.getNextHighestDepth(), _root.level_container.getNextHighestDepth(), {_x:key[x][0]*tile_size+tile_size/2, _y:key[x][1]*tile_size+tile_size/2+1});
		key_mc.ind = x;
		key_mc.onEnterFrame = function() {
			if (this.hitTest(level_container.hero._x, level_container.hero._y, true)) {
				open_x = [key[this.ind][2]];
				open_y = [key[this.ind][3]];
				level[open_y][open_x] = 0;
				_root.level_container[&quot;t&quot;+open_y+&quot;_&quot;+open_x].removeMovieClip();
				this.removeMovieClip();
			}
		};
	}
	for (x=0; x&lt;enemy.length; x++) {
		foe = level_container.attachMovie(&quot;patrol&quot;, &quot;patrol_&quot;+_root.level_container.getNextHighestDepth(), _root.level_container.getNextHighestDepth(), {_x:enemy[x][0]*tile_size+tile_size/2, _y:enemy[x][1]*tile_size+tile_size/2+1});
		foe.speed = enemy[x][2];
		foe.onEnterFrame = function() {
			this.x_pos = this._x;
			this.y_pos = this._y;
			this.x_pos += this.speed;
			this.left_foot_x = Math.floor((this.x_pos-6)/tile_size);
			this.right_foot_x = Math.floor((this.x_pos+5)/tile_size);
			this.foot_y = Math.floor((this.y_pos+9)/tile_size);
			this.bottom = Math.floor((this.y_pos+8)/tile_size);
			this.left_foot = level[this.foot_y][this.left_foot_x];
			this.right_foot = level[this.foot_y][this.right_foot_x];
			this.left = level[this.bottom][this.left_foot_x];
			this.right = level[this.bottom][this.right_foot_x];
			if (this.left_foot != 0 and this.right_foot != 0 and this.left == 0 and this.right == 0) {
				this._x = this.x_pos;
			} else {
				this.speed *= -1;
			}
		};
	}
}
create_level(level);
_root.onEnterFrame = function() {
	ground_under_feet();
	walking = false;
	climbing = false;
	if (Key.isDown(Key.LEFT)) {
		xspeed -= speed;
		walking = true;
	}
	if (Key.isDown(Key.RIGHT)) {
		xspeed += speed;
		walking = true;
	}
	if (Key.isDown(Key.UP)) {
		get_edges();
		if (top_right == 6 or bottom_right == 6 or top_left == 6 or bottom_left == 6) {
			jumping = false;
			falling = false;
			climbing = true;
			climbdir = -1;
		}
	}
	if (Key.isDown(Key.DOWN)) {
		get_edges();
		if ((over == &quot;ladder&quot;) or (top_right == 6 or bottom_right == 6 or top_left == 6 or bottom_left == 6)) {
			jumping = false;
			falling = false;
			climbing = true;
			climbdir = 1;
		}
	}
	if (Key.isDown(Key.SPACE)) {
		//get_edges();
		if (!falling and !jumping) {
			jumping = true;
			yspeed = -jump_speed;
		}
	}
	if (!walking) {
		xspeed *= friction;
		if (Math.abs(xspeed)&lt;0.5) {
			xspeed = 0;
		}
	}
	if (xspeed&gt;max_speed) {
		xspeed = max_speed;
	}
	if (xspeed&lt;max_speed*-1) {
		xspeed = max_speed*-1;
	}
	if (falling or jumping) {
		yspeed += gravity;
	}
	if (climbing) {
		yspeed = climb_speed*climbdir;
	}
	if (!falling and !jumping and !climbing) {
		yspeed = 0;
	}
	xspeed += bonus_speed;
	check_collisions();
	level_container.hero._x = x_pos;
	level_container.hero._y = y_pos;
	xspeed -= bonus_speed;
};
function ground_under_feet() {
	bonus_speed = 0;
	left_foot_x = Math.floor((x_pos-6)/tile_size);
	right_foot_x = Math.floor((x_pos+5)/tile_size);
	foot_y = Math.floor((y_pos+9)/tile_size);
	left_foot = level[foot_y][left_foot_x];
	right_foot = level[foot_y][right_foot_x];
	if (left_foot != 0) {
		current_tile = left_foot;
	} else {
		current_tile = right_foot;
	}
	switch (current_tile) {
		case 0 :
			over = &quot;air&quot;;
			speed = air_acceleration;
			friction = air_friction;
			falling = true;
			break;
		case 1 :
			over = &quot;ground&quot;;
			speed = ground_acceleration;
			friction = ground_friction;
			break;
		case 2 :
			over = &quot;ice&quot;;
			speed = ice_acceleration;
			friction = ice_friction;
			break;
		case 3 :
			over = &quot;treadmill&quot;;
			speed = ground_acceleration;
			friction = ground_friction;
			bonus_speed = -treadmill_speed;
			break;
		case 4 :
			over = &quot;treadmill&quot;;
			speed = ground_acceleration;
			friction = ground_friction;
			bonus_speed = treadmill_speed;
			break;
		case 5 :
			over = &quot;cloud&quot;;
			speed = ground_acceleration;
			friction = ground_friction;
			break;
		case 6 :
			over = &quot;ladder&quot;;
			speed = ground_acceleration;
			friction = ground_friction;
			break;
		case 7 :
			over = &quot;trampoline&quot;;
			speed = ground_acceleration;
			friction = ground_friction;
			break;
		case 8 :
			over = &quot;spikes&quot;;
			if (left_foot == 8 and right_foot == 8) {
				place_player();
			}
		default :
			over = &quot;ground&quot;;
			speed = ground_acceleration;
			friction = ground_friction;
			break;
	}
}
function check_collisions() {
	get_edges();
	is_on_slope();
	y_pos += yspeed;
	get_edges();
	// collision to the bottom 
	if (yspeed&gt;0 and !on_slope) {
		if ((bottom_right != 0 and bottom_right != 6 and bottom_right != 10 and bottom_right != 11) or (bottom_left != 0 and bottom_left != 6 and bottom_left != 10 and bottom_left != 11)) {
			// not a cloud...
			if (bottom_right != 5 and bottom_left != 5) {
				// a trampoline
				if ((bottom_right == 7 or bottom_left == 7) and (Math.abs(yspeed)&gt;1)) {
					yspeed = yspeed*-1;
					jumping = true;
					falling = true;
				} else {
					y_pos = bottom*tile_size-9;
					yspeed = 0;
					falling = false;
					jumping = false;
				}
			} else {
				//cloud
				if (prev_bottom&lt;bottom) {
					y_pos = bottom*tile_size-9;
					yspeed = 0;
					falling = false;
					jumping = false;
				}
			}
		}
	}
	// collision to the top                                                                                                               
	if (yspeed&lt;0) {
		if ((top_right != 0 and top_right != 5 and top_right != 6) or (top_left != 0 and top_left != 5 and top_left != 6)) {
			y_pos = bottom*tile_size+1+8;
			yspeed = 0;
			falling = false;
			jumping = false;
		}
	}
	x_pos += xspeed;
	get_edges();
	// collision to the left           
	if (xspeed&lt;0) {
		if (!is_walkable(top_left) or !is_walkable(bottom_left)) {
			x_pos = (left+1)*tile_size+6;
			xspeed = 0;
		}
	}
	// collision to the right                                                                                                                                      
	if (xspeed&gt;0) {
		if (!is_walkable(top_right) or !is_walkable(bottom_right)) {
			x_pos = right*tile_size-6;
			xspeed = 0;
		}
	}
	prev_bottom = bottom;
}
function get_edges() {
	// right edge
	right = Math.floor((x_pos+5)/tile_size);
	// left edge   
	left = Math.floor((x_pos-6)/tile_size);
	// bottom edge
	bottom = Math.floor((y_pos+8)/tile_size);
	// top edge
	top = Math.floor((y_pos-9)/tile_size);
	// adjacent tiles
	top_right = level[top][right];
	top_left = level[top][left];
	bottom_left = level[bottom][left];
	bottom_right = level[bottom][right];
}
function place_player() {
	level_container.hero.removeMovieClip();
	x_pos = player[0]*tile_size+tile_size/2;
	y_pos = player[1]*tile_size+tile_size/2+1;
	level_container.attachMovie(&quot;hero&quot;,&quot;hero&quot;,_root.level_container.getNextHighestDepth(),{_x:x_pos, _y:y_pos});
}
function is_walkable(tile) {
	walkable = false;
	if (!on_slope) {
		for (x=0; x&lt;walkable_tiles.length; x++) {
			if (tile == walkable_tiles[x]) {
				walkable = true;
				break;
			}
		}
	} else {
		walkable = true;
	}
	return (walkable);
}
function is_on_slope() {
	on_slope = false;
	x_slope_detector = Math.floor(x_pos/tile_size);
	y_slope_detector = Math.floor(y_pos/tile_size);
	if (jumping or falling) {
		if (level[y_slope_detector][x_slope_detector] == 10 or level[y_slope_detector][x_slope_detector] == 11) {
			if (level[y_slope_detector][x_slope_detector] == 10) {
				x_offset = tile_size-x_pos%tile_size;
			}
			// could be an &quot;else&quot;...               
			if (level[y_slope_detector][x_slope_detector] == 11) {
				x_offset = x_pos%tile_size;
			}
			if (y_pos&gt;Math.floor(y_pos/tile_size)*tile_size-9+x_offset) {
				// rebounce fix here
			}
		}
	}
	// could NOT be an else  
	if (!jumping and !falling) {
		if (level[y_slope_detector+1][x_slope_detector] == 10 or level[y_slope_detector+1][x_slope_detector] == 11) {
			y_pos = (y_slope_detector+1)*tile_size+tile_size/2+1;
			y_slope_detector += 1;
		}
		if (level[y_slope_detector][x_slope_detector] == 10 or level[y_slope_detector][x_slope_detector] == 11) {
			if (level[y_slope_detector][x_slope_detector] == 10) {
				x_offset = tile_size-x_pos%tile_size;
			}
			// could be an &quot;else&quot;...               
			if (level[y_slope_detector][x_slope_detector] == 11) {
				x_offset = x_pos%tile_size;
			}
			y_pos = Math.floor(y_pos/tile_size)*tile_size-9+x_offset;
			on_slope = true;
		}
	}
	if (!jumping and !falling and !on_slope and over != &quot;ladder&quot;) {
		y_pos = (y_slope_detector)*tile_size+tile_size/2+1;
	}
}</pre></td></tr></table></div>

<p>Enjoy the result</p>
<p><embed src="/downloads/newplat12.swf" allowscriptaccess="always" menu="false" quality="high" width="500" height="200" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></p>
<p><a href="/downloads/newplat12.zip">Download the source code</a> and have fun</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2008/10/24/new-tile-based-platform-engine-part-11-slopes-part-b/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>New tile based platform engine &#8211; part 11 &#8211; slopes part a</title>
		<link>http://www.emanueleferonato.com/2008/10/19/new-tile-banew-tile-based-platform-engine-part-11-slopes-part-ased-platform-engine-part-11-slopes/</link>
		<comments>http://www.emanueleferonato.com/2008/10/19/new-tile-banew-tile-based-platform-engine-part-11-slopes-part-ased-platform-engine-part-11-slopes/#comments</comments>
		<pubDate>Sun, 19 Oct 2008 17:14:16 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 2]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=583</guid>
		<description><![CDATA[You asked for it, I made it&#8230; ladies and gentlemen&#8230; SLOPES! (applause). I decided to split slopes in two parts, because they are a bit more difficult than other tile types. In this part, you can walk on slopes but you can&#8217;t jump on/from them. Oh, well, you can actually jump or land on them, [...]]]></description>
			<content:encoded><![CDATA[<p>You asked for it, I made it&#8230; ladies and gentlemen&#8230; SLOPES! (applause).</p>
<p>I decided to split slopes in two parts, because they are a bit more difficult than other tile types.</p>
<p>In this part, you can walk on slopes but you can&#8217;t jump on/from them. Oh, well, you can actually jump or land on them, but without the second part of the code, there could be some glitches.</p>
<p>Obviously if you want to suggest your jumping routine, you&#8217;re welcome.</p>
<p>Slopes need a lot of rules in order to work, that can be summarized in one big rule: don&#8217;t make senseless slopes.</p>
<p>For senseless slopes I mean everything&#8230; senseless&#8230; refer to the picture:</p>
<p><img src="/images/slopes.png" alt="" /></p>
<p>Green shapes show some possible slopes while red ones show impossible ones.</p>
<p>Then the <code>is_on_slope</code> function solves slope walking.</p>
<p>Once I&#8217;ll publish jumping routine, I&#8217;ll write a detailed slope tutorial.</p>
<p>Meanwhile take the source code:<span id="more-583"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
</pre></td><td class="code"><pre class="actionscript2" style="font-family:monospace;">walkable_tiles = Array(0, 5, 6, 7, 10, 11);
tile_size = 20;
ground_acceleration = 1;
ground_friction = 0.8;
air_acceleration = 0.5;
air_friction = 0.7;
ice_acceleration = 0.15;
ice_friction = 0.95;
treadmill_speed = 2;
max_speed = 3;
xspeed = 0;
yspeed = 0;
falling = false;
on_slope = false;
gravity = 0.5;
jump_speed = 6;
climbing = false;
climb_speed = 0.8;
level = new Array();
enemy = new Array();
coin = new Array();
key = new Array();
level[0] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
level[1] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1];
level[2] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 1, 0, 0, 0, 0, 1];
level[3] = [1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 1];
level[4] = [1, 0, 1, 2, 2, 1, 0, 4, 4, 8, 3, 3, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 1];
level[5] = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 6, 0, 0, 0, 0, 0, 1];
level[6] = [1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 1, 0, 0, 0, 0, 0, 1];
level[7] = [1, 1, 1, 0, 0, 1, 0, 0, 0, 10, 1, 11, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 1];
level[8] = [1, 1, 1, 1, 0, 9, 0, 0, 10, 1, 1, 1, 11, 0, 7, 0, 0, 6, 0, 0, 0, 0, 7, 0, 1];
level[9] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 1, 4, 4, 1, 8, 1, 8, 1];
player = [10, 6];
enemy[0] = [10, 3, -2];
enemy[1] = [3, 3, -2];
coin[0] = [2, 2];
coin[1] = [23, 4];
key[0] = [1, 5, 5, 8];
function create_level(l) {
	_root.createEmptyMovieClip(&quot;level_container&quot;,1);
	level_height = l.length;
	level_width = l[0].length;
	for (y=0; y&lt;level_height; y++) {
		for (x=0; x&lt;level_width; x++) {
			if (l[y][x] != 0) {
				t = level_container.attachMovie(&quot;tile&quot;, &quot;t&quot;+y+&quot;_&quot;+x, _root.level_container.getNextHighestDepth(), {_x:x*tile_size, _y:y*tile_size});
				t.gotoAndStop(l[y][x]);
			}
		}
	}
	place_player();
	for (x=0; x&lt;coin.length; x++) {
		coin_mc = level_container.attachMovie(&quot;coin&quot;, &quot;coin_&quot;+_root.level_container.getNextHighestDepth(), _root.level_container.getNextHighestDepth(), {_x:coin[x][0]*tile_size+tile_size/2, _y:coin[x][1]*tile_size+tile_size/2+1});
		coin_mc.onEnterFrame = function() {
			if (this.hitTest(level_container.hero._x, level_container.hero._y, true)) {
				this.removeMovieClip();
			}
		};
	}
	for (x=0; x&lt;key.length; x++) {
		key_mc = level_container.attachMovie(&quot;key&quot;, &quot;key&quot;+_root.level_container.getNextHighestDepth(), _root.level_container.getNextHighestDepth(), {_x:key[x][0]*tile_size+tile_size/2, _y:key[x][1]*tile_size+tile_size/2+1});
		key_mc.ind = x;
		key_mc.onEnterFrame = function() {
			if (this.hitTest(level_container.hero._x, level_container.hero._y, true)) {
				open_x = [key[this.ind][2]];
				open_y = [key[this.ind][3]];
				level[open_y][open_x] = 0;
				_root.level_container[&quot;t&quot;+open_y+&quot;_&quot;+open_x].removeMovieClip();
				this.removeMovieClip();
			}
		};
	}
	for (x=0; x&lt;enemy.length; x++) {
		foe = level_container.attachMovie(&quot;patrol&quot;, &quot;patrol_&quot;+_root.level_container.getNextHighestDepth(), _root.level_container.getNextHighestDepth(), {_x:enemy[x][0]*tile_size+tile_size/2, _y:enemy[x][1]*tile_size+tile_size/2+1});
		foe.speed = enemy[x][2];
		foe.onEnterFrame = function() {
			this.x_pos = this._x;
			this.y_pos = this._y;
			this.x_pos += this.speed;
			this.left_foot_x = Math.floor((this.x_pos-6)/tile_size);
			this.right_foot_x = Math.floor((this.x_pos+5)/tile_size);
			this.foot_y = Math.floor((this.y_pos+9)/tile_size);
			this.bottom = Math.floor((this.y_pos+8)/tile_size);
			this.left_foot = level[this.foot_y][this.left_foot_x];
			this.right_foot = level[this.foot_y][this.right_foot_x];
			this.left = level[this.bottom][this.left_foot_x];
			this.right = level[this.bottom][this.right_foot_x];
			if (this.left_foot != 0 and this.right_foot != 0 and this.left == 0 and this.right == 0) {
				this._x = this.x_pos;
			}
			else {
				this.speed *= -1;
			}
		};
	}
}
create_level(level);
_root.onEnterFrame = function() {
	ground_under_feet();
	walking = false;
	climbing = false;
	if (Key.isDown(Key.LEFT)) {
		xspeed -= speed;
		walking = true;
	}
	if (Key.isDown(Key.RIGHT)) {
		xspeed += speed;
		walking = true;
	}
	if (Key.isDown(Key.UP)) {
		get_edges();
		if (top_right == 6 or bottom_right == 6 or top_left == 6 or bottom_left == 6) {
			jumping = false;
			falling = false;
			climbing = true;
			climbdir = -1;
		}
	}
	if (Key.isDown(Key.DOWN)) {
		get_edges();
		if ((over == &quot;ladder&quot;) or (top_right == 6 or bottom_right == 6 or top_left == 6 or bottom_left == 6)) {
			jumping = false;
			falling = false;
			climbing = true;
			climbdir = 1;
		}
	}
	if (Key.isDown(Key.SPACE)) {
		//get_edges();
		if (!falling and !jumping) {
			jumping = true;
			yspeed = -jump_speed;
		}
	}
	if (!walking) {
		xspeed *= friction;
		if (Math.abs(xspeed)&lt;0.5) {
			xspeed = 0;
		}
	}
	if (xspeed&gt;max_speed) {
		xspeed = max_speed;
	}
	if (xspeed&lt;max_speed*-1) {
		xspeed = max_speed*-1;
	}
	if (falling or jumping) {
		yspeed += gravity;
	}
	if (climbing) {
		yspeed = climb_speed*climbdir;
	}
	if (!falling and !jumping and !climbing) {
		yspeed = 0;
	}
	xspeed += bonus_speed;
	check_collisions();
	level_container.hero._x = x_pos;
	level_container.hero._y = y_pos;
	xspeed -= bonus_speed;
};
function ground_under_feet() {
	bonus_speed = 0;
	left_foot_x = Math.floor((x_pos-6)/tile_size);
	right_foot_x = Math.floor((x_pos+5)/tile_size);
	foot_y = Math.floor((y_pos+9)/tile_size);
	left_foot = level[foot_y][left_foot_x];
	right_foot = level[foot_y][right_foot_x];
	if (left_foot != 0) {
		current_tile = left_foot;
	}
	else {
		current_tile = right_foot;
	}
	switch (current_tile) {
		case 0 :
			over = &quot;air&quot;;
			speed = air_acceleration;
			friction = air_friction;
			falling = true;
			break;
		case 1 :
			over = &quot;ground&quot;;
			speed = ground_acceleration;
			friction = ground_friction;
			break;
		case 2 :
			over = &quot;ice&quot;;
			speed = ice_acceleration;
			friction = ice_friction;
			break;
		case 3 :
			over = &quot;treadmill&quot;;
			speed = ground_acceleration;
			friction = ground_friction;
			bonus_speed = -treadmill_speed;
			break;
		case 4 :
			over = &quot;treadmill&quot;;
			speed = ground_acceleration;
			friction = ground_friction;
			bonus_speed = treadmill_speed;
			break;
		case 5 :
			over = &quot;cloud&quot;;
			speed = ground_acceleration;
			friction = ground_friction;
			break;
		case 6 :
			over = &quot;ladder&quot;;
			speed = ground_acceleration;
			friction = ground_friction;
			break;
		case 7 :
			over = &quot;trampoline&quot;;
			speed = ground_acceleration;
			friction = ground_friction;
			break;
		case 8 :
			over = &quot;spikes&quot;;
			if (left_foot == 8 and right_foot == 8) {
				place_player();
			}
		default :
			over = &quot;ground&quot;;
			speed = ground_acceleration;
			friction = ground_friction;
			break;
	}
}
function check_collisions() {
	get_edges();
	is_on_slope();
	y_pos += yspeed;
	get_edges();
	// collision to the bottom 
	if (yspeed&gt;0 and !on_slope) {
		if ((bottom_right != 0 and bottom_right != 6 and bottom_right != 10) or (bottom_left != 0 and bottom_left != 6 and bottom_left != 10)) {
			// not a cloud...
			if (bottom_right != 5 and bottom_left != 5) {
				// a trampoline
				if ((bottom_right == 7 or bottom_left == 7) and (Math.abs(yspeed)&gt;1)) {
					yspeed = yspeed*-1;
					jumping = true;
					falling = true;
				}
				else {
					y_pos = bottom*tile_size-9;
					yspeed = 0;
					falling = false;
					jumping = false;
				}
			}
			else {
				//cloud
				if (prev_bottom&lt;bottom) {
					y_pos = bottom*tile_size-9;
					yspeed = 0;
					falling = false;
					jumping = false;
				}
			}
		}
	}
	// collision to the top                                                                                                   
	if (yspeed&lt;0 and !on_slope) {
		if ((top_right != 0 and top_right != 5 and top_right != 6) or (top_left != 0 and top_left != 5 and top_left != 6)) {
			y_pos = bottom*tile_size+1+8;
			yspeed = 0;
			falling = false;
			jumping = false;
		}
	}
	x_pos += xspeed;
	get_edges();
	// collision to the left           
	if (xspeed&lt;0) {
		if (!is_walkable(top_left) or !is_walkable(bottom_left)) {
			x_pos = (left+1)*tile_size+6;
			xspeed = 0;
		}
	}
	// collision to the right                                                                                                                          
	if (xspeed&gt;0) {
		if (!is_walkable(top_right) or !is_walkable(bottom_right)) {
			x_pos = right*tile_size-6;
			xspeed = 0;
		}
	}
	prev_bottom = bottom;
}
function get_edges() {
	// right edge
	right = Math.floor((x_pos+5)/tile_size);
	// left edge   
	left = Math.floor((x_pos-6)/tile_size);
	// bottom edge
	bottom = Math.floor((y_pos+8)/tile_size);
	// top edge
	top = Math.floor((y_pos-9)/tile_size);
	// adjacent tiles
	top_right = level[top][right];
	top_left = level[top][left];
	bottom_left = level[bottom][left];
	bottom_right = level[bottom][right];
}
function place_player() {
	level_container.hero.removeMovieClip();
	x_pos = player[0]*tile_size+tile_size/2;
	y_pos = player[1]*tile_size+tile_size/2+1;
	level_container.attachMovie(&quot;hero&quot;,&quot;hero&quot;,_root.level_container.getNextHighestDepth(),{_x:x_pos, _y:y_pos});
}
function is_walkable(tile) {
	walkable = false;
	if (!on_slope) {
		for (x=0; x&lt;walkable_tiles.length; x++) {
			if (tile == walkable_tiles[x]) {
				walkable = true;
				break;
			}
		}
	}
	else {
		walkable = true;
	}
	return (walkable);
}
function is_on_slope() {
	x_slope_detector = Math.floor(x_pos/tile_size);
	y_slope_detector = Math.floor(y_pos/tile_size);
	if (!jumping and !falling) {
		if (level[y_slope_detector+1][x_slope_detector] == 10 or level[y_slope_detector+1][x_slope_detector] == 11) {
			y_pos = (y_slope_detector+1)*tile_size+tile_size/2+1;
			y_slope_detector += 1;
		}
		if (level[y_slope_detector][x_slope_detector] == 10 or level[y_slope_detector][x_slope_detector] == 11) {
			if (level[y_slope_detector][x_slope_detector] == 10) {
				x_offset = tile_size-x_pos%tile_size;
			}
			// could be an &quot;else&quot;...   
			if (level[y_slope_detector][x_slope_detector] == 11) {
				x_offset = x_pos%tile_size;
			}
			y_pos = Math.floor(y_pos/tile_size)*tile_size-9+x_offset;
			on_slope = true;
		}
		else {
			on_slope = false;
		}
	}
	if (!jumping and !falling and !on_slope and over != &quot;ladder&quot;) {
		y_pos = (y_slope_detector)*tile_size+tile_size/2+1;
	}
}</pre></td></tr></table></div>

<p>And the final example:</p>
<p><embed src="/downloads/newplat11.swf" allowscriptaccess="always" menu="false" quality="high" width="500" height="230" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></p>
<p><a href="/downloads/newplat11.zip">Download the source code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2008/10/19/new-tile-banew-tile-based-platform-engine-part-11-slopes-part-ased-platform-engine-part-11-slopes/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>New tile based platform engine &#8211; part 10 &#8211; optimization, doors n&#8217; keys</title>
		<link>http://www.emanueleferonato.com/2008/10/13/new-tile-based-platform-engine-part-10-optimization-doors-n-keys/</link>
		<comments>http://www.emanueleferonato.com/2008/10/13/new-tile-based-platform-engine-part-10-optimization-doors-n-keys/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 13:48:27 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 2]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=569</guid>
		<description><![CDATA[Here we are with some optimization, as well as a feature some people requested: doors and keys. Let&#8217;s start with the first optimization step. Optimization See how does the script at step 9 determine if a tile is walkable (player can pass through it): if ((top_right != 0 and top_right != 5 and top_right != [...]]]></description>
			<content:encoded><![CDATA[<p>Here we are with some optimization, as well as a feature some people requested: doors and keys.</p>
<p>Let&#8217;s start with the first optimization step.</p>
<p><strong>Optimization</strong></p>
<p>See how does the script at <a href="http://www.emanueleferonato.com/2008/10/07/new-tile-based-platform-engine-part-9-coins-n-spikes/">step 9</a> determine if a tile is walkable (player can pass through it):</p>
<p><code>if ((top_right != 0 and top_right != 5 and top_right != 6 and top_right != 7) or (bottom_right != 0 and bottom_right != 5 and bottom_right != 6 and bottom_right != 7)) {</code></p>
<p>I have to check if all values are different from <code>0</code>, <code>5</code>, <code>6</code> and <code>7</code> because 0 = empty, 5 = cloud, 6 = ladder and 7 = trampoline.</p>
<p>Nothing difficult at this point, but let&#8217;s imagine I am going to add another walkable tile&#8230; I should update the <code>and</code> formula by adding the new tile type.</p>
<p>The more walkable tiles I add, the more the probability of making errors or forgetting something.</p>
<p>So I created an array with all walkable tiles this way:</p>
<p><code>walkable_tiles = Array(0, 5, 6, 7);</code></p>
<p>Then the old code becomes</p>
<p><code>if (!is_walkable(top_right) or !is_walkable(bottom_right)) {</code></p>
<p>Where <code>is_walkable</code> is basically an <code>in_array</code> function (not included in AS2!!)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="actionscript2" style="font-family:monospace;">function is_walkable(tile) {
	walkable = false;
	for (x=0; x&lt;walkable_tiles.length; x++) {
		if (tile == walkable_tiles[x]) {
			walkable = true;
			break;
		}
	}
	return (walkable);
}</pre></td></tr></table></div>

<p><strong>Doors and keys</strong></p>
<p>A door is a unwalkable tile that becomes a walkable one when the player takes its key.</p>
<p>Every key is an array made this way:</p>
<p><code>[key x pos, key y pos, door x pos, door y pos]</code></p>
<p>Meaning that the key is located at (<code>key x pos</code>, <code>key y pos</code>) and once collected opens the door at (<code>door x pos</code>, <code>door y pos</code>).</p>
<p>Let&#8217;s see the source:<span id="more-569"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
</pre></td><td class="code"><pre class="actionscript2" style="font-family:monospace;">walkable_tiles = Array(0, 5, 6, 7);
tile_size = 20;
ground_acceleration = 1;
ground_friction = 0.8;
air_acceleration = 0.5;
air_friction = 0.7;
ice_acceleration = 0.15;
ice_friction = 0.95;
treadmill_speed = 2;
max_speed = 3;
xspeed = 0;
yspeed = 0;
falling = false;
gravity = 0.5;
jump_speed = 6;
climbing = false;
climb_speed = 0.8;
level = new Array();
enemy = new Array();
coin = new Array();
key = new Array();
level[0] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
level[1] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1];
level[2] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 1, 0, 0, 0, 0, 1];
level[3] = [1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 1];
level[4] = [1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 1];
level[5] = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 1];
level[6] = [1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 1, 0, 0, 0, 0, 0, 1];
level[7] = [1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 1];
level[8] = [1, 1, 1, 1, 0, 9, 0, 0, 0, 5, 5, 0, 0, 0, 7, 0, 0, 6, 0, 0, 0, 0, 7, 0, 1];
level[9] = [1, 1, 1, 1, 1, 1, 1, 2, 2, 8, 8, 8, 8, 1, 1, 3, 3, 1, 4, 4, 1, 8, 1, 8, 1];
player = [4, 8];
enemy[0] = [10, 3, -2];
enemy[1] = [3, 3, -2];
coin[0] = [2, 2];
coin[1] = [23, 4];
key[0] = [1, 5, 5, 8];
function create_level(l) {
	_root.createEmptyMovieClip(&quot;level_container&quot;, 1);
	level_height = l.length;
	level_width = l[0].length;
	for (y=0; y&lt;level_height; y++) {
		for (x=0; x&lt;level_width; x++) {
			if (l[y][x] != 0) {
				t = level_container.attachMovie(&quot;tile&quot;, &quot;t&quot;+y+&quot;_&quot;+x, _root.level_container.getNextHighestDepth(), {_x:x*tile_size, _y:y*tile_size});
				t.gotoAndStop(l[y][x]);
			}
		}
	}
	place_player();
	for (x=0; x&lt;coin.length; x++) {
		coin_mc = level_container.attachMovie(&quot;coin&quot;, &quot;coin_&quot;+_root.level_container.getNextHighestDepth(), _root.level_container.getNextHighestDepth(), {_x:coin[x][0]*tile_size+tile_size/2, _y:coin[x][1]*tile_size+tile_size/2+1});
		coin_mc.onEnterFrame = function() {
			if (this.hitTest(level_container.hero._x, level_container.hero._y, true)) {
				this.removeMovieClip();
			}
		};
	}
	for (x=0; x&lt;key.length; x++) {
		key_mc = level_container.attachMovie(&quot;key&quot;, &quot;key&quot;+_root.level_container.getNextHighestDepth(), _root.level_container.getNextHighestDepth(), {_x:key[x][0]*tile_size+tile_size/2, _y:key[x][1]*tile_size+tile_size/2+1});
		key_mc.ind = x;
		key_mc.onEnterFrame = function() {
			if (this.hitTest(level_container.hero._x, level_container.hero._y, true)) {
				open_x = [key[this.ind][2]];
				open_y = [key[this.ind][3]];
				level[open_y][open_x] = 0;
				_root.level_container[&quot;t&quot;+open_y+&quot;_&quot;+open_x].removeMovieClip();
				this.removeMovieClip();
			}
		};
	}
	for (x=0; x&lt;enemy.length; x++) {
		foe = level_container.attachMovie(&quot;patrol&quot;, &quot;patrol_&quot;+_root.level_container.getNextHighestDepth(), _root.level_container.getNextHighestDepth(), {_x:enemy[x][0]*tile_size+tile_size/2, _y:enemy[x][1]*tile_size+tile_size/2+1});
		foe.speed = enemy[x][2];
		foe.onEnterFrame = function() {
			this.x_pos = this._x;
			this.y_pos = this._y;
			this.x_pos += this.speed;
			this.left_foot_x = Math.floor((this.x_pos-6)/tile_size);
			this.right_foot_x = Math.floor((this.x_pos+5)/tile_size);
			this.foot_y = Math.floor((this.y_pos+9)/tile_size);
			this.bottom = Math.floor((this.y_pos+8)/tile_size);
			this.left_foot = level[this.foot_y][this.left_foot_x];
			this.right_foot = level[this.foot_y][this.right_foot_x];
			this.left = level[this.bottom][this.left_foot_x];
			this.right = level[this.bottom][this.right_foot_x];
			if (this.left_foot != 0 and this.right_foot != 0 and this.left == 0 and this.right == 0) {
				this._x = this.x_pos;
			} else {
				this.speed *= -1;
			}
		};
	}
}
create_level(level);
_root.onEnterFrame = function() {
	ground_under_feet();
	walking = false;
	climbing = false;
	if (Key.isDown(Key.LEFT)) {
		xspeed -= speed;
		walking = true;
	}
	if (Key.isDown(Key.RIGHT)) {
		xspeed += speed;
		walking = true;
	}
	if (Key.isDown(Key.UP)) {
		get_edges();
		if (top_right == 6 or bottom_right == 6 or top_left == 6 or bottom_left == 6) {
			jumping = false;
			falling = false;
			climbing = true;
			climbdir = -1;
		}
	}
	if (Key.isDown(Key.DOWN)) {
		get_edges();
		if ((over == &quot;ladder&quot;) or (top_right == 6 or bottom_right == 6 or top_left == 6 or bottom_left == 6)) {
			jumping = false;
			falling = false;
			climbing = true;
			climbdir = 1;
		}
	}
	if (Key.isDown(Key.SPACE)) {
		get_edges();
		if (!falling and !jumping) {
			jumping = true;
			yspeed = -jump_speed;
		}
	}
	if (!walking) {
		xspeed *= friction;
		if (Math.abs(xspeed)&lt;0.5) {
			xspeed = 0;
		}
	}
	if (xspeed&gt;max_speed) {
		xspeed = max_speed;
	}
	if (xspeed&lt;max_speed*-1) {
		xspeed = max_speed*-1;
	}
	if (falling or jumping) {
		yspeed += gravity;
	}
	if (climbing) {
		yspeed = climb_speed*climbdir;
	}
	if (!falling and !jumping and !climbing) {
		yspeed = 0;
	}
	xspeed += bonus_speed;
	check_collisions();
	level_container.hero._x = x_pos;
	level_container.hero._y = y_pos;
	xspeed -= bonus_speed;
};
function ground_under_feet() {
	bonus_speed = 0;
	left_foot_x = Math.floor((x_pos-6)/tile_size);
	right_foot_x = Math.floor((x_pos+5)/tile_size);
	foot_y = Math.floor((y_pos+9)/tile_size);
	left_foot = level[foot_y][left_foot_x];
	right_foot = level[foot_y][right_foot_x];
	if (left_foot != 0) {
		current_tile = left_foot;
	} else {
		current_tile = right_foot;
	}
	switch (current_tile) {
	case 0 :
		over = &quot;air&quot;;
		speed = air_acceleration;
		friction = air_friction;
		falling = true;
		break;
	case 1 :
		over = &quot;ground&quot;;
		speed = ground_acceleration;
		friction = ground_friction;
		break;
	case 2 :
		over = &quot;ice&quot;;
		speed = ice_acceleration;
		friction = ice_friction;
		break;
	case 3 :
		over = &quot;treadmill&quot;;
		speed = ground_acceleration;
		friction = ground_friction;
		bonus_speed = -treadmill_speed;
		break;
	case 4 :
		over = &quot;treadmill&quot;;
		speed = ground_acceleration;
		friction = ground_friction;
		bonus_speed = treadmill_speed;
		break;
	case 5 :
		over = &quot;cloud&quot;;
		speed = ground_acceleration;
		friction = ground_friction;
		break;
	case 6 :
		over = &quot;ladder&quot;;
		speed = ground_acceleration;
		friction = ground_friction;
		break;
	case 7 :
		over = &quot;trampoline&quot;;
		speed = ground_acceleration;
		friction = ground_friction;
		break;
	case 8 :
		over = &quot;spikes&quot;;
		if (left_foot == 8 and right_foot == 8) {
			place_player();
		}
	}
}
function check_collisions() {
	y_pos += yspeed;
	get_edges();
	// collision to the bottom 
	if (yspeed&gt;0) {
		if ((bottom_right != 0 and bottom_right != 6) or (bottom_left != 0 and bottom_left != 6)) {
			// not a cloud...
			if (bottom_right != 5 and bottom_left != 5) {
				// a trampoline
				if ((bottom_right == 7 or bottom_left == 7) and (Math.abs(yspeed)&gt;1)) {
					yspeed = yspeed*-1;
					jumping = true;
					falling = true;
				} else {
					y_pos = bottom*tile_size-9;
					yspeed = 0;
					falling = false;
					jumping = false;
				}
			} else {
				//cloud
				if (prev_bottom&lt;bottom) {
					y_pos = bottom*tile_size-9;
					yspeed = 0;
					falling = false;
					jumping = false;
				}
			}
		}
	}
	// collision to the top                                                                
	if (yspeed&lt;0) {
		if ((top_right != 0 and top_right != 5 and top_right != 6) or (top_left != 0 and top_left != 5 and top_left != 6)) {
			y_pos = bottom*tile_size+1+8;
			yspeed = 0;
			falling = false;
			jumping = false;
		}
	}
	x_pos += xspeed;
	get_edges();
	// collision to the left           
	if (xspeed&lt;0) {
		if (!is_walkable(top_left) or !is_walkable(bottom_left)) {
			x_pos = (left+1)*tile_size+6;
			xspeed = 0;
		}
	}
	// collision to the right                                                                                       
	if (xspeed&gt;0) {
		if (!is_walkable(top_right) or !is_walkable(bottom_right)) {
			x_pos = right*tile_size-6;
			xspeed = 0;
		}
	}
	prev_bottom = bottom;
}
function get_edges() {
	// right edge
	right = Math.floor((x_pos+5)/tile_size);
	// left edge   
	left = Math.floor((x_pos-6)/tile_size);
	// bottom edge
	bottom = Math.floor((y_pos+8)/tile_size);
	// top edge
	top = Math.floor((y_pos-9)/tile_size);
	// adjacent tiles
	top_right = level[top][right];
	top_left = level[top][left];
	bottom_left = level[bottom][left];
	bottom_right = level[bottom][right];
}
function place_player() {
	level_container.hero.removeMovieClip();
	x_pos = player[0]*tile_size+tile_size/2;
	y_pos = player[1]*tile_size+tile_size/2+1;
	level_container.attachMovie(&quot;hero&quot;, &quot;hero&quot;, _root.level_container.getNextHighestDepth(), {_x:x_pos, _y:y_pos});
}
function is_walkable(tile) {
	walkable = false;
	for (x=0; x&lt;walkable_tiles.length; x++) {
		if (tile == walkable_tiles[x]) {
			walkable = true;
			break;
		}
	}
	return (walkable);
}</pre></td></tr></table></div>

<p>And this is the game:</p>
<p><embed src="/downloads/newplat10.swf" menu="false" quality="high" width="500" height="200" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p><a href="/downloads/newplat10.zip">Download the source code</a> and give feedback.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2008/10/13/new-tile-based-platform-engine-part-10-optimization-doors-n-keys/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Create a Flash game like Gold Miner &#8211; step 2</title>
		<link>http://www.emanueleferonato.com/2008/10/10/create-a-flash-game-like-gold-miner-step-2/</link>
		<comments>http://www.emanueleferonato.com/2008/10/10/create-a-flash-game-like-gold-miner-step-2/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 14:02:17 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 2]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=565</guid>
		<description><![CDATA[I received a lot of emails asking me to add left-right movement to my Gold Miner clone and requiring more information about manually placing the boulders. In order to add left-right movement, you need to check for left and right arrow keys and move the hook in the proper direction. Just remember you don&#8217;t have [...]]]></description>
			<content:encoded><![CDATA[<p>I received a lot of emails asking me to add left-right movement to my <a href="http://www.emanueleferonato.com/2008/10/04/create-a-flash-game-like-gold-miner/">Gold Miner clone</a> and requiring more information about manually placing the boulders.</p>
<p>In order to add left-right movement, you need to check for left and right arrow keys and move the hook in the proper direction.</p>
<p>Just remember you don&#8217;t have to let the hook move out of the stage and to update the starting/ending points of the rope.</p>
<p>When you want to manually place boulders, you need an array.</p>
<p>In the one I created, every boulder is an array made this way</p>
<p><code>[x position, y position, diameter]</code></p>
<p>Then I created an array containing <code>n</code> boulder arrays where <code>n</code> is the number of boulder I wanted to be in the stage.</p>
<p>Here it is the commented code:<span id="more-565"></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
</pre></td><td class="code"><pre class="actionscript2" style="font-family:monospace;">// boulders are stored in an array
// [0] is x pos
// [1] is y pos
// [2] is the width
// don't make boulders too large (&lt;50) or the rewind won't work
// until you change slowdown formula
boulders = [[100, 100, 30], [200, 100, 40], [300, 100, 40], [400, 100, 30], [100, 200, 30], [200, 200, 40], [300, 200, 40], [400, 200, 30], [100, 300, 30], [200, 300, 40], [300, 300, 40], [400, 300, 30]];
for (x=0; x&lt;boulders.length; x++) {
	// creating the boulders
	bould = _root.attachMovie(&quot;boulder&quot;, &quot;boulder_&quot;+_root.getNextHighestDepth(), _root.getNextHighestDepth());
	// placing them in random positions and with random dimensions
	bould._x = boulders[x][0];
	bould._y = boulders[x][1];
	bould._width = boulders[x][2];
	bould._height = boulders[x][2];
	// setting picked attribute as false
	// picked = false =&gt; the boulder has not been picked by the hook
	// picked = true =&gt; the boulder has been picked
	bould.picked = false;
	// function to be executed at every frame for the boulder
	bould.onEnterFrame = function() {
		// if it's not been picked...
		if (!this.picked) {
			// check if the hook is in shoot mode and touched the boulder
			// you'll see later what do hot_spot_x and hot_spot_y mean
			if (pod_status == &quot;shoot&quot; and this.hitTest(hot_spot_x, hot_spot_y, true)) {
				// set the hook on rewind mode
				pod_status = &quot;rewind&quot;;
				// mark this boulder as picked
				this.picked = true;
				// determining the slowdown according to boulder size
				slowdown = Math.floor(this._width/5);
			}
		} else {
			// the boulder has been picked, so move it as the hook moves
			this._x = hot_spot_x;
			this._y = hot_spot_y;
			// if the hook status changed to rotate
			// (this means: if the hook took a boulder and pulled it out to surface...
			if (pod_status == &quot;rotate&quot;) {
				// remove the boulder
				this.removeMovieClip();
			}
		}
	};
}
// placing the hook on stage
_root.attachMovie(&quot;pod&quot;, &quot;pod&quot;, _root.getNextHighestDepth(), {_x:250});
// creating an empty movie clip to draw the rope
_root.createEmptyMovieClip(&quot;rod&quot;, _root.getNextHighestDepth());
// this is the rotation direction and speed
rotation_dir = 2;
// hook initial status
pod_status = &quot;rotate&quot;;
// slowdown malus
slowdown = 0;
// hook movement speed
pod_speed = 4;
// function the hook will execute at every frame
pod.onEnterFrame = function() {
	// getting pod status
	switch (pod_status) {
	case &quot;rotate&quot; :
		// moving the hook to the left if player presses left
		if (Key.isDown(Key.LEFT)) {
			this._x -= pod_speed;
			if (this._x&lt;20) {
				this._x = 20;
			}
		}
		// moving the hook to the right if player presses left   
		if (Key.isDown(Key.RIGHT)) {
			this._x += pod_speed;
			if (this._x&gt;480) {
				this._x = 480;
			}
		}
		// if the status is rotate, just rotate the hook according to rotation_dir      
		this._rotation += rotation_dir;
		if (this._rotation == 80 or this._rotation == -80) {
			// invert rotation_dir if the hook reaches its minimum (or maximum) rotation allowed
			rotation_dir *= -1;
		}
		break;
	case &quot;shoot&quot; :
		// the hook has ben shoot
		// (re)set slowdown malus to zero
		slowdown = 0;
		// moving the hook using trigonometry
		this._x += 10*Math.cos(dir);
		this._y += 10*Math.sin(dir);
		// determining the hot spot of the hook
		// the hot spot is the lowest corner of the hook (that acts like an harpoon in this case)
		hot_spot_x = this._x+40*Math.cos(dir);
		hot_spot_y = this._y+40*Math.sin(dir);
		// if the hot spot goes off the stage
		if (hot_spot_y&gt;400 or hot_spot_x&lt;0 or hot_spot_x&gt;500) {
			// then rewind the hook
			pod_status = &quot;rewind&quot;;
		}
		// draw a line from the hook starting position to its actual position       
		// this will simulate the rope
		rod.clear();
		rod.lineStyle(1, 0x000000);
		// once it started from (250,0), now that hook can move I am starting from (start_rope_x, 0)
		rod.moveTo(start_rope_x, 0);
		rod.lineTo(this._x, this._y);
		break;
	case &quot;rewind&quot; :
		// clearing the rope
		rod.clear();
		// rewinding the hook...
		// it may seem a nonsense determining the hot spot now, but I need id
		// to move the boulder (if I have any boulder attached to the hook)
		hot_spot_x = this._x+40*Math.cos(dir);
		hot_spot_y = this._y+40*Math.sin(dir);
		// moving the hook with slowdown malus (if any)
		this._x -= (10-slowdown)*Math.cos(dir);
		this._y -= (10-slowdown)*Math.sin(dir);
		// if the hook returns in its initial position...
		if (this._y&lt;0) {
			// then reset its position and set its status to rotate
			this._y = 0;
			this._x = start_rope_x;
			pod_status = &quot;rotate&quot;;
		} else {
			// drawing a line as seen in shoot status, but only if the hook is still in the air   
			rod.lineStyle(1, 0x000000);
			rod.moveTo(start_rope_x, 0);
			rod.lineTo(this._x, this._y);
		}
		break;
	}
};
// when the mouse is clicked...
_root.onMouseDown = function() {
	// if the status is rotate...
	if (pod_status == &quot;rotate&quot;) {
		// save hook heading and convert it to radians
		dir = (pod._rotation+90)*0.0174532925;
		// setting rope start position... the last hook position
		start_rope_x = pod._x;
		// set pod status to shoot
		pod_status = &quot;shoot&quot;;
	}
};</pre></td></tr></table></div>

<p>And here it is the result&#8230;</p>
<p><embed src="/downloads/goldminer2.swf" menu="false" quality="high" width="500" height="400" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>Left/right arrows to move, mousebutton to fire.</p>
<p><a href="/downloads/goldminer2.zip">Download the source code</a> and enjoy</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2008/10/10/create-a-flash-game-like-gold-miner-step-2/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching 10/18 queries in 0.030 seconds using disk: basic

Served from: www.emanueleferonato.com @ 2012-02-08 20:13:35 -->
