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

Part 5: Finishing Touches

This part of tutorial is where we add some bug fixes and special effects. Let’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 our current code, you can continue clicking and jumping even while you’re in the air. This is definitely not what we want. Fortunately, this is easy to fix. Just take the mcBg‘s onRelease function and change it to this:

mcBg.onRelease = function(){//if the user clicks
	if(!mainJumping){
		mainJumping = true;//then we can start jumping
		jumpSpeed = jumpSpeedLimit*-1;//change the jumpSpeed so that we can begin jumping
	}
}

The next bug we need to fix occurs after the mcFinalStats is shown on the screen. Whenever you click anywhere, mcMain can still jump. When it lands, another mcFinalStats is created. We can fix this no problem. Add an && !gameOver to the if statement in the mcBg‘s click function. That’s all we need.

The next thing we need to fix really isn’t a bug. In my opinion, mcMain doesn’t jump high enough. Simply make him jump just a little bit higher by changing the mainJump() function to this:

function mainJump():Void{
	if(mainJumping) {//if jumping has been initiated
		if(jumpSpeed < 0){//if the guy is still going up
			jumpSpeed *= 1 - jumpSpeedLimit/133;//decrease jumpSpeed slightly
			if(jumpSpeed > -jumpSpeedLimit*.1){//if jumpSpeed is small enough
				jumpSpeed *= -1;//then begin to go down
			}
		}
		if(jumpSpeed > 0 && jumpSpeed <= jumpSpeedLimit){//if main is going down
			jumpSpeed *= 1 + jumpSpeedLimit/133;//incrase the falling speed
		}
		mcMain._y += jumpSpeed;//finally, apply jumpSpeed to mcMain
		//if main hits the floor, then stop jumping
		if(mcMain._y >= Stage.height - mcMain._height && totalHeight <= 0){
			mainJumping = false;
			mcMain._y = 387.5;
			if(startedJumping){//if the main has begun jumping
				gameOver = true;//then finish the game
				showFinalStats();//and show the poor kid their stats
			}
		}

		totalHeight -= jumpSpeed;//add to the total height (jumpSpeed will be negative)
	}
	if(mcMain._y > 387.5){
		mcMain._y = 387.5;
	}
}

I just changed the two 120’s to 133’s. That’ll make jumping a bit better.

Now, we can add some special effects. The first one, of course, is going to be a background. First, define a variable called totalBgShapes at the top and set it to 0. Then, add this code to the main onEnterFrame() function:

//creating background particles
bellHolder.createEmptyMovieClip("bg"+totalBgShapes, bellHolder.getNextHighestDepth());
bellHolder["bg"+totalBgShapes].beginFill(0x333333); //this just determines the shape's color
bellHolder["bg"+totalBgShapes]._x = int(Math.random()*550);
bellHolder["bg"+totalBgShapes]._y = bellTop;
//creating 4 random points to make a random shape
bellHolder["bg"+totalBgShapes].lineTo(int(Math.random()*5), int(Math.random()*5));
bellHolder["bg"+totalBgShapes].lineTo(int(Math.random()*5), int(Math.random()*5));
bellHolder["bg"+totalBgShapes].lineTo(int(Math.random()*5), int(Math.random()*5));
ellHolder["bg"+totalBgShapes].lineTo(int(Math.random()*5), int(Math.random()*5));
bellHolder["bg"+totalBgShapes].endFill();//finishes up the shape

bellHolder["bg"+totalBgShapes].onEnterFrame = function(){//giving it some actions
	this._y += 2;
}

totalBgShapes ++;

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:

mcMain.swapDepths(10);//making it in front of everyone

Well, I guess that pretty much finished up everything. I hoped you learned much from my tutorial!

Preview

Download Source
(Requires Flash 8 or above)

Subscribe!

Subscribe!
Enter your email address:  

Awesome Tutorials