{"id":1075,"date":"2009-01-17T08:01:28","date_gmt":"2009-01-17T12:01:28","guid":{"rendered":"http:\/\/www.mrsunstudios.com\/?p=1075"},"modified":"2022-05-29T08:23:31","modified_gmt":"2022-05-29T12:23:31","slug":"tutorial-make-a-vertical-shooter-in-as2","status":"publish","type":"post","link":"http:\/\/www.mrsunstudios.com\/blog\/flash\/tutorial-make-a-vertical-shooter-in-as2\/","title":{"rendered":"Tutorial: Make a Vertical Shooter in AS2"},"content":{"rendered":"<div class=\"toc\">\n<h3>Table of Contents<\/h3>\n<ol>\n<li class=\"c_chap\"><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><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 1: Programming the Character<\/h3>\n<p>Today, we&#8217;re going to make a classic vertical shooter game in ActionScript 2. I hope you learn from it! Let us begin.<\/p>\n<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 more narrow. My new dimensions are at 300&#215;400 pixels.<\/p>\n<p>Next, we&#8217;re going to draw a character. Mine will be simple, just a triangle pointing upwards.<br \/>\n<img src=\"http:\/\/mrsunstudios.com\/obj\/tuts\/vert-shooter-as3\/pt1\/character.gif\" alt=\"My character\" \/><br \/>\nThe dimensions for it are 30&#215;35 pixels.<\/p>\n<p>Then, we&#8217;re going to turn it into a symbol. After that, we&#8217;re going to give it an instance name of <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>\n<pre lang=\"actionscript\">\r\nvar mainSpeed:Number = 5;\/\/how fast the main guy can move\r\n\r\nonEnterFrame = function(){ \/\/this function will run every frame (needed for moving the character\r\n\tif(Key.isDown(37) || Key.isDown(65)){ \/\/if the \"A\" key or Left Arrow Key is Down\r\n\t\tmcMain._x -= mainSpeed;\/\/then the move the guy left\r\n\t}\r\n\tif (Key.isDown(38) || Key.isDown(87)){\/\/if the \"W\" key or Up Arrow Key is Down\r\n\t\tmcMain._y -= mainSpeed; \/\/then move the guy up\r\n\t}\r\n\tif(Key.isDown(39) || Key.isDown(68)){\/\/if the \"D\" key or Right Arrow Key is Down\r\n\t\tmcMain._x += mainSpeed; \/\/then move the guy to the right\r\n\t}\r\n\tif(Key.isDown(40) || Key.isDown(83)){\/\/if the \"S\" key or Down Arrow Key is Down\r\n\t\tmcMain._y += mainSpeed; \/\/then move the guy down\r\n\t}\r\n\r\n\t\/\/keeping the main character within bounds\r\n\tif(mcMain._x <= 0){\r\n\t\tmcMain._x += mainSpeed;\r\n\t}\r\n\tif(mcMain._y <= 0){\r\n\t\tmcMain._y += mainSpeed;\r\n\t}\r\n\tif(mcMain._x >= Stage.width - mcMain._width){\r\n\t\tmcMain._x -= mainSpeed;\r\n\t}\r\n\tif(mcMain._y >= Stage.height - mcMain._height){\r\n\t\tmcMain._y -= mainSpeed;\r\n\t}\r\n}\r\n<\/pre>\n<p>This is actually all we need for this chapter. Pretty easy, right? Next time, we&#8217;ll make him shoot!<\/p>\n<h4>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\/pt1\/source.swf\" \/><embed type=\"application\/x-shockwave-flash\" width=\"300\" height=\"400\" src=\"http:\/\/mrsunstudios.com\/obj\/tuts\/vert-shooter-as2\/pt1\/source.swf\"><\/embed><\/object><\/p>\n<p><a href=\"http:\/\/mrsunstudios.com\/obj\/tuts\/vert-shooter-as2\/pt1\/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 1: Programming the Character Today, we&#8217;re going to make a classic vertical shooter game in ActionScript 2. I hope you learn from it! Let us begin. The first thing that I&#8217;m going to [&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\/1075"}],"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=1075"}],"version-history":[{"count":6,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/posts\/1075\/revisions"}],"predecessor-version":[{"id":1203,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/posts\/1075\/revisions\/1203"}],"wp:attachment":[{"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/media?parent=1075"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/categories?post=1075"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/tags?post=1075"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}