{"id":1254,"date":"2009-01-01T08:05:12","date_gmt":"2009-01-01T12:05:12","guid":{"rendered":"http:\/\/www.mrsunstudios.com\/?p=1254"},"modified":"2022-05-29T08:23:33","modified_gmt":"2022-05-29T12:23:33","slug":"tutorial-create-a-game-like-winter-bells-in-as2-part-5","status":"publish","type":"post","link":"http:\/\/www.mrsunstudios.com\/blog\/flash\/tutorial-create-a-game-like-winter-bells-in-as2-part-5\/","title":{"rendered":"Tutorial: Create a Game Like Winter Bells in AS2 &#8211; Part 5"},"content":{"rendered":"<div class=\"toc\">\n<ol>\n<li><a href=\"http:\/\/mrsunstudios.com\/2009\/01\/tutorial-create-a-game-like-winter-bells-in-as2\/\">Basic Character Programming<\/a><\/li>\n<li><a href=\"http:\/\/mrsunstudios.com\/2009\/01\/tutorial-create-a-game-like-winter-bells-in-as2-part-2\/\">Programming the &#8220;Bells&#8221;<\/a><\/li>\n<li><a href=\"http:\/\/mrsunstudios.com\/2009\/01\/tutorial-create-a-game-like-winter-bells-in-as2-part-3\/\">Level Creation<\/a><\/li>\n<li><a href=\"http:\/\/mrsunstudios.com\/2009\/01\/tutorial-create-a-game-like-winter-bells-in-as2-part-4\/\">Scoring<\/a><\/li>\n<li class=\"c_chap\"><a href=\"http:\/\/mrsunstudios.com\/2009\/01\/tutorial-create-a-game-like-winter-bells-in-as2-part-5\/\">Finishing Touches<\/a><\/li>\n<\/ol>\n<\/div>\n<h3>Step 5: Finishing Touches<\/h3>\n<p>This part of tutorial is where we add some bug fixes and special effects. Let&#8217;s get started.<\/p>\n<p>The first bug fix that we have to make is one related to jumping. I probably should have noticed this beforehand but with our current code, you can continue clicking and jumping even while you&#8217;re in the air. This is definitely not what we want. Fortunately, this is easy to fix. Just take the <tt>mcBg<\/tt>&#8216;s <tt>onRelease<\/tt> function and change it to this:<\/p>\n<pre lang=\"actionscript\">\nmcBg.onRelease = function(){\/\/if the user clicks\n\tif(!mainJumping){\n\t\tmainJumping = true;\/\/then we can start jumping\n\t\tjumpSpeed = jumpSpeedLimit*-1;\/\/change the jumpSpeed so that we can begin jumping\n\t}\n}\n<\/pre>\n<p>The next bug we need to fix occurs after the <tt>mcFinalStats<\/tt> is shown on the screen. Whenever you click anywhere, <tt>mcMain<\/tt> can still jump. When it lands, another <tt>mcFinalStats<\/tt> is created. We can fix this no problem. Add an <tt>&& !gameOver<\/tt> to the if statement in the <tt>mcBg<\/tt>&#8216;s click function. That&#8217;s all we need.<\/p>\n<p>The next thing we need to fix really isn&#8217;t a bug. In my opinion, <tt>mcMain<\/tt> doesn&#8217;t jump high enough. Simply make him jump just a little bit higher by changing the <tt>mainJump()<\/tt> function to this:<\/p>\n<pre lang=\"actionscript\">\nfunction mainJump():Void{\n\tif(mainJumping) {\/\/if jumping has been initiated\n\t\tif(jumpSpeed < 0){\/\/if the guy is still going up\n\t\t\tjumpSpeed *= 1 - jumpSpeedLimit\/133;\/\/decrease jumpSpeed slightly\n\t\t\tif(jumpSpeed > -jumpSpeedLimit*.1){\/\/if jumpSpeed is small enough\n\t\t\t\tjumpSpeed *= -1;\/\/then begin to go down\n\t\t\t}\n\t\t}\n\t\tif(jumpSpeed > 0 && jumpSpeed <= jumpSpeedLimit){\/\/if main is going down\n\t\t\tjumpSpeed *= 1 + jumpSpeedLimit\/133;\/\/incrase the falling speed\n\t\t}\n\t\tmcMain._y += jumpSpeed;\/\/finally, apply jumpSpeed to mcMain\n\t\t\/\/if main hits the floor, then stop jumping\n\t\tif(mcMain._y >= Stage.height - mcMain._height && totalHeight <= 0){\n\t\t\tmainJumping = false;\n\t\t\tmcMain._y = 387.5;\n\t\t\tif(startedJumping){\/\/if the main has begun jumping\n\t\t\t\tgameOver = true;\/\/then finish the game\n\t\t\t\tshowFinalStats();\/\/and show the poor kid their stats\n\t\t\t}\n\t\t}\n\t\t\n\t\ttotalHeight -= jumpSpeed;\/\/add to the total height (jumpSpeed will be negative)\n\t}\n\tif(mcMain._y > 387.5){\n\t\tmcMain._y = 387.5;\n\t}\n}\n<\/pre>\n<p>I just changed the two 120&#8217;s to 133&#8217;s. That&#8217;ll make jumping a bit better.<\/p>\n<p>Now, we can add some special effects. The first one, of course, is going to be a background. First, define a variable called <tt>totalBgShapes<\/tt> at the top and set it to 0. Then, add this code to the main <tt>onEnterFrame()<\/tt> function:<\/p>\n<pre lang=\"actionscript\">\n\/\/creating background particles\nbellHolder.createEmptyMovieClip(\"bg\"+totalBgShapes, bellHolder.getNextHighestDepth());\nbellHolder[\"bg\"+totalBgShapes].beginFill(0x333333); \/\/this just determines the shape's color\nbellHolder[\"bg\"+totalBgShapes]._x = int(Math.random()*550);\nbellHolder[\"bg\"+totalBgShapes]._y = bellTop;\n\/\/creating 4 random points to make a random shape\nbellHolder[\"bg\"+totalBgShapes].lineTo(int(Math.random()*5), int(Math.random()*5));\nbellHolder[\"bg\"+totalBgShapes].lineTo(int(Math.random()*5), int(Math.random()*5));\nbellHolder[\"bg\"+totalBgShapes].lineTo(int(Math.random()*5), int(Math.random()*5));\nellHolder[\"bg\"+totalBgShapes].lineTo(int(Math.random()*5), int(Math.random()*5));\nbellHolder[\"bg\"+totalBgShapes].endFill();\/\/finishes up the shape\n\nbellHolder[\"bg\"+totalBgShapes].onEnterFrame = function(){\/\/giving it some actions\n\tthis._y += 2;\n}\n\t\ntotalBgShapes ++;\n<\/pre>\n<p>Now, we notice that the background is actually in front of the main character. Do not fret, simply add this code to the bottom of everything:<\/p>\n<pre lang=\"actionscript\">\nmcMain.swapDepths(10);\/\/making it in front of everyone\n<\/pre>\n<p>Well, I guess that pretty much finished up everything. I hoped you learned much from my tutorial!<\/p>\n<h4>The Final Product<\/h4>\n<p><center><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\/winter-bells-as2\/pt5\/source.swf\" \/><embed type=\"application\/x-shockwave-flash\" width=\"550\" height=\"400\" src=\"http:\/\/mrsunstudios.com\/obj\/tuts\/winter-bells-as2\/pt5\/source.swf\"><\/embed><\/object><\/p>\n<p><a href=\"http:\/\/mrsunstudios.com\/obj\/tuts\/winter-bells-as2\/pt5\/source.fla\">Source .fla File<\/a><\/center><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Basic Character Programming Programming the &#8220;Bells&#8221; Level Creation Scoring Finishing Touches Step 5: Finishing Touches This part of tutorial is where we add some bug fixes and special effects. Let&#8217;s get started. The first bug fix that we have to make is one related to jumping. I probably should have noticed this beforehand but with [&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":[7,233,235,18,68,234,236,11,232],"_links":{"self":[{"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/posts\/1254"}],"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=1254"}],"version-history":[{"count":2,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/posts\/1254\/revisions"}],"predecessor-version":[{"id":1291,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/posts\/1254\/revisions\/1291"}],"wp:attachment":[{"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/media?parent=1254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/categories?post=1254"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/tags?post=1254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}