{"id":1241,"date":"2009-01-01T08:03:44","date_gmt":"2009-01-01T12:03:44","guid":{"rendered":"http:\/\/www.mrsunstudios.com\/?p=1241"},"modified":"2022-05-29T08:23:33","modified_gmt":"2022-05-29T12:23:33","slug":"tutorial-create-a-game-like-winter-bells-in-as2-part-3","status":"publish","type":"post","link":"http:\/\/www.mrsunstudios.com\/blog\/flash\/tutorial-create-a-game-like-winter-bells-in-as2-part-3\/","title":{"rendered":"Tutorial: Create a Game Like Winter Bells in AS2 &#8211; Part 3"},"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 class=\"c_chap\"><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><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 3: Level Creation<\/h3>\n<p>Welcome to the third part of this tutorial. In this part, we&#8217;re going to create the entire thing into a functional level. The first thing we&#8217;re going to do is make the screen move along with the character, so it can actually move up the levels. Define this function at the end of your code:<\/p>\n<pre lang=\"actionscript\">\r\nfunction moveScreen():Void{ \/\/function that moves the screen up and down\r\n\tif(mcMain._y <= 125){\/\/if main gets up high enough\r\n\t\tmcMain._y = 125;\/\/don't let him jump any higher\r\n\t\tbellHolder._y -= jumpSpeed;\/\/instead, move the entire level down\r\n\t\tbellTop += jumpSpeed;\/\/we also have to move the creation point for new bells\r\n\t\tbellLimit = 6;\/\/make the bells appear quicker since we're moving up quicker\r\n\t} else {\r\n\t\tbellLimit = 20;\/\/change it back if we're done\r\n\t}\r\n}\r\n<\/pre>\n<p>Now, run it in the main <tt>onEnterFrame()<\/tt> function. Right now, all this code will do is make the level go upwards for the main character, but not back down. In order to accomplish this feat, we have to define some variables at the top:<\/p>\n<pre lang=\"actionscript\">\r\nvar totalHeight:Number = 0; \/\/how far up the main guy has travelled\r\nvar startedJumping:Boolean = false;\/\/whether or not main has actually hit a bell yet\r\n<\/pre>\n<p>Now, we're going to have to add and subtract to the <tt>totalHeight<\/tt> whenever the character jumps and falls. This is actually easier than it seems. All we have to do is add <tt>totalHeight -= jumpSpeed;<\/tt> to the <tt>mainJump()<\/tt> function. Not too bad, eh? Now, add this code to the <tt>moveScreen()<\/tt> function:<\/p>\n<pre lang=\"actionscript\">\r\nif(mcMain._y >= 275 && totalHeight >= 275){ \/\/if mcMain is above a certain point and the screen has been moved up\r\n\tbellHolder._y -= jumpSpeed;\/\/make bellHolder go back down\r\n\tbellTop += jumpSpeed;\/\/as well as the creation point\r\n\tmcMain._y = 275;\/\/keep mcMain's y stationary until it is done falling\r\n}\r\n<\/pre>\n<p>Now, the game should work out pretty fine. We're actually pretty much done with this portion of the tutorial. Please, do join us next time when we add some scoring factors to this lil' game of ours.<\/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\/pt3\/source.swf\" \/><embed type=\"application\/x-shockwave-flash\" width=\"550\" height=\"400\" src=\"http:\/\/mrsunstudios.com\/obj\/tuts\/winter-bells-as2\/pt3\/source.swf\"><\/embed><\/object><\/p>\n<p><a href=\"http:\/\/mrsunstudios.com\/obj\/tuts\/winter-bells-as2\/pt3\/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 3: Level Creation Welcome to the third part of this tutorial. In this part, we&#8217;re going to create the entire thing into a functional level. The first thing we&#8217;re going to do is make the screen move along with the character, so it [&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\/1241"}],"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=1241"}],"version-history":[{"count":3,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/posts\/1241\/revisions"}],"predecessor-version":[{"id":1289,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/posts\/1241\/revisions\/1289"}],"wp:attachment":[{"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/media?parent=1241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/categories?post=1241"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.mrsunstudios.com\/blog\/wp-json\/wp\/v2\/tags?post=1241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}