<?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>Flash Game Tuts &#187; Intermediate</title>
	<atom:link href="http://www.flashgametuts.com/tutorials/category/intermediate/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.flashgametuts.com</link>
	<description>Free Flash Game Tutorials in AS2 and AS3</description>
	<lastBuildDate>Wed, 29 Jul 2009 14:43:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>How to Make a Vertical Shooter in AS3 &#8211; Part 6</title>
		<link>http://www.flashgametuts.com/tutorials/as3/how-to-make-a-vertical-shooter-in-as3-part-6/</link>
		<comments>http://www.flashgametuts.com/tutorials/as3/how-to-make-a-vertical-shooter-in-as3-part-6/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 12:05:45 +0000</pubDate>
		<dc:creator>Mr Sun</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[Intermediate Tutorials]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[shooter]]></category>
		<category><![CDATA[teaching]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[vertical]]></category>

		<guid isPermaLink="false">http://www.mrsunstudios.com/?p=642</guid>
		<description><![CDATA[As always, the finishing touches of this game won&#8217;t be explained too much by me, in hopes that you actually can do some of this stuff by yourself. Of course, there will always be source files at the bottom if you need to clear anything up. The first thing I want to do is show [...]]]></description>
			<content:encoded><![CDATA[<p>As always, the finishing touches of this game won&#8217;t be explained too much by me, in hopes that you actually can do some of this stuff by yourself. Of course, there will always be source files at the bottom if you need to clear anything up.</p>
<p>The first thing I want to do is show the score on the &#8220;lose&#8221; screen. That&#8217;ll be pretty easy, just add a dynamic text field there.</p>
<p>Next, we can make some particles move down the screen so it looks like the player is actually moving forward. We&#8217;re going to make them the same speed as the enemies. I&#8217;m actually show some code for this one, because it&#8217;s also a pretty new thing for me. We&#8217;re not going to make a MovieClip for this, we&#8217;re going to make dynamic shapes through ActionScript. Here&#8217;s the code to place at the bottom:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//adding another enterframe listener for the particles</span>
<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, generateParticles<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//checking if there already is another particlecontainer there</span>
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>particleContainer == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//this movieclip will hold all of the particles</span>
	<span style="color: #000000; font-weight: bold;">var</span> particleContainer:<span style="color: #0066CC;">MovieClip</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">MovieClip</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	addChild<span style="color: #66cc66;">&#40;</span>particleContainer<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> generateParticles<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//so we don't do it every frame, we'll do it randomly</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">10</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">//creating a new shape</span>
		<span style="color: #000000; font-weight: bold;">var</span> mcParticle:Shape = <span style="color: #000000; font-weight: bold;">new</span> Shape<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #808080; font-style: italic;">//making random dimensions (only ranges from 1-5 px)</span>
		<span style="color: #000000; font-weight: bold;">var</span> dimensions:<span style="color: #0066CC;">int</span> = <span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span>+<span style="color: #cc66cc;">1</span>;
		<span style="color: #808080; font-style: italic;">//add color to the shape</span>
		mcParticle.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0x999999<span style="color: #808080; font-style: italic;">/*The color for shape*/</span>,<span style="color: #cc66cc;">1</span><span style="color: #808080; font-style: italic;">/*The alpha for the shape*/</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #808080; font-style: italic;">//turning the shape into a square</span>
		mcParticle.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span>dimensions,dimensions,dimensions,dimensions<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #808080; font-style: italic;">//change the coordinates of the particle</span>
		mcParticle.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span><span style="color: #66cc66;">&#41;</span>;
		mcParticle.<span style="color: #006600;">y</span> = -<span style="color: #cc66cc;">10</span>;
		<span style="color: #808080; font-style: italic;">//adding the particle to stage</span>
		particleContainer.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>mcParticle<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">//making all of the particles move down stage</span>
	<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">0</span>;i<span style="color: #66cc66;">&lt;</span>particleContainer.<span style="color: #006600;">numChildren</span>;i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">//getting a certain particle</span>
		<span style="color: #000000; font-weight: bold;">var</span> theParticle:<span style="color: #0066CC;">Object</span> = particleContainer.<span style="color: #006600;">getChildAt</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #808080; font-style: italic;">//it'll go half the speed of the character</span>
		theParticle.<span style="color: #006600;">y</span> += mainSpeed<span style="color: #66cc66;">*</span>.5;
		<span style="color: #808080; font-style: italic;">//checking if the particle is offstage</span>
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>theParticle.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&gt;</span>= <span style="color: #cc66cc;">400</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">//remove it</span>
			particleContainer.<span style="color: #006600;">removeChild</span><span style="color: #66cc66;">&#40;</span>theParticle<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Pretty intense, eh? Well, this is a finishing touch, and most finishing touches <em>are</em> pretty intense. If you want to, you can remove this function when the player loses, but I won&#8217;t because it adds a pretty cool effect.</p>
<p>Well, that&#8217;s actually all that I really have to finish off the game. I hope you had fun making it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashgametuts.com/tutorials/as3/how-to-make-a-vertical-shooter-in-as3-part-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Make a Vertical Shooter in AS3 &#8211; Part 5</title>
		<link>http://www.flashgametuts.com/tutorials/as3/how-to-make-a-vertical-shooter-in-as3-part-5/</link>
		<comments>http://www.flashgametuts.com/tutorials/as3/how-to-make-a-vertical-shooter-in-as3-part-5/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 12:04:34 +0000</pubDate>
		<dc:creator>Mr Sun</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[Intermediate Tutorials]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[shooter]]></category>
		<category><![CDATA[teaching]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[vertical]]></category>

		<guid isPermaLink="false">http://www.mrsunstudios.com/?p=632</guid>
		<description><![CDATA[Now that we&#8217;ve got the hardest part down, it all gets easier from here. This chapter will be simple, just some code that has scoring. Also, as promised, we&#8217;re going to have a function run when the player is hit by an enemy. Let&#8217;s start with this one first, eh? In order to do this, [...]]]></description>
			<content:encoded><![CDATA[<p>Now that we&#8217;ve got the hardest part down, it all gets easier from here. This chapter will be simple, just some code that has scoring. Also, as promised, we&#8217;re going to have a function run when the player is hit by an enemy. Let&#8217;s start with this one first, eh?</p>
<p>In order to do this, we have to make a frame called &#8220;lose&#8221;. This will be the frame that we&#8217;ll navigate to when we get hit. It&#8217;ll be simple, just some text that says &#8220;You Lose&#8221; and a listener for keystrokes or a click that will return us to play another game. First, make the frame called &#8220;lose&#8221;. I recommend making an entire new layer for labels, but this isn&#8217;t required. In that frame, draw or type in whatever you want to signify that the player has lost the game. I&#8217;m just going to put the text, &#8220;YOU LOSE&#8221;.</p>
<p>Then, in the actions, type in the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, goBack<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> goBack<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">gotoAndStop</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, goBack<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Then, we&#8217;ll have to add a variable called <tt>gameOver</tt> to signify that the game is over and that some stuff should be deleted and such.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//whether or not the game is over</span>
<span style="color: #000000; font-weight: bold;">var</span> gameOver:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;</pre></div></div>

<p>Then, both in the <tt>Bullet</tt>&#8216;s and the <tt>Enemy</tt>&#8216;s <tt>eFrame()</tt> function, add the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//checking if game is over</span>
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_root</span>.<span style="color: #006600;">gameOver</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	removeEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, eFrame<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0066CC;">this</span>.<span style="color: #006600;">parent</span>.<span style="color: #006600;">removeChild</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Finally, add this code to where we hit tested for the main character in &#8220;Enemy.as&#8221;</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//hit testing with the user</span>
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>hitTestObject<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_root</span>.<span style="color: #006600;">mcMain</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//losing the game</span>
	<span style="color: #0066CC;">_root</span>.<span style="color: #006600;">gameOver</span> = <span style="color: #000000; font-weight: bold;">true</span>;
	<span style="color: #0066CC;">_root</span>.<span style="color: #0066CC;">gotoAndStop</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'lose'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>If you test the game, there will be a bug that comes up. Don&#8217;t worry, we can fix it. Just keep <tt>mcMain</tt> in the &#8220;lose&#8221; frame. Also, so it can&#8217;t be controlled while in the &#8220;lose&#8221; frame, place the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//keeping mcMain out of sight</span>
mcMain.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span>;
mcMain.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span>;
mcMain.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, moveChar<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Phew, that was a lot of work, wasn&#8217;t it? Now we can move onto actually scoring the game. First, we have to define a score variable at the top:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//the player's score</span>
<span style="color: #000000; font-weight: bold;">var</span> score:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>;</pre></div></div>

<p>Then, increment the score every time an enemy is killed. Place this code in the Enemy&#8217;s hit testing for the bullet.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//up the score</span>
<span style="color: #0066CC;">_root</span>.<span style="color: #006600;">score</span> += <span style="color: #cc66cc;">5</span>;</pre></div></div>

<p>Now, we can show the score to the user with a dynamic text field. Make one at the bottom of the stage and give it an instance name of <tt>txtScore</tt>. Next, place this code into the <tt>moveChar</tt> function.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//updating the score text</span>
txtScore.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">'Score: '</span>+score;</pre></div></div>

<p>Pretty easy, right? Well, that&#8217;s all we&#8217;re going to do for scoring. Next, we&#8217;ll add some sweet finishing touches, eh?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashgametuts.com/tutorials/as3/how-to-make-a-vertical-shooter-in-as3-part-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Make a Vertical Shooter in AS3 &#8211; Part 4</title>
		<link>http://www.flashgametuts.com/tutorials/as3/how-to-make-a-vertical-shooter-in-as3-part-4/</link>
		<comments>http://www.flashgametuts.com/tutorials/as3/how-to-make-a-vertical-shooter-in-as3-part-4/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 12:03:06 +0000</pubDate>
		<dc:creator>Mr Sun</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[Intermediate Tutorials]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[shooter]]></category>
		<category><![CDATA[teaching]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[vertical]]></category>

		<guid isPermaLink="false">http://www.mrsunstudios.com/?p=625</guid>
		<description><![CDATA[Now we have to make it so the enemies can be shot. This probably will be the most complicated of the steps. But, it also is what makes this thing a game. There are two ways that I know of to accomplish this task. The first one is to have the bullet listen for hit [...]]]></description>
			<content:encoded><![CDATA[<p>Now we have to make it so the enemies can be shot. This probably will be the most complicated of the steps. But, it also is what makes this thing a game. There are two ways that I know of to accomplish this task. The first one is to have the bullet listen for hit testing the enemy, or the enemy listen for the bullet. It&#8217;s basically the same thing. However, I&#8217;m going to have the enemy listen for the bullet, just because.</p>
<p>The first thing we need to do in order to accomplish this feat is to create a container for all of the bullets. This way, we can access all of the bullets through the container. I can&#8217;t really explain this too well, so I&#8217;ll just demonstrate it for you. At the top of the code, add the following:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//this movieclip will hold all of the bullets</span>
<span style="color: #000000; font-weight: bold;">var</span> bulletContainer:<span style="color: #0066CC;">MovieClip</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">MovieClip</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
addChild<span style="color: #66cc66;">&#40;</span>bulletContainer<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>The <tt>bulletContainer</tt> is invisible and is just a container for all of the bullets. In order for this to be any use to us, we need to actually add the bullets to this container. This will be easy. Instead of the code where we add the bullet to the stage, <tt>addChild(newBullet);</tt>, we just replace it with <tt>bulletContainer.addChild(newBullet)</tt>. It&#8217;s as simple as that. But now arises a problem. When we remove the MovieClip from stage, it returns an error. This is simple to fix. Instead of saying just <tt>_root.removeChild(this)</tt> in the &#8220;Bullet.as&#8221; file, replace it with <tt>_root.bulletContainer.removeChild(this);</tt>. Just another simple quick fix.</p>
<p>Now we enter complicated territory. Go to &#8220;Enemy.as&#8221; and add the following code to the <tt>eFrame()</tt> function:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//checking if it is touching any bullets</span>
<span style="color: #808080; font-style: italic;">//we will have to run a for loop because there will be multiple bullets</span>
<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>;i<span style="color: #66cc66;">&lt;</span>_root.<span style="color: #006600;">bulletContainer</span>.<span style="color: #006600;">numChildren</span>;i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//numChildren is just the amount of movieclips within</span>
	<span style="color: #808080; font-style: italic;">//the bulletContainer.</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">//we define a variable that will be the bullet that we are currently</span>
	<span style="color: #808080; font-style: italic;">//hit testing.</span>
	<span style="color: #000000; font-weight: bold;">var</span> bulletTarget:<span style="color: #0066CC;">MovieClip</span> = <span style="color: #0066CC;">_root</span>.<span style="color: #006600;">bulletContainer</span>.<span style="color: #006600;">getChildAt</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">//now we hit test</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>hitTestObject<span style="color: #66cc66;">&#40;</span>bulletTarget<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">//remove this from the stage if it touches a bullet</span>
		removeEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, eFrame<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">_root</span>.<span style="color: #006600;">removeChild</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #808080; font-style: italic;">//also remove the bullet and its listeners</span>
		<span style="color: #0066CC;">_root</span>.<span style="color: #006600;">bulletContainer</span>.<span style="color: #006600;">removeChild</span><span style="color: #66cc66;">&#40;</span>bulletTarget<span style="color: #66cc66;">&#41;</span>;
		bulletTarget.<span style="color: #006600;">removeListeners</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>You might note that we have to run <tt>removeListeners()</tt> which isn&#8217;t a preset ActionScript function. We have to define it in the <tt>Bullet</tt> class because there isn&#8217;t any other way to remove the listeners. Just define the function in the &#8220;Bullet.as&#8221; file.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> removeListeners<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	removeEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, eFrame<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Now, try out your game. It should work pretty well now. The only problem with it, however, is that it doesn&#8217;t do anything when it touches the player. We aren&#8217;t going to really do anything with this right now, but we will set it up so we can make a function for it in the next part of the tutorial, &#8220;Scoring&#8221;. Just place the following code in the <tt>Enemy</tt>&#8216;s <tt>eFrame()</tt> function:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//hit testing with the user</span>
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>hitTestObject<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_root</span>.<span style="color: #006600;">mcMain</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//we'll add code here in the next part</span>
	<span style="color: #808080; font-style: italic;">//but for now, we'll just trace something</span>
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'You got hit!'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Well, that&#8217;s all for today. Join us next time when we score the game!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashgametuts.com/tutorials/as3/how-to-make-a-vertical-shooter-in-as3-part-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Make a Vertical Shooter in AS3 &#8211; Part 3</title>
		<link>http://www.flashgametuts.com/tutorials/as3/how-to-make-a-vertical-shooter-in-as3-part-3/</link>
		<comments>http://www.flashgametuts.com/tutorials/as3/how-to-make-a-vertical-shooter-in-as3-part-3/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 12:02:19 +0000</pubDate>
		<dc:creator>Mr Sun</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[Intermediate Tutorials]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[shooter]]></category>
		<category><![CDATA[teaching]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[vertical]]></category>

		<guid isPermaLink="false">http://www.mrsunstudios.com/?p=616</guid>
		<description><![CDATA[Well, now that we can make our lil&#8217; guy shoot, we have to make something for him to shoot at! I&#8217;m going to first start by just drawing a little enemy guy. It won&#8217;t be too artistic. Its dimensions are 30&#215;30 if you wanted to know. Now, do the same thing we did for the [...]]]></description>
			<content:encoded><![CDATA[<p>Well, now that we can make our lil&#8217; guy shoot, we have to make something for him to shoot at! I&#8217;m going to first start by just drawing a little enemy guy. It won&#8217;t be too artistic.<br />
<img src="http://www.flashgametuts.com/obj/tuts/vert-shooter-as3/pt3/enemy.gif" alt="My enemy" /><br />
Its dimensions are 30&#215;30 if you wanted to know.</p>
<p>Now, do the same thing we did for the bullet, convert it to a MovieClip, and Export it for ActionScript. This time, give it a class of &#8220;Enemy&#8221;. I think you know what&#8217;s next. Now, we have to create another external file for the enemy. Once you&#8217;ve done that, place in the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//This is the basic skeleton that all classes must have</span>
package<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//we have to import certain display objects and events</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #66cc66;">*</span>;
	<span style="color: #808080; font-style: italic;">//this just means that Eullet will act like a MovieClip</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Enemy <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">//VARIABLES</span>
		<span style="color: #808080; font-style: italic;">//this will act as the root of the document</span>
		<span style="color: #808080; font-style: italic;">//so we can easily reference it within the class</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">_root</span>:<span style="color: #0066CC;">Object</span>;
		<span style="color: #808080; font-style: italic;">//how quickly the enemy will move</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> speed:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">5</span>;
		<span style="color: #808080; font-style: italic;">//this function will run every time the Bullet is added</span>
		<span style="color: #808080; font-style: italic;">//to the stage</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Enemy<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">//adding events to this class</span>
			<span style="color: #808080; font-style: italic;">//functions that will run only when the MC is added</span>
			addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ADDED</span>, beginClass<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #808080; font-style: italic;">//functions that will run on enter frame</span>
			addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, eFrame<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> beginClass<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">_root</span> = <span style="color: #0066CC;">MovieClip</span><span style="color: #66cc66;">&#40;</span>root<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> eFrame<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">//moving the bullet up screen</span>
			y += speed;
			<span style="color: #808080; font-style: italic;">//making the bullet be removed if it goes off stage</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
				removeEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, eFrame<span style="color: #66cc66;">&#41;</span>;
				<span style="color: #0066CC;">_root</span>.<span style="color: #006600;">removeChild</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>If you didn&#8217;t notice, I just copied and pasted the code from &#8220;Bullet.as&#8221; and edited it around a little bit. You&#8217;ll find that you will do this often when making classes. This code will just make the Enemy just move down the screen. Now, we have to add code to the main timeline that will create it and add it to the stage.</p>
<p>We first have to add 2 variables at the top of our code. They will be similar to <tt>cTime</tt> and <tt>cLimit</tt> but instead they are for creating enemies. Here&#8217;s the code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//how much time before another enemy is made</span>
<span style="color: #000000; font-weight: bold;">var</span> enemyTime:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>;
<span style="color: #808080; font-style: italic;">//how much time needed to make an enemy</span>
<span style="color: #808080; font-style: italic;">//it should be more than the shooting rate</span>
<span style="color: #808080; font-style: italic;">//or else killing all of the enemies would</span>
<span style="color: #808080; font-style: italic;">//be impossible :O</span>
<span style="color: #000000; font-weight: bold;">var</span> enemyLimit:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">16</span>;</pre></div></div>

<p>Next, we have to create a function that will add the enemies to the stage. We don&#8217;t really want too many <tt>enterFrame</tt> functions so we can just add to the <tt>moveChar</tt> function. If you want, you can rename it to <tt>eFrameFunctions</tt> so that you don&#8217;t get confused on the purpose of the code. Add this to the bottom of that function.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//adding enemies to stage</span>
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>enemyTime <span style="color: #66cc66;">&lt;</span> enemyLimit<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//if time hasn't reached the limit, then just increment</span>
	enemyTime ++;
<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//defining a variable which will hold the new enemy</span>
	<span style="color: #000000; font-weight: bold;">var</span> newEnemy = <span style="color: #000000; font-weight: bold;">new</span> Enemy<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #808080; font-style: italic;">//making the enemy offstage when it is created</span>
	newEnemy.<span style="color: #006600;">y</span> = -<span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">*</span> newEnemy.<span style="color: #0066CC;">height</span>;
	<span style="color: #808080; font-style: italic;">//making the enemy's x coordinates random</span>
	<span style="color: #808080; font-style: italic;">//the &quot;int&quot; function will act the same as Math.floor but a bit faster</span>
	newEnemy.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span> - newEnemy.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #808080; font-style: italic;">//then add the enemy to stage</span>
	addChild<span style="color: #66cc66;">&#40;</span>newEnemy<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #808080; font-style: italic;">//and reset the enemyTime</span>
	enemyTime = <span style="color: #cc66cc;">0</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This code will constantly add the enemies to the stage, which is exactly what we want. This ends this part of the tutorial. Next time, we&#8217;ll program the enemies so they get shot!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashgametuts.com/tutorials/as3/how-to-make-a-vertical-shooter-in-as3-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Make a Vertical Shooter in AS3 &#8211; Part 2</title>
		<link>http://www.flashgametuts.com/tutorials/as3/how-to-make-a-vertical-shooter-in-as3-part-2/</link>
		<comments>http://www.flashgametuts.com/tutorials/as3/how-to-make-a-vertical-shooter-in-as3-part-2/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 12:01:19 +0000</pubDate>
		<dc:creator>Mr Sun</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[Intermediate Tutorials]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[shooter]]></category>
		<category><![CDATA[teaching]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[vertical]]></category>

		<guid isPermaLink="false">http://www.mrsunstudios.com/?p=608</guid>
		<description><![CDATA[Well, now that we&#8217;ve got the character moving, we have to make him able to shoot. The first step in doing this is to create a MovieClip which will be the bullet. Mine is 5&#215;30 pixels. Give it a name of &#8220;Bullet&#8221; with the capitals. We also are going to have to export it for [...]]]></description>
			<content:encoded><![CDATA[<p>Well, now that we&#8217;ve got the character moving, we have to make him able to shoot. The first step in doing this is to create a MovieClip which will be the bullet. Mine is 5&#215;30 pixels. Give it a name of &#8220;Bullet&#8221; with the capitals. We also are going to have to export it for actionscript. Hopefully by now, you know how to do this. But, I&#8217;ll explain it once again (for the 5th time).</p>
<p>Right click the MovieClip and click on &#8220;Linkage&#8230;&#8221;. A window will pop up. In this window, check off &#8220;Export for ActionScript&#8221; and leave everything just as it is.</p>
<p>Now that we&#8217;ve got this down, we&#8217;re going to make a &#8220;Bullet&#8221; class. To do this, we have to make an external .as file. Press Command+N if you are on a Mac or Ctrl+N if you are on Windows and under &#8220;Type:&#8221;, select &#8220;ActionScript File&#8221;. Then, immediately save this file as &#8220;Bullet.as&#8221; in the same directory as your main game. Then, within it, type in the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//This is the basic skeleton that all classes must have</span>
package<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//we have to import certain display objects and events</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #66cc66;">*</span>;
	<span style="color: #808080; font-style: italic;">//this just means that Bullet will act like a MovieClip</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> <span style="color: #0066CC;">Bullet</span> <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">//VARIABLES</span>
		<span style="color: #808080; font-style: italic;">//this will act as the root of the document</span>
		<span style="color: #808080; font-style: italic;">//so we can easily reference it within the class</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">_root</span>:<span style="color: #0066CC;">Object</span>;
		<span style="color: #808080; font-style: italic;">//how quickly the bullet will move</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> speed:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">10</span>;
		<span style="color: #808080; font-style: italic;">//this function will run every time the Bullet is added</span>
		<span style="color: #808080; font-style: italic;">//to the stage</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">Bullet</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">//adding events to this class</span>
			<span style="color: #808080; font-style: italic;">//functions that will run only when the MC is added</span>
			addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ADDED</span>, beginClass<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #808080; font-style: italic;">//functions that will run on enter frame</span>
			addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, eFrame<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> beginClass<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">_root</span> = <span style="color: #0066CC;">MovieClip</span><span style="color: #66cc66;">&#40;</span>root<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> eFrame<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">//moving the bullet up screen</span>
			y -= speed;
			<span style="color: #808080; font-style: italic;">//making the bullet be removed if it goes off stage</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&lt;</span> -<span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
				removeEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, eFrame<span style="color: #66cc66;">&#41;</span>;
				<span style="color: #0066CC;">_root</span>.<span style="color: #006600;">removeChild</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This code really won&#8217;t do anything by itself. We have to add it to stage whenever the player presses a button (the Space Bar). We also want to limit how quickly the user can shoot. This will be easy. Just add these variables to the top of the main code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//how much time before allowed to shoot again</span>
<span style="color: #000000; font-weight: bold;">var</span> cTime:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>;
<span style="color: #808080; font-style: italic;">//the time it has to reach in order to be allowed to shoot (in frames)</span>
<span style="color: #000000; font-weight: bold;">var</span> cLimit:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">12</span>;
<span style="color: #808080; font-style: italic;">//whether or not the user is allowed to shoot</span>
<span style="color: #000000; font-weight: bold;">var</span> shootAllow:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">true</span>;</pre></div></div>

<p>Next, we have to add a timer that will increment the <tt>cTime</tt> variable every frame. We won&#8217;t use the built in <tt>Timer</tt> class that ActionScript has (if you even know what that is) because going by frames is much more efficient. Add this code to the <tt>moveChar()</tt> function:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//Incrementing the cTime</span>
&nbsp;
<span style="color: #808080; font-style: italic;">//checking if cTime has reached the limit yet</span>
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>cTime <span style="color: #66cc66;">&lt;</span> cLimit<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	cTime ++;
<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//if it has, then allow the user to shoot</span>
	shootAllow = <span style="color: #000000; font-weight: bold;">true</span>;
	<span style="color: #808080; font-style: italic;">//and reset cTime</span>
	cTime = <span style="color: #cc66cc;">0</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Now we can finally allow the shooting to occur. Add this code to the <tt>checkKeysDown()</tt> function.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//checking if the space bar is pressed and shooting is allowed</span>
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">keyCode</span> == <span style="color: #cc66cc;">32</span> <span style="color: #66cc66;">&amp;&amp;</span> shootAllow<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//making it so the user can't shoot for a bit</span>
	shootAllow = <span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #808080; font-style: italic;">//declaring a variable to be a new Bullet</span>
	<span style="color: #000000; font-weight: bold;">var</span> newBullet:<span style="color: #0066CC;">Bullet</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Bullet</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #808080; font-style: italic;">//changing the bullet's coordinates</span>
	newBullet.<span style="color: #006600;">x</span> = mcMain.<span style="color: #006600;">x</span> + mcMain.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span> - newBullet.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;
	newBullet.<span style="color: #006600;">y</span> = mcMain.<span style="color: #006600;">y</span>;
	<span style="color: #808080; font-style: italic;">//then we add the bullet to stage</span>
	addChild<span style="color: #66cc66;">&#40;</span>newBullet<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Now if you test your movie, you should be able to shoot! Hurrah!</p>
<p>This concludes this part of the tutorial, stay tuned for the next one, creating enemies!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashgametuts.com/tutorials/as3/how-to-make-a-vertical-shooter-in-as3-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Make a Vertical Shooter in AS3 &#8211; Part 1</title>
		<link>http://www.flashgametuts.com/tutorials/as3/how-to-make-a-vertical-shooter-in-as3-part-1/</link>
		<comments>http://www.flashgametuts.com/tutorials/as3/how-to-make-a-vertical-shooter-in-as3-part-1/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 12:00:18 +0000</pubDate>
		<dc:creator>Mr Sun</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[Intermediate Tutorials]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[shooter]]></category>
		<category><![CDATA[teaching]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[vertical]]></category>

		<guid isPermaLink="false">http://www.mrsunstudios.com/?p=600</guid>
		<description><![CDATA[Today, we&#8217;re going to make a classic vertical shooter game in ActionScript 3. I hope you learn from it! Let us begin. The first thing that I&#8217;m going to do is make the background of my game black, so it looks more retro. Then, we&#8217;re going to have to make the frame rate faster, mine [...]]]></description>
			<content:encoded><![CDATA[<p>Today, we&#8217;re going to make a classic vertical shooter game in ActionScript 3. I hope you learn from it! Let us begin.</p>
<p>The first thing that I&#8217;m going to do is make the background of my game black, so it looks more retro. Then, we&#8217;re going to have to make the frame rate faster, mine will be 24 fps. Also, this will be a vertical shooter, so we probably should make the playing screen less wide. My new dimensions are at 300&#215;400 pixels.</p>
<p>Next, we&#8217;re going to draw a character. Mine will be simple, just a triangle pointing upwards.<br />
<img src="http://www.flashgametuts.com/obj/tuts/vert-shooter-as3/pt1/character.gif" alt="My character" /><br />
The dimensions for it are 30&#215;35 pixels.</p>
<p>Then, we&#8217;re going to turn it into a symbol. After that, we&#8217;re going to call it <tt>mcMain</tt> for main character. We will need this so we can reference the guy later. Now we&#8217;re ready to code this sucker. Make a new layer called &#8220;actions&#8221; and add the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//these booleans will check which keys are down</span>
<span style="color: #000000; font-weight: bold;">var</span> leftDown:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;
<span style="color: #000000; font-weight: bold;">var</span> upDown:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;
<span style="color: #000000; font-weight: bold;">var</span> rightDown:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;
<span style="color: #000000; font-weight: bold;">var</span> downDown:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;
<span style="color: #808080; font-style: italic;">//how fast the character will be able to go</span>
<span style="color: #000000; font-weight: bold;">var</span> mainSpeed:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">5</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//adding a listener to mcMain that will move the character</span>
mcMain.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, moveChar<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">function</span> moveChar<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//checking if the key booleans are true then moving</span>
	<span style="color: #808080; font-style: italic;">//the character based on the keys</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>leftDown<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		mcMain.<span style="color: #006600;">x</span> -= mainSpeed;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>upDown<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		mcMain.<span style="color: #006600;">y</span> -= mainSpeed;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>rightDown<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		mcMain.<span style="color: #006600;">x</span> += mainSpeed;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>downDown<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		mcMain.<span style="color: #006600;">y</span> += mainSpeed;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #808080; font-style: italic;">//keeping the main character within bounds</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>mcMain.<span style="color: #006600;">x</span> <span style="color: #66cc66;">&lt;</span>= <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		mcMain.<span style="color: #006600;">x</span> += mainSpeed;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>mcMain.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&lt;</span>= <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		mcMain.<span style="color: #006600;">y</span> += mainSpeed;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>mcMain.<span style="color: #006600;">x</span> <span style="color: #66cc66;">&gt;</span>= <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span> - mcMain.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		mcMain.<span style="color: #006600;">x</span> -= mainSpeed;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>mcMain.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&gt;</span>= <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span> - mcMain.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		mcMain.<span style="color: #006600;">y</span> -= mainSpeed;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">//this listener will listen for down keystrokes</span>
<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>KeyboardEvent.<span style="color: #006600;">KEY_DOWN</span>, checkKeysDown<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">function</span> checkKeysDown<span style="color: #66cc66;">&#40;</span>event:KeyboardEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//making the booleans true based on the keycode</span>
	<span style="color: #808080; font-style: italic;">//WASD Keys or arrow keys</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">keyCode</span> == <span style="color: #cc66cc;">37</span> <span style="color: #66cc66;">||</span> event.<span style="color: #006600;">keyCode</span> == <span style="color: #cc66cc;">65</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		leftDown = <span style="color: #000000; font-weight: bold;">true</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">keyCode</span> == <span style="color: #cc66cc;">38</span> <span style="color: #66cc66;">||</span> event.<span style="color: #006600;">keyCode</span> == <span style="color: #cc66cc;">87</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		upDown = <span style="color: #000000; font-weight: bold;">true</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">keyCode</span> == <span style="color: #cc66cc;">39</span> <span style="color: #66cc66;">||</span> event.<span style="color: #006600;">keyCode</span> == <span style="color: #cc66cc;">68</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		rightDown = <span style="color: #000000; font-weight: bold;">true</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">keyCode</span> == <span style="color: #cc66cc;">40</span> <span style="color: #66cc66;">||</span> event.<span style="color: #006600;">keyCode</span> == <span style="color: #cc66cc;">83</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		downDown = <span style="color: #000000; font-weight: bold;">true</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">//this listener will listen for keys being released</span>
<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>KeyboardEvent.<span style="color: #006600;">KEY_UP</span>, checkKeysUp<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">function</span> checkKeysUp<span style="color: #66cc66;">&#40;</span>event:KeyboardEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//making the booleans false based on the keycode</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">keyCode</span> == <span style="color: #cc66cc;">37</span> <span style="color: #66cc66;">||</span> event.<span style="color: #006600;">keyCode</span> == <span style="color: #cc66cc;">65</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		leftDown = <span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">keyCode</span> == <span style="color: #cc66cc;">38</span> <span style="color: #66cc66;">||</span> event.<span style="color: #006600;">keyCode</span> == <span style="color: #cc66cc;">87</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		upDown = <span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">keyCode</span> == <span style="color: #cc66cc;">39</span> <span style="color: #66cc66;">||</span> event.<span style="color: #006600;">keyCode</span> == <span style="color: #cc66cc;">68</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		rightDown = <span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">keyCode</span> == <span style="color: #cc66cc;">40</span> <span style="color: #66cc66;">||</span> event.<span style="color: #006600;">keyCode</span> == <span style="color: #cc66cc;">83</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		downDown = <span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Yes, sometimes with arrow keys, the code does get very repetitive.</p>
<p>Actually, this is all that this part of the tutorial actually requires. Next time, we&#8217;ll make the main character shoot!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashgametuts.com/tutorials/as3/how-to-make-a-vertical-shooter-in-as3-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Make a Rhythm Game in AS3 &#8211; Part 6</title>
		<link>http://www.flashgametuts.com/tutorials/as3/how-to-make-a-rhythm-game-in-as3-part-6/</link>
		<comments>http://www.flashgametuts.com/tutorials/as3/how-to-make-a-rhythm-game-in-as3-part-6/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 12:06:53 +0000</pubDate>
		<dc:creator>Mr Sun</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[Intermediate Tutorials]]></category>
		<category><![CDATA[music]]></category>
		<category><![CDATA[rhythm]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.mrsunstudios.com/?p=1210</guid>
		<description><![CDATA[The next step in making our rhythm game is scoring. The user will get points depending on how far away the arrow is from the receptor when it hits it. We&#8217;re also going to make the health bar gain and lose parts when the user hits or misses the receptor. First of all, we need [...]]]></description>
			<content:encoded><![CDATA[<p>The next step in making our rhythm game is scoring. The user will get points depending on how far away the arrow is from the receptor when it hits it. We&#8217;re also going to make the health bar gain and lose parts when the user hits or misses the receptor. First of all, we need to define a score variable at the top of the game frame. We also have to define a String variable that will show how well the user hits the arrow.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//the score variable</span>
<span style="color: #000000; font-weight: bold;">var</span> score:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>;
<span style="color: #808080; font-style: italic;">//either perfect, great, nice, or good</span>
<span style="color: #000000; font-weight: bold;">var</span> scoreString:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">''</span>;</pre></div></div>

<p>That was pretty easy. Next, we want to increase the score whenever the user hits the right key when it hits the score. We&#8217;re going to make it increase by 10 for a perfect hit, 8 for a great hit, 6 for an nice hit, and 4 for a good hit.  Add this code to the &#8220;Arrow.as&#8221; class in the <tt>checkKeys()</tt> function:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> checkKeys<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:KeyboardEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//checking if a certain key is down and it's touching the receptor</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span> == arrowCode <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #0066CC;">this</span>.<span style="color: #006600;">hitTestObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_root</span>.<span style="color: #006600;">mcReceptor</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">//checking if the correct key is down</span>
		<span style="color: #808080; font-style: italic;">//if the user hits it about perfectly</span>
		<span style="color: #808080; font-style: italic;">//the receptors y coordinate is about 10 px away from the</span>
		<span style="color: #808080; font-style: italic;">//symbol's y coordinate.</span>
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&lt;</span>= <span style="color: #0066CC;">_root</span>.<span style="color: #006600;">mcReceptor</span>.<span style="color: #006600;">y</span> + <span style="color: #cc66cc;">15</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #0066CC;">this</span>.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&gt;</span>= <span style="color: #0066CC;">_root</span>.<span style="color: #006600;">mcReceptor</span>.<span style="color: #006600;">y</span> + <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">_root</span>.<span style="color: #006600;">score</span> += <span style="color: #cc66cc;">10</span>;
			<span style="color: #0066CC;">_root</span>.<span style="color: #006600;">scoreString</span> = <span style="color: #ff0000;">'Perfect'</span>;
		<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&lt;</span>= <span style="color: #0066CC;">_root</span>.<span style="color: #006600;">mcReceptor</span>.<span style="color: #006600;">y</span> + <span style="color: #cc66cc;">25</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #0066CC;">this</span>.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&gt;</span>= <span style="color: #0066CC;">_root</span>.<span style="color: #006600;">mcReceptor</span>.<span style="color: #006600;">y</span>-<span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">_root</span>.<span style="color: #006600;">score</span> += <span style="color: #cc66cc;">8</span>;
			<span style="color: #0066CC;">_root</span>.<span style="color: #006600;">scoreString</span> = <span style="color: #ff0000;">'Great'</span>;
		<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&lt;</span>= <span style="color: #0066CC;">_root</span>.<span style="color: #006600;">mcReceptor</span>.<span style="color: #006600;">y</span> + <span style="color: #cc66cc;">40</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #0066CC;">this</span>.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&gt;</span>= <span style="color: #0066CC;">_root</span>.<span style="color: #006600;">mcReceptor</span>.<span style="color: #006600;">y</span> -<span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">_root</span>.<span style="color: #006600;">score</span> += <span style="color: #cc66cc;">6</span>;
			<span style="color: #0066CC;">_root</span>.<span style="color: #006600;">scoreString</span> = <span style="color: #ff0000;">'Nice'</span>;
		<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">_root</span>.<span style="color: #006600;">score</span> += <span style="color: #cc66cc;">4</span>;
			<span style="color: #0066CC;">_root</span>.<span style="color: #006600;">scoreString</span> = <span style="color: #ff0000;">'Good'</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		destroyThis<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//remove it from stage</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The next thing we have to do now is program the health bar. If the user misses or hits the arrow key at the wrong time, then we have to lose health. If the user hits it right though, the health will increase. First of all, give the health bar an instance name, <tt>mcHealth</tt>. Then, we&#8217;re going to make a function for this, so we don&#8217;t have to write all the if statements repeatedly. Define this function at the bottom of your code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//this function will change the health depending on how much health change</span>
<span style="color: #808080; font-style: italic;">//it needs, positive or negative</span>
<span style="color: #000000; font-weight: bold;">function</span> changeHealth<span style="color: #66cc66;">&#40;</span>healthDiff:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	healthDiff <span style="color: #66cc66;">/</span>= <span style="color: #cc66cc;">100</span>;<span style="color: #808080; font-style: italic;">//the scaleX only changes in percentages</span>
	<span style="color: #808080; font-style: italic;">//checking if the health is already at it's full</span>
	<span style="color: #808080; font-style: italic;">//or will be full after this hit</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>mcHealth.<span style="color: #006600;">scaleX</span> + healthDiff <span style="color: #66cc66;">&gt;</span>= <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		mcHealth.<span style="color: #006600;">scaleX</span> = <span style="color: #cc66cc;">1</span>;
	<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>mcHealth.<span style="color: #006600;">scaleX</span> + healthDiff <span style="color: #66cc66;">&lt;</span>= <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">//checking if the health will be equal or below 0</span>
		<span style="color: #808080; font-style: italic;">//lose function will go here</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">//if there are no problems</span>
		mcHealth.<span style="color: #006600;">scaleX</span> += healthDiff;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The next thing we&#8217;re going to do is run this function positively when the user hits the key correctly. In the arrow&#8217;s code where it hit tests with the receptor, put this code for perfect:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">changeHealth<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>This will increase the health by 5. You can do the rest yourself, just keep on decrementing the health change by 1, and you&#8217;ll be good.</p>
<p>Next comes the hard part, making the user lose health. Again, we have to define a few variables at the top. They will be Booleans saying whether or not the receptor is touching a certain key.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//Booleans checking if the arrows are touching the receptor</span>
<span style="color: #000000; font-weight: bold;">var</span> touchLeft:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;
<span style="color: #000000; font-weight: bold;">var</span> touchUp:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;
<span style="color: #000000; font-weight: bold;">var</span> touchDown:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;
<span style="color: #000000; font-weight: bold;">var</span> touchRight:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;</pre></div></div>

<p>Now, add this code to the <tt>makeLvl()</tt> function:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//checking if mcReceptor is touching any arrows</span>
	<span style="color: #808080; font-style: italic;">//first we reset the variables we got last time just in case they aren't true anymore</span>
	touchLeft = <span style="color: #000000; font-weight: bold;">false</span>;
	touchUp = <span style="color: #000000; font-weight: bold;">false</span>;
	touchDown = <span style="color: #000000; font-weight: bold;">false</span>;
	touchRight = <span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #808080; font-style: italic;">//this for loop will be used for the hit testing</span>
	<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>;i<span style="color: #66cc66;">&lt;</span>numChildren;i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">target</span>:<span style="color: #0066CC;">Object</span> = getChildAt<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">target</span>.<span style="color: #006600;">arrowCode</span> <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #0066CC;">target</span>.<span style="color: #006600;">hitTestObject</span><span style="color: #66cc66;">&#40;</span>mcReceptor<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #808080; font-style: italic;">//if the object is an arrow and is touching the receptor</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">target</span>.<span style="color: #006600;">arrowCode</span> == <span style="color: #cc66cc;">37</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #808080; font-style: italic;">//if left arrow</span>
				touchLeft = <span style="color: #000000; font-weight: bold;">true</span>;
			<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">target</span>.<span style="color: #006600;">arrowCode</span> == <span style="color: #cc66cc;">38</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #808080; font-style: italic;">//if up arrow</span>
				touchUp = <span style="color: #000000; font-weight: bold;">true</span>;
			<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">target</span>.<span style="color: #006600;">arrowCode</span> == <span style="color: #cc66cc;">40</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #808080; font-style: italic;">//if down arrow</span>
				touchDown = <span style="color: #000000; font-weight: bold;">true</span>;
			<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">target</span>.<span style="color: #006600;">arrowCode</span> == <span style="color: #cc66cc;">39</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #808080; font-style: italic;">//if right arrow</span>
				touchRight = <span style="color: #000000; font-weight: bold;">true</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Now that we have the variables checking which arrow is touching the receptor, now we need some key checkers. Add this to the bottom of your code in the &#8220;game&#8221; frame:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>KeyboardEvent.<span style="color: #006600;">KEY_DOWN</span>, checkKeys<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">function</span> checkKeys<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:KeyboardEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//if the left key is down and no left arrows are touching the receptor</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span> == <span style="color: #cc66cc;">37</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #66cc66;">!</span>touchLeft<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		changeHealth<span style="color: #66cc66;">&#40;</span>-<span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//make the health go down</span>
	<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span> == <span style="color: #cc66cc;">38</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #66cc66;">!</span>touchUp<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #808080; font-style: italic;">//and so on</span>
		changeHealth<span style="color: #66cc66;">&#40;</span>-<span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span> == <span style="color: #cc66cc;">40</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #66cc66;">!</span>touchDown<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		changeHealth<span style="color: #66cc66;">&#40;</span>-<span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span> == <span style="color: #cc66cc;">39</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #66cc66;">!</span>touchRight<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		changeHealth<span style="color: #66cc66;">&#40;</span>-<span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Phew, that took a while. Now, for the final part of losing health, when the person misses the arrow altogether. Place this code at the end of the arrow&#8217;s <tt>eFrame</tt> function.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//if game is over or it's off the stage, destroy it</span>
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_root</span>.<span style="color: #006600;">gameOver</span> <span style="color: #66cc66;">||</span> <span style="color: #0066CC;">this</span>.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&lt;</span> -<span style="color: #cc66cc;">60</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//if off the stage</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&lt;</span> -<span style="color: #cc66cc;">60</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">_root</span>.<span style="color: #006600;">changeHealth</span><span style="color: #66cc66;">&#40;</span>-<span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	destroyThis<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Well, that&#8217;s all for scoring. This probably has been the longest lesson in the series. If you survived through this without having any trouble, then you can do the next part without my help, the finishing touches.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashgametuts.com/tutorials/as3/how-to-make-a-rhythm-game-in-as3-part-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Make a Vertical Shooter in AS2 &#8211; Part 6</title>
		<link>http://www.flashgametuts.com/tutorials/as2/how-to-make-a-vertical-shooter-in-as2-part-6/</link>
		<comments>http://www.flashgametuts.com/tutorials/as2/how-to-make-a-vertical-shooter-in-as2-part-6/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 12:06:47 +0000</pubDate>
		<dc:creator>Mr Sun</dc:creator>
				<category><![CDATA[AS2]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[Intermediate Tutorials]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[shooter]]></category>
		<category><![CDATA[teaching]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[vertical]]></category>

		<guid isPermaLink="false">http://www.mrsunstudios.com/?p=1148</guid>
		<description><![CDATA[As always, the finishing touches of this game won&#8217;t be explained too much by me, in hopes that you actually can do some of this stuff by yourself. Of course, there will always be source files at the bottom if you need to clear anything up. The first thing I want to do is show [...]]]></description>
			<content:encoded><![CDATA[<p>As always, the finishing touches of this game won&#8217;t be explained too much by me, in hopes that you actually can do some of this stuff by yourself. Of course, there will always be source files at the bottom if you need to clear anything up.</p>
<p>The first thing I want to do is show the score on the &#8220;lose&#8221; screen. That&#8217;ll be pretty easy, just add a dynamic text field there.</p>
<p>Next, we can make some particles move down the screen so it looks like the player is actually moving forward. We&#8217;re going to make them the same speed as the enemies. I&#8217;m actually show some code for this one, because it&#8217;s also a pretty new thing for me. We&#8217;re not going to make a MovieClip for this, we&#8217;re going to make dynamic shapes through ActionScript. First, we have to add a <tt>totalBgShapes</tt> variable to the top of the code. Next, create an empty MovieClip called <tt>bgHolder</tt> Then, here&#8217;s the code to place at the bottom of the <tt>onEnterFrame</tt> function:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//creating background particles</span>
bgHolder.<span style="color: #0066CC;">createEmptyMovieClip</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;bg&quot;</span>+totalBgShapes, bgHolder.<span style="color: #0066CC;">getNextHighestDepth</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
bgHolder<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;bg&quot;</span>+totalBgShapes<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0x333333<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//this just determines the shape's color</span>
bgHolder<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;bg&quot;</span>+totalBgShapes<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">_x</span> = <span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">550</span><span style="color: #66cc66;">&#41;</span>;
gHolder<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;bg&quot;</span>+totalBgShapes<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">_y</span> = -<span style="color: #cc66cc;">50</span> - bgHolder.<span style="color: #0066CC;">_y</span>;
<span style="color: #808080; font-style: italic;">//creating 4 random points to make a random shape</span>
bgHolder<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;bg&quot;</span>+totalBgShapes<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">25</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">25</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
bgHolder<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;bg&quot;</span>+totalBgShapes<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">25</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">25</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
bgHolder<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;bg&quot;</span>+totalBgShapes<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">25</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">25</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
bgHolder<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;bg&quot;</span>+totalBgShapes<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">25</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">25</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
bgHolder<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;bg&quot;</span>+totalBgShapes<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//finishes up the shape</span>
&nbsp;
bgHolder<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;bg&quot;</span>+totalBgShapes<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">onEnterFrame</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #808080; font-style: italic;">//giving it some actions</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">_y</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">450</span> - bgHolder.<span style="color: #0066CC;">_y</span> <span style="color: #66cc66;">||</span> <span style="color: #0066CC;">_root</span>.<span style="color: #006600;">gameOver</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #808080; font-style: italic;">//if it goes off the stage or game is over</span>
		<span style="color: #808080; font-style: italic;">//then destroy it</span>
		<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">removeMovieClip</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
totalBgShapes ++;
bgHolder.<span style="color: #0066CC;">_y</span> += <span style="color: #cc66cc;">2</span>;</pre></div></div>

<p>Pretty intense, eh? Well, this is a finishing touch, and most finishing touches <em>are</em> pretty intense. Now, we have to make it so <tt>mcMain</tt> is on top of everything with this code at the end:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">mcMain.<span style="color: #0066CC;">swapDepths</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Also, remove <tt>mcMain</tt> when <tt>gameOver</tt> is true or else strange things will happen.</p>
<p>There is one final thing that I want to do before actually wrapping up this tutorial.  For some reason, there is a bug where a bullet disappears for some strange reason.  I think I know exactly how to fix it.  When we added the bullet to the stage, we made its depth the <tt>_root.getNextHighestDepth</tt>. I&#8217;m sorry, it should actually be <tt>bulletHolder.getNextHighestDepth</tt>.</p>
<p>Well, that&#8217;s actually all that I really have to finish off the game. I hope you had fun making it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashgametuts.com/tutorials/as2/how-to-make-a-vertical-shooter-in-as2-part-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Make a Vertical Shooter in AS2 &#8211; Part 5</title>
		<link>http://www.flashgametuts.com/tutorials/as2/how-to-make-a-vertical-shooter-in-as2-part-5/</link>
		<comments>http://www.flashgametuts.com/tutorials/as2/how-to-make-a-vertical-shooter-in-as2-part-5/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 12:05:02 +0000</pubDate>
		<dc:creator>Mr Sun</dc:creator>
				<category><![CDATA[AS2]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[Intermediate Tutorials]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[shooter]]></category>
		<category><![CDATA[teaching]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[vertical]]></category>

		<guid isPermaLink="false">http://www.mrsunstudios.com/?p=1140</guid>
		<description><![CDATA[Now that we&#8217;ve got the hardest part down, it all gets easier from here. This chapter will be simple, just some code that has scoring. Also, as promised, we&#8217;re going to have a function run when the player is hit by an enemy. Let&#8217;s start with this one first, eh? In order to do this, [...]]]></description>
			<content:encoded><![CDATA[<p>Now that we&#8217;ve got the hardest part down, it all gets easier from here. This chapter will be simple, just some code that has scoring. Also, as promised, we&#8217;re going to have a function run when the player is hit by an enemy. Let&#8217;s start with this one first, eh?</p>
<p>In order to do this, we have to make a frame called &#8220;lose&#8221;. This will be the frame that we&#8217;ll navigate to when we get hit. It&#8217;ll be simple, just some text that says &#8220;You Lose&#8221; and a listener for keystrokes  that will return us to play another game. First, make the frame called &#8220;lose&#8221;. I recommend making an entire new layer for labels, but this isn&#8217;t required. In that frame, draw or type in whatever you want to signify that the player has lost the game. I&#8217;m just going to put the text, &#8220;YOU LOSE&#8221; and, in smaller text, &#8220;Press Space to Restart&#8221;.</p>
<p>Then, in the actions, type in the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//stops the game so nothing goes wrong</span>
&nbsp;
<span style="color: #0066CC;">_root</span>.<span style="color: #0066CC;">onEnterFrame</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">//create a function to check for keystrokes</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Key</span>.<span style="color: #0066CC;">isDown</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #808080; font-style: italic;">//if the space key is down...</span>
		<span style="color: #0066CC;">gotoAndStop</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//then go back to the first frame, restarting the game</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Now, I&#8217;ve noticed a bit of a problem in the main code.  For some reason, the game thinks that you get hit whenever you shoot an enemy.  I&#8217;ve found a way around this strange behavior, however. First of all, add this variable to the top of the code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//showing the amount of enemies that have been added to the stage</span>
<span style="color: #000000; font-weight: bold;">var</span> enemyTotal:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;</pre></div></div>

<p>Next, find the code where we have to create the enemy and add it to the stage.  Change it to this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">_root</span>.<span style="color: #0066CC;">attachMovie</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'mcEnemy'</span>, <span style="color: #ff0000;">'en'</span>+enemyTotal,<span style="color: #0066CC;">_root</span>.<span style="color: #0066CC;">getNextHighestDepth</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//then add the enemy</span>
<span style="color: #808080; font-style: italic;">//setting it's coordinates</span>
<span style="color: #0066CC;">_root</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'en'</span>+enemyTotal<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">_x</span> = <span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #0066CC;">Stage</span>.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//randomly within the boundaries</span>
<span style="color: #0066CC;">_root</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'en'</span>+enemyTotal<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">_y</span> = -<span style="color: #cc66cc;">50</span>; <span style="color: #808080; font-style: italic;">//sets this offstage at first</span>
<span style="color: #0066CC;">_root</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'en'</span>+enemyTotal<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">onEnterFrame</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #808080; font-style: italic;">//then give it some functions</span>
	<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">_y</span> += <span style="color: #cc66cc;">5</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">//run a loop checking if it's touching any bullets</span>
	<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> cBullet:<span style="color: #0066CC;">String</span> <span style="color: #b1b100;">in</span> <span style="color: #0066CC;">_root</span>.<span style="color: #006600;">bulletHolder</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">//if it's touching the bullet</span>
		<span style="color: #808080; font-style: italic;">//we have to use coordinates because hit testing doesn't seem to work</span>
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">_y</span> <span style="color: #66cc66;">&gt;</span>= <span style="color: #0066CC;">_root</span>.<span style="color: #006600;">bulletHolder</span><span style="color: #66cc66;">&#91;</span>cBullet<span style="color: #66cc66;">&#93;</span>._y-<span style="color: #cc66cc;">30</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">_y</span> <span style="color: #66cc66;">&lt;</span>= <span style="color: #0066CC;">_root</span>.<span style="color: #006600;">bulletHolder</span><span style="color: #66cc66;">&#91;</span>cBullet<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">_y</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">_x</span> <span style="color: #66cc66;">&lt;</span>= <span style="color: #0066CC;">_root</span>.<span style="color: #006600;">bulletHolder</span><span style="color: #66cc66;">&#91;</span>cBullet<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">_x</span>+<span style="color: #cc66cc;">5</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">_x</span> <span style="color: #66cc66;">&gt;</span>= <span style="color: #0066CC;">_root</span>.<span style="color: #006600;">bulletHolder</span><span style="color: #66cc66;">&#91;</span>cBullet<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">_x</span> -<span style="color: #cc66cc;">35</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
				<span style="color: #808080; font-style: italic;">//then destroy this guy</span>
				<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">removeMovieClip</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #808080; font-style: italic;">//and destroy the bullet</span>
				<span style="color: #0066CC;">_root</span>.<span style="color: #006600;">bulletHolder</span><span style="color: #66cc66;">&#91;</span>cBullet<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">removeMovieClip</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">//hit testing with the user</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">hitTest</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_root</span>.<span style="color: #006600;">mcMain</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">//we'll add code here in the next part</span>
		<span style="color: #808080; font-style: italic;">//but for now, we'll just trace something</span>
		<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'You just got hit!'</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
enemyTime = <span style="color: #cc66cc;">0</span>;<span style="color: #808080; font-style: italic;">//reset the time</span>
enemyTotal ++; <span style="color: #808080; font-style: italic;">//add 1 more to the amount of enemies total</span></pre></div></div>

<p>I&#8217;m sorry about this delay, but we need this to continue on with our game.</p>
<p>Now, we have to create a new variable at the top that will say whether or not the game has been ended:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//add a stop function too!</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> gameOver:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;</pre></div></div>

<p>Then, add this code to both the <tt>mcBullet</tt>&#8216;s and <tt>mcEnemy</tt>&#8216;s <tt>onEnterFrame</tt> functions:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//checking if the game is over</span>
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>gameOver<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//destroy this guy if the game is over</span>
	<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">removeMovieClip</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Now, we can make this Boolean false when the user gets touched by the enemy. Find where we hit test for <tt>mcMain</tt> and replace that trace statement with:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//hit testing with the user</span>
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">hitTest</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_root</span>.<span style="color: #006600;">mcMain</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//set the game to be over and go to lose screen</span>
	gameOver = <span style="color: #000000; font-weight: bold;">true</span>;
	<span style="color: #0066CC;">gotoAndStop</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'lose'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Phew, that was a lot of work, wasn&#8217;t it? Now we can move onto actually scoring the game. First, we have to define a score variable at the top:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//the player's score</span>
<span style="color: #000000; font-weight: bold;">var</span> score:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;</pre></div></div>

<p>Then, increment the score every time an enemy is killed. Place this code in the Enemy&#8217;s hit testing for the bullet.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//up the score</span>
<span style="color: #0066CC;">_root</span>.<span style="color: #006600;">score</span> += <span style="color: #cc66cc;">5</span>;</pre></div></div>

<p>Now, we can show the score to the user with a dynamic text field. Make one at the bottom of the stage and give it an instance name of <tt>txtScore</tt>. Next, place this code into the <tt>onEnterFrame</tt> function.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//updating the score text field</span>
txtScore.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">'Score:  '</span>+score;</pre></div></div>

<p>Pretty easy, right? Well, that&#8217;s all we&#8217;re going to do for scoring. Next, we&#8217;ll add some sweet finishing touches, eh?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashgametuts.com/tutorials/as2/how-to-make-a-vertical-shooter-in-as2-part-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Make a Vertical Shooter in AS2 &#8211; Part 4</title>
		<link>http://www.flashgametuts.com/tutorials/as2/how-to-make-a-vertical-shooter-in-as2-part-4/</link>
		<comments>http://www.flashgametuts.com/tutorials/as2/how-to-make-a-vertical-shooter-in-as2-part-4/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 12:04:34 +0000</pubDate>
		<dc:creator>Mr Sun</dc:creator>
				<category><![CDATA[AS2]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[Intermediate Tutorials]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[shooter]]></category>
		<category><![CDATA[teaching]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[vertical]]></category>

		<guid isPermaLink="false">http://www.mrsunstudios.com/?p=1132</guid>
		<description><![CDATA[Now we have to make it so the enemies can be shot. This probably will be the most complicated of the steps. But, it also is what makes this thing a game. There are two ways that I know of to accomplish this task. The first one is to have the bullet listen for hit [...]]]></description>
			<content:encoded><![CDATA[<p>Now we have to make it so the enemies can be shot. This probably will be the most complicated of the steps. But, it also is what makes this thing a game. There are two ways that I know of to accomplish this task. The first one is to have the bullet listen for hit testing the enemy, or the enemy listen for the bullet. It&#8217;s basically the same thing. However, I&#8217;m going to have the enemy listen for the bullet, just because I feel like it.</p>
<p>The first thing we need to do in order to accomplish this feat is to create a container for all of the bullets. This way, we can access all of the bullets through the container. I can&#8217;t really explain this too well, so I&#8217;ll just demonstrate it for you. At the top of the code, add the following:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//this movieclip will hold all of the bullets</span>
<span style="color: #0066CC;">_root</span>.<span style="color: #0066CC;">createEmptyMovieClip</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'bulletHolder'</span>, <span style="color: #0066CC;">_root</span>.<span style="color: #0066CC;">getNextHighestDepth</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>The <tt>bulletHolder</tt> is invisible and is just a container for all of the bullets. In order for this to be any use to us, we need to actually add the bullets to this container. This will be easy. Find where we add the bullet to the stage:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">_root</span>.<span style="color: #0066CC;">attachMovie</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'mcBullet'</span>, <span style="color: #ff0000;">'Bullet'</span>+bulletID,<span style="color: #0066CC;">_root</span>.<span style="color: #0066CC;">getNextHighestDepth</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">//setting the coordinates of the bullet to be the same as the main character</span>
<span style="color: #0066CC;">_root</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'Bullet'</span>+bulletID<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">_x</span> = mcMain.<span style="color: #0066CC;">_x</span> + mcMain.<span style="color: #0066CC;">_width</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span> - <span style="color: #0066CC;">_root</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'Bullet'</span>+bulletID<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">_width</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;
<span style="color: #0066CC;">_root</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'Bullet'</span>+bulletID<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">_y</span> = mcMain.<span style="color: #0066CC;">_y</span>;
	<span style="color: #0066CC;">_root</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'Bullet'</span>+bulletID<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">onEnterFrame</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//giving the bullet some actions</span>
	<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">_y</span> -= <span style="color: #cc66cc;">10</span>; <span style="color: #808080; font-style: italic;">//moving the bullet</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">_y</span> <span style="color: #66cc66;">&lt;</span> -<span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">_height</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #808080; font-style: italic;">//if the bullet goes off stage</span>
		<span style="color: #808080; font-style: italic;">//then destroy it</span>
		<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">removeMovieClip</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Change it to this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">bulletHolder.<span style="color: #0066CC;">attachMovie</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'mcBullet'</span>, <span style="color: #ff0000;">'Bullet'</span>+bulletID,<span style="color: #0066CC;">_root</span>.<span style="color: #0066CC;">getNextHighestDepth</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">//setting the coordinates of the bullet to be the same as the main character</span>
bulletHolder<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'Bullet'</span>+bulletID<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">_x</span> = mcMain.<span style="color: #0066CC;">_x</span> + mcMain.<span style="color: #0066CC;">_width</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span> - bulletHolder<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'Bullet'</span>+bulletID<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">_width</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;
bulletHolder<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'Bullet'</span>+bulletID<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">_y</span> = mcMain.<span style="color: #0066CC;">_y</span>;
bulletHolder<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'Bullet'</span>+bulletID<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">onEnterFrame</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//giving the bullet some actions</span>
	<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">_y</span> -= <span style="color: #cc66cc;">10</span>; <span style="color: #808080; font-style: italic;">//moving the bullet</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">_y</span> <span style="color: #66cc66;">&lt;</span> -<span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">*</span> <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">_height</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #808080; font-style: italic;">//if the bullet goes off stage</span>
		<span style="color: #808080; font-style: italic;">//then destroy it</span>
		<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">removeMovieClip</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Now we enter complicated territory. Find the <tt>onEnterFrame</tt> function we added to the Enemy. Add the following to it:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//run a loop checking if it's touching any bullets</span>
<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> cBullet:<span style="color: #0066CC;">String</span> <span style="color: #b1b100;">in</span> <span style="color: #0066CC;">_root</span>.<span style="color: #006600;">bulletHolder</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//if it's touching the bullet</span>
	<span style="color: #808080; font-style: italic;">//we have to use coordinates because hit testing doesn't seem to work</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">_y</span> <span style="color: #66cc66;">&gt;</span>= <span style="color: #0066CC;">_root</span>.<span style="color: #006600;">bulletHolder</span><span style="color: #66cc66;">&#91;</span>cBullet<span style="color: #66cc66;">&#93;</span>._y-<span style="color: #cc66cc;">30</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">_y</span> <span style="color: #66cc66;">&lt;</span>= <span style="color: #0066CC;">_root</span>.<span style="color: #006600;">bulletHolder</span><span style="color: #66cc66;">&#91;</span>cBullet<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">_y</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">_x</span> <span style="color: #66cc66;">&lt;</span>= <span style="color: #0066CC;">_root</span>.<span style="color: #006600;">bulletHolder</span><span style="color: #66cc66;">&#91;</span>cBullet<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">_x</span>+<span style="color: #cc66cc;">5</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">_x</span> <span style="color: #66cc66;">&gt;</span>= <span style="color: #0066CC;">_root</span>.<span style="color: #006600;">bulletHolder</span><span style="color: #66cc66;">&#91;</span>cBullet<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">_x</span> -<span style="color: #cc66cc;">35</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">//then destroy this guy</span>
			<span style="color: #0066CC;">_root</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'en'</span>+enID<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">removeMovieClip</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #808080; font-style: italic;">//and destroy the bullet</span>
			<span style="color: #0066CC;">_root</span>.<span style="color: #006600;">bulletHolder</span><span style="color: #66cc66;">&#91;</span>cBullet<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">removeMovieClip</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Now, try out your game. It should work pretty well now. The only problem with it, however, is that it doesn&#8217;t do anything when it touches the player. We aren&#8217;t going to really do anything with this right now, but we will set it up so we can make a function for it in the next part of the tutorial, &#8220;Scoring&#8221;. Just place the following code in the <tt>Enemy</tt>&#8216;s <tt>onEnterFrame()</tt> function:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">			<span style="color: #808080; font-style: italic;">//hit testing with the user</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">_y</span> <span style="color: #66cc66;">&gt;</span>= <span style="color: #0066CC;">_root</span>.<span style="color: #006600;">mcMain</span>._y-<span style="color: #cc66cc;">30</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">_y</span> <span style="color: #66cc66;">&lt;</span>= <span style="color: #0066CC;">_root</span>.<span style="color: #006600;">mcMain</span>.<span style="color: #0066CC;">_y</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
				<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">_x</span> <span style="color: #66cc66;">&lt;</span>= <span style="color: #0066CC;">_root</span>.<span style="color: #006600;">mcMain</span>.<span style="color: #0066CC;">_x</span>+<span style="color: #cc66cc;">30</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">_x</span> <span style="color: #66cc66;">&gt;</span>= <span style="color: #0066CC;">_root</span>.<span style="color: #006600;">mcMain</span>.<span style="color: #0066CC;">_x</span> -<span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
					<span style="color: #808080; font-style: italic;">//we'll add code here in the next part</span>
					<span style="color: #808080; font-style: italic;">//but for now, we'll just trace something</span>
					<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'You got hit!'</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #66cc66;">&#125;</span>
			<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Well, that&#8217;s all for today. Join us next time when we score the game!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashgametuts.com/tutorials/as2/how-to-make-a-vertical-shooter-in-as2-part-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
