{"id":1046,"date":"2009-01-03T08:05:40","date_gmt":"2009-01-03T12:05:40","guid":{"rendered":"http:\/\/www.mrsunstudios.com\/?p=1046"},"modified":"2022-05-29T08:23:32","modified_gmt":"2022-05-29T12:23:32","slug":"tutorial-create-a-platform-game-in-as2-part-6-2","status":"publish","type":"post","link":"http:\/\/www.mrsunstudios.com\/blog\/flash\/tutorial-create-a-platform-game-in-as2-part-6-2\/","title":{"rendered":"Tutorial: Create a Platform Game in AS2 &#8211; Part 6"},"content":{"rendered":"<div class=\"toc\">\n<h3 id=\"1020_table-of-contents_1\" >Table of Contents<\/h3>\n<ol>\n<li><a href=\"http:\/\/www.mrsunstudios.com\/2009\/01\/tutorial-create-a-platform-game-in-as2\">Basic Character Programming<\/a><\/li>\n<li><a href=\"http:\/\/www.mrsunstudios.com\/2009\/01\/tutorial-create-a-platform-game-in-as2-part-2\">Creating The Level<\/a><\/li>\n<li><a href=\"http:\/\/www.mrsunstudios.com\/2009\/01\/tutorial-create-a-platform-game-in-as2-part-3\">Programming the Level<\/a><\/li>\n<li><a href=\"http:\/\/www.mrsunstudios.com\/2009\/01\/tutorial-create-a-platform-game-in-as2-part-4\">Adding Level Elements<\/a><\/li>\n<li><a href=\"http:\/\/www.mrsunstudios.com\/2009\/01\/tutorial-create-a-platform-game-in-as2-part-5\">Adding Enemies<\/a><\/li>\n<li class=\"c_chap\"><a href=\"http:\/\/www.mrsunstudios.com\/2009\/01\/tutorial-create-a-platform-game-in-as2-part-6\">Goals and Level Completion<\/a><\/li>\n<li><a href=\"http:\/\/www.mrsunstudios.com\/2009\/01\/tutorial-create-a-platform-game-in-as2-part-7\">Finishing Touches<\/a><\/li>\n<\/ol>\n<\/div>\n<h3 id=\"1046_step-6-goals-and-lev_1\" >Step 6: Goals and Level Completion<\/h3>\n<p>Ok, now that we&#8217;ve added level components and enemies, we can finally make it possible to complete a level. In our game, we&#8217;re simply going to make an object that the player has to touch in order to get to the next level. We&#8217;re also going to add some coins that will rack up points along the way. The first thing we&#8217;re going to do for this is to add a score variable:<\/p>\n<pre lang=\"actionscript\">\r\n\/\/SCORING VARIABLES\r\nvar mainScore:Number = 0;\r\n<\/pre>\n<p>Next, we&#8217;re going to add coins. We&#8217;ll do this just like we added the level elements. Because we don&#8217;t need <tt>main<\/tt> to run checks on them, we don&#8217;t need to create a separated holder for them. First, we have to create a <tt>mcCoin<\/tt> MovieClip. Mine is going to be a 5&#215;5 white circle. Just export it for ActionScript like usual with that name.<\/p>\n<p>Now, add this code to the <tt>createLvl()<\/tt> function:<\/p>\n<pre lang=\"actionscript\">\r\nif (lvlArray[i] == 7){\r\n\tlvlHolder.attachMovie('mcCoin', 'Coin'+i, lvlHolder.getNextHighestDepth());\r\n\tlvlHolder['Coin'+i]._x = (i-(row-1)*lvlColumns)*25;\r\n\tlvlHolder['Coin'+i]._y = (row-1)*25;\r\n\tlvlHolder['Coin'+i].onEnterFrame = function(){\r\n\t\tif(this.hitTest(_root.mcMain)){\r\n\t\t\tmainScore += 100;\/\/increase the score\r\n\t\t\tthis.removeMovieClip();\/\/and destroy this\r\n\t\t\ttrace(mainScore);\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p>The next thing to do is update the score whenever we kill an enemy. I hope you can do this on your own. I&#8217;m guessing that 500 points is a fair value for slaying an enemy. Now, we can add a goal object. I&#8217;m going to make mine turquoise, simply because it&#8217;s a cool color. Make that MovieClip called &#8220;<tt>mcGoal<\/tt>&#8221; and add the following code to the <tt>createLvl()<\/tt> function:<\/p>\n<pre lang=\"actionscript\">\r\nif (lvlArray[i] == 8){\r\n\tlvlHolder.attachMovie('mcGoal', 'Goal'+i, lvlHolder.getNextHighestDepth());\r\n\tlvlHolder['Goal'+i]._x = (i-(row-1)*lvlColumns)*25;\r\n\tlvlHolder['Goal'+i]._y = (row-1)*25;\r\n\tlvlHolder['Goal'+i].onEnterFrame = function(){\r\n\t\tif(this.hitTest(_root.mcMain)){\r\n\t\t\/\/go to the next lvl\r\n\t\t\t_root.lvlCur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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\r\n\t0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\r\n\t0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\r\n);\r\n<\/pre>\n<p>Well, that&#8217;s it for goals and level completion. Next time, we&#8217;ll fix some bugs and add some finishing touches!<\/p>\n<h4 id=\"1046_the-final-product_1\" >The Final Product<\/h4>\n<p><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"550\" 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\/platform-as2\/pt6\/source.swf\" \/><embed type=\"application\/x-shockwave-flash\" width=\"550\" height=\"400\" src=\"http:\/\/mrsunstudios.com\/obj\/tuts\/platform-as2\/pt6\/source.swf\"><\/embed><\/object><\/p>\n<p><a href=\"http:\/\/www.mrsunstudios.com\/obj\/tuts\/platform-as2\/pt6\/source.fla\">Source .fla File<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Table of Contents Basic Character Programming Creating The Level Programming the Level Adding Level Elements Adding Enemies Goals and Level Completion Finishing Touches Step 6: Goals and Level Completion Ok, now that we&#8217;ve added level components and enemies, we can finally make it possible to complete a level. In our game, we&#8217;re simply 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":[160,5,7,4,6],"tags":[25,160,7,162,19,18,161,22,11],"_links":{"self":[{"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/posts\/1046"}],"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=1046"}],"version-history":[{"count":5,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/posts\/1046\/revisions"}],"predecessor-version":[{"id":1406,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/posts\/1046\/revisions\/1406"}],"wp:attachment":[{"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/media?parent=1046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/categories?post=1046"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/tags?post=1046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}