How to Make a Vertical Shooter in AS3 – Part 6

Part 6: Finishing Touches

As always, the finishing touches of this game won’t be explained too much by me, in hopes that you actually can do some of this stuff by yourself. Of course, there will always be source files at the bottom if you need to clear anything up.

The first thing I want to do is show the score on the “lose” screen. That’ll be pretty easy, just add a dynamic text field there.

Next, we can make some particles move down the screen so it looks like the player is actually moving forward. We’re going to make them the same speed as the enemies. I’m actually show some code for this one, because it’s also a pretty new thing for me. We’re not going to make a MovieClip for this, we’re going to make dynamic shapes through ActionScript. Here’s the code to place at the bottom:

//adding another enterframe listener for the particles
stage.addEventListener(Event.ENTER_FRAME, generateParticles);
 
//checking if there already is another particlecontainer there
if(particleContainer == null){
	//this movieclip will hold all of the particles
	var particleContainer:MovieClip = new MovieClip();
	addChild(particleContainer);
}
 
function generateParticles(event:Event):void{
	//so we don't do it every frame, we'll do it randomly
	if(Math.random()*10 < 2){
		//creating a new shape
		var mcParticle:Shape = new Shape();
		//making random dimensions (only ranges from 1-5 px)
		var dimensions:int = int(Math.random()*5)+1;
		//add color to the shape
		mcParticle.graphics.beginFill(0x999999/*The color for shape*/,1/*The alpha for the shape*/);
		//turning the shape into a square
		mcParticle.graphics.drawRect(dimensions,dimensions,dimensions,dimensions);
		//change the coordinates of the particle
		mcParticle.x = int(Math.random()*stage.stageWidth);
		mcParticle.y = -10;
		//adding the particle to stage
		particleContainer.addChild(mcParticle);
	}
 
	//making all of the particles move down stage
	for(var i:int=0;i<particleContainer.numChildren;i++){
		//getting a certain particle
		var theParticle:Object = particleContainer.getChildAt(i);
		//it'll go half the speed of the character
		theParticle.y += mainSpeed*.5;
		//checking if the particle is offstage
		if(theParticle.y >= 400){
			//remove it
			particleContainer.removeChild(theParticle);
		}
	}
}

Pretty intense, eh? Well, this is a finishing touch, and most finishing touches are pretty intense. If you want to, you can remove this function when the player loses, but I won’t because it adds a pretty cool effect.

Well, that’s actually all that I really have to finish off the game. I hope you had fun making it!

Spread the Knowledge

  • Print
  • Digg
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Twitter
  • Google Bookmarks
  • Design Float
  • DZone
  • Yahoo! Buzz
  • PDF
  • Reddit
  • RSS
  • Technorati

Preview

Download Source
(Requires Flash CS3 or above)

Subscribe!

Subscribe!
Enter your email address:  

Awesome Tutorials