{"id":642,"date":"2008-08-23T08:05:45","date_gmt":"2008-08-23T12:05:45","guid":{"rendered":"http:\/\/www.mrsunstudios.com\/?p=642"},"modified":"2022-05-29T08:23:36","modified_gmt":"2022-05-29T12:23:36","slug":"tutorial-make-a-vertical-shooter-in-as3-part-6","status":"publish","type":"post","link":"http:\/\/www.mrsunstudios.com\/blog\/flash\/tutorial-make-a-vertical-shooter-in-as3-part-6\/","title":{"rendered":"Tutorial: Make a Vertical Shooter in AS3 &#8211; Part 6"},"content":{"rendered":"<div class=\"toc\">\n<h3>Table of Contents<\/h3>\n<ol>\n<li><a href=\"http:\/\/www.mrsunstudios.com\/2008\/08\/tutorial-make-a-vertical-shooter-in-as3\">Programming the Character<\/a><\/li>\n<li><a href=\"http:\/\/www.mrsunstudios.com\/2008\/08\/tutorial-make-a-vertical-shooter-in-as3-part-2\">Programming the Character &#8211; Part 2<\/a><\/li>\n<li><a href=\"http:\/\/www.mrsunstudios.com\/2008\/08\/tutorial-make-a-vertical-shooter-in-as3-part-3\">Creating the Enemies<\/a><\/li>\n<li><a href=\"http:\/\/www.mrsunstudios.com\/2008\/08\/tutorial-make-a-vertical-shooter-in-as3-part-4\">Programming the Enemies<\/a><\/li>\n<li><a href=\"http:\/\/www.mrsunstudios.com\/2008\/08\/tutorial-make-a-vertical-shooter-in-as3-part-5\">Scoring<\/a><\/li>\n<li class=\"c_chap\"><a href=\"http:\/\/www.mrsunstudios.com\/2008\/08\/tutorial-make-a-vertical-shooter-in-as3-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. Here&#8217;s the code to place at the bottom:<\/p>\n<pre lang=\"actionscript\">\r\n\/\/adding another enterframe listener for the particles\r\nstage.addEventListener(Event.ENTER_FRAME, generateParticles);\r\n\r\n\/\/checking if there already is another particlecontainer there\r\nif(particleContainer == null){\r\n\t\/\/this movieclip will hold all of the particles\r\n\tvar particleContainer:MovieClip = new MovieClip();\r\n\taddChild(particleContainer);\r\n}\r\n\r\nfunction generateParticles(event:Event):void{\r\n\t\/\/so we don't do it every frame, we'll do it randomly\r\n\tif(Math.random()*10 < 2){\r\n\t\t\/\/creating a new shape\r\n\t\tvar mcParticle:Shape = new Shape(); \r\n\t\t\/\/making random dimensions (only ranges from 1-5 px)\r\n\t\tvar dimensions:int = int(Math.random()*5)+1;\r\n\t\t\/\/add color to the shape\r\n\t\tmcParticle.graphics.beginFill(0x999999\/*The color for shape*\/,1\/*The alpha for the shape*\/);\r\n\t\t\/\/turning the shape into a square\r\n\t\tmcParticle.graphics.drawRect(dimensions,dimensions,dimensions,dimensions);\r\n\t\t\/\/change the coordinates of the particle\r\n\t\tmcParticle.x = int(Math.random()*stage.stageWidth);\r\n\t\tmcParticle.y = -10;\r\n\t\t\/\/adding the particle to stage\r\n\t\tparticleContainer.addChild(mcParticle);\r\n\t}\r\n\t\r\n\t\/\/making all of the particles move down stage\r\n\tfor(var i:int=0;i<particleContainer.numChildren;i++){\r\n\t\t\/\/getting a certain particle\r\n\t\tvar theParticle:Object = particleContainer.getChildAt(i);\r\n\t\t\/\/it'll go half the speed of the character\r\n\t\ttheParticle.y += mainSpeed*.5;\r\n\t\t\/\/checking if the particle is offstage\r\n\t\tif(theParticle.y >= 400){\r\n\t\t\t\/\/remove it\r\n\t\t\tparticleContainer.removeChild(theParticle);\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<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>\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-as3\/pt6\/source.swf\" \/><embed type=\"application\/x-shockwave-flash\" width=\"300\" height=\"400\" src=\"http:\/\/mrsunstudios.com\/obj\/tuts\/vert-shooter-as3\/pt6\/source.swf\"><\/embed><\/object><\/p>\n<p><a href=\"http:\/\/mrsunstudios.com\/obj\/tuts\/vert-shooter-as3\/pt6\/source.zip\">Source Files (zipped)<\/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,8,4,6,68],"tags":[25,8,19,18,68,152,22,150,151,11,149],"_links":{"self":[{"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/posts\/642"}],"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=642"}],"version-history":[{"count":5,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/posts\/642\/revisions"}],"predecessor-version":[{"id":655,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/posts\/642\/revisions\/655"}],"wp:attachment":[{"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/media?parent=642"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/categories?post=642"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/tags?post=642"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}