{"id":1123,"date":"2009-01-17T08:03:23","date_gmt":"2009-01-17T12:03:23","guid":{"rendered":"http:\/\/www.mrsunstudios.com\/?p=1123"},"modified":"2022-05-29T08:23:30","modified_gmt":"2022-05-29T12:23:30","slug":"tutorial-make-a-vertical-shooter-in-as2-part-3","status":"publish","type":"post","link":"http:\/\/www.mrsunstudios.com\/blog\/flash\/tutorial-make-a-vertical-shooter-in-as2-part-3\/","title":{"rendered":"Tutorial: Make a Vertical Shooter in AS2 &#8211; Part 3"},"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 class=\"c_chap\"><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><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 3: Creating the Enemies<\/h3>\n<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 \/>\n<img src=\"http:\/\/mrsunstudios.com\/obj\/tuts\/vert-shooter-as2\/pt3\/enemy.gif\" alt=\"My enemy\" \/><br \/>\nIts dimensions are 30&#215;30 if you wanted to know.<\/p>\n<p>Now, do the same thing we did for the bullet, convert it to a MovieClip, and Export it for ActionScript.<\/p>\n<p>Next, we&#8217;ll do something similar to what we did with the bullet. We&#8217;re going to add two timing variables again at the top of the code:<\/p>\n<pre lang=\"actionscript\">\r\n\/\/ENEMY TIMING VARIABLES\r\n\/\/how much time before another enemy is made\r\nvar enemyTime:Number = 0;\r\n\/\/how much time needed to make an enemy\r\n\/\/it should be more than the shooting rate\r\n\/\/or else killing all of the enemies would\r\n\/\/be impossible :O\r\nvar enemyLimit:Number = 16;\r\n<\/pre>\n<p>Now, in order to add this enemy to the stage, we have to program this into the <tt>onEnterFrame<\/tt> function:<\/p>\n<pre lang=\"actionscript\">\r\n\tenemyTime ++;\/\/incrementing time for enemy\r\n\tif(enemyTime == enemyLimit){\/\/if enough time has elapsed\r\n\t\tvar enID:Number = Math.random(); \/\/create a variable that we'll use at the enemy's id\r\n\t\t_root.attachMovie('mcEnemy', 'en'+enID,_root.getNextHighestDepth());\/\/then add the enemy\r\n\t\t\/\/setting it's coordinates\r\n\t\t_root['en'+enID]._x = int(Math.random()*Stage.width);\/\/randomly within the boundaries\r\n\t\t_root['en'+enID]._y = -50; \/\/sets this offstage at first\r\n\t\t_root['en'+enID].onEnterFrame = function(){\/\/then give it some functions\r\n\t\t\tthis._y += 5;\r\n\t\t}\r\n\t\tenemyTime = 0;\/\/reset the time\r\n\t}\r\n<\/pre>\n<p>This concludes this part of the tutorial. Next time, we&#8217;ll program the enemies so they get shot!<\/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\/pt3\/source.swf\" \/><embed type=\"application\/x-shockwave-flash\" width=\"300\" height=\"400\" src=\"http:\/\/mrsunstudios.com\/obj\/tuts\/vert-shooter-as2\/pt3\/source.swf\"><\/embed><\/object><\/p>\n<p><a href=\"http:\/\/mrsunstudios.com\/obj\/tuts\/vert-shooter-as2\/pt3\/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 3: Creating the Enemies 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 [&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\/1123"}],"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=1123"}],"version-history":[{"count":7,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/posts\/1123\/revisions"}],"predecessor-version":[{"id":1529,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/posts\/1123\/revisions\/1529"}],"wp:attachment":[{"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/media?parent=1123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/categories?post=1123"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/tags?post=1123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}