How to Create a Game Like Winter Bells in AS2 – Part 3

Part 3: Level Creation

Welcome to the third part of this tutorial. In this part, we’re going to create the entire thing into a functional level. The first thing we’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:

function moveScreen():Void{ //function that moves the screen up and down
	if(mcMain._y <= 125){//if main gets up high enough
		mcMain._y = 125;//don't let him jump any higher
		bellHolder._y -= jumpSpeed;//instead, move the entire level down
		bellTop += jumpSpeed;//we also have to move the creation point for new bells
		bellLimit = 6;//make the bells appear quicker since we're moving up quicker
	} else {
		bellLimit = 20;//change it back if we're done
	}
}

Now, run it in the main onEnterFrame() 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:

var totalHeight:Number = 0; //how far up the main guy has travelled
var startedJumping:Boolean = false;//whether or not main has actually hit a bell yet

Now, we're going to have to add and subtract to the totalHeight whenever the character jumps and falls. This is actually easier than it seems. All we have to do is add totalHeight -= jumpSpeed; to the mainJump() function. Not too bad, eh? Now, add this code to the moveScreen() function:

if(mcMain._y >= 275 && totalHeight >= 275){ //if mcMain is above a certain point and the screen has been moved up
	bellHolder._y -= jumpSpeed;//make bellHolder go back down
	bellTop += jumpSpeed;//as well as the creation point
	mcMain._y = 275;//keep mcMain's y stationary until it is done falling
}

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.

Preview

Download Source
(Requires Flash 8 or above)

Subscribe!

Subscribe!
Enter your email address:  

Awesome Tutorials