{"id":1148,"date":"2009-01-17T08:06:47","date_gmt":"2009-01-17T12:06:47","guid":{"rendered":"http:\/\/www.mrsunstudios.com\/?p=1148"},"modified":"2022-05-29T08:23:30","modified_gmt":"2022-05-29T12:23:30","slug":"tutorial-make-a-vertical-shooter-in-as2-part-6","status":"publish","type":"post","link":"http:\/\/www.mrsunstudios.com\/blog\/flash\/tutorial-make-a-vertical-shooter-in-as2-part-6\/","title":{"rendered":"Tutorial: Make a Vertical Shooter in AS2 &#8211; Part 6"},"content":{"rendered":"<div class=\"toc\">\n<h3>Table of Contents<\/h3>\n<ol>\n<li><a href=\"http:\/\/www.mrsunstudios.com\/2009\/01\/tutorial-make-a-vertical-shooter-in-as2\">Programming the Character<\/a><\/li>\n<li><a href=\"http:\/\/www.mrsunstudios.com\/2009\/01\/tutorial-make-a-vertical-shooter-in-as2-part-2\">Programming the Character &#8211; Part 2<\/a><\/li>\n<li><a href=\"http:\/\/www.mrsunstudios.com\/2009\/01\/tutorial-make-a-vertical-shooter-in-as2-part-3\">Creating the Enemies<\/a><\/li>\n<li><a href=\"http:\/\/www.mrsunstudios.com\/2009\/01\/tutorial-make-a-vertical-shooter-in-as2-part-4\">Programming the Enemies<\/a><\/li>\n<li><a href=\"http:\/\/www.mrsunstudios.com\/2009\/01\/tutorial-make-a-vertical-shooter-in-as2-part-5\">Scoring<\/a><\/li>\n<li class=\"c_chap\"><a href=\"http:\/\/www.mrsunstudios.com\/2009\/01\/tutorial-make-a-vertical-shooter-in-as2-part-6\">Finishing Touches<\/a><\/li>\n<\/ol>\n<\/div>\n<h3>Step 6: Finishing Touches<\/h3>\n<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>\n<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>\n<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>\n<pre lang=\"actionscript\">\r\n\/\/creating background particles\r\nbgHolder.createEmptyMovieClip(\"bg\"+totalBgShapes, bgHolder.getNextHighestDepth());\r\nbgHolder[\"bg\"+totalBgShapes].beginFill(0x333333); \/\/this just determines the shape's color\r\nbgHolder[\"bg\"+totalBgShapes]._x = int(Math.random()*550);\r\ngHolder[\"bg\"+totalBgShapes]._y = -50 - bgHolder._y;\r\n\/\/creating 4 random points to make a random shape\r\nbgHolder[\"bg\"+totalBgShapes].lineTo(int(Math.random()*25), int(Math.random()*25));\r\nbgHolder[\"bg\"+totalBgShapes].lineTo(int(Math.random()*25), int(Math.random()*25));\r\nbgHolder[\"bg\"+totalBgShapes].lineTo(int(Math.random()*25), int(Math.random()*25));\r\nbgHolder[\"bg\"+totalBgShapes].lineTo(int(Math.random()*25), int(Math.random()*25));\r\nbgHolder[\"bg\"+totalBgShapes].endFill();\/\/finishes up the shape\r\n\t\r\nbgHolder[\"bg\"+totalBgShapes].onEnterFrame = function(){\/\/giving it some actions\r\n\tif(this._y > 450 - bgHolder._y || _root.gameOver){\/\/if it goes off the stage or game is over\r\n\t\t\/\/then destroy it\r\n\t\tthis.removeMovieClip();\r\n\t}\r\n}\r\n\t\r\ntotalBgShapes ++;\r\nbgHolder._y += 2;\r\n<\/pre>\n<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>\n<pre lang=\"actionscript\">\r\nmcMain.swapDepths(1000);\r\n<\/pre>\n<p>Also, remove <tt>mcMain<\/tt> when <tt>gameOver<\/tt> is true or else strange things will happen.<\/p>\n<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>\n<p>Well, that&#8217;s actually all that I really have to finish off the game. I hope you had fun making it!<\/p>\n<h4>The Final Product:<\/h4>\n<p><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"300\" height=\"400\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=6,0,40,0\"><param name=\"src\" value=\"http:\/\/mrsunstudios.com\/obj\/tuts\/vert-shooter-as2\/pt6\/source.swf\" \/><embed type=\"application\/x-shockwave-flash\" width=\"300\" height=\"400\" src=\"http:\/\/mrsunstudios.com\/obj\/tuts\/vert-shooter-as2\/pt6\/source.swf\"><\/embed><\/object><\/p>\n<p><a href=\"http:\/\/mrsunstudios.com\/obj\/tuts\/vert-shooter-as2\/pt6\/source.fla\">Source .fla File<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Table of Contents Programming the Character Programming the Character &#8211; Part 2 Creating the Enemies Programming the Enemies Scoring Finishing Touches Step 6: Finishing Touches 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, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,7,4,6,68],"tags":[25,7,19,18,68,152,22,150,151,11,149],"_links":{"self":[{"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/posts\/1148"}],"collection":[{"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/comments?post=1148"}],"version-history":[{"count":2,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/posts\/1148\/revisions"}],"predecessor-version":[{"id":1209,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/posts\/1148\/revisions\/1209"}],"wp:attachment":[{"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/media?parent=1148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/categories?post=1148"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/tags?post=1148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}