Tutorial: Make a Vertical Shooter in AS2 – Part 6
Categories: Flash
Table of Contents
Step 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. First, we have to add a totalBgShapes variable to the top of the code. Next, create an empty MovieClip called bgHolder Then, here’s the code to place at the bottom of the onEnterFrame function:
//creating background particles
bgHolder.createEmptyMovieClip("bg"+totalBgShapes, bgHolder.getNextHighestDepth());
bgHolder["bg"+totalBgShapes].beginFill(0x333333); //this just determines the shape's color
bgHolder["bg"+totalBgShapes]._x = int(Math.random()*550);
gHolder["bg"+totalBgShapes]._y = -50 - bgHolder._y;
//creating 4 random points to make a random shape
bgHolder["bg"+totalBgShapes].lineTo(int(Math.random()*25), int(Math.random()*25));
bgHolder["bg"+totalBgShapes].lineTo(int(Math.random()*25), int(Math.random()*25));
bgHolder["bg"+totalBgShapes].lineTo(int(Math.random()*25), int(Math.random()*25));
bgHolder["bg"+totalBgShapes].lineTo(int(Math.random()*25), int(Math.random()*25));
bgHolder["bg"+totalBgShapes].endFill();//finishes up the shape
bgHolder["bg"+totalBgShapes].onEnterFrame = function(){//giving it some actions
if(this._y > 450 - bgHolder._y || _root.gameOver){//if it goes off the stage or game is over
//then destroy it
this.removeMovieClip();
}
}
totalBgShapes ++;
bgHolder._y += 2;
Pretty intense, eh? Well, this is a finishing touch, and most finishing touches are pretty intense. Now, we have to make it so mcMain is on top of everything with this code at the end:
mcMain.swapDepths(1000);
Also, remove mcMain when gameOver is true or else strange things will happen.
There is one final thing that I want to do before actually wrapping up this tutorial. For some reason, there is a bug where a bullet disappears for some strange reason. I think I know exactly how to fix it. When we added the bullet to the stage, we made its depth the _root.getNextHighestDepth. I’m sorry, it should actually be bulletHolder.getNextHighestDepth.
Well, that’s actually all that I really have to finish off the game. I hope you had fun making it!
a minor bug, no biggie.
say you shoot to shots. a first, then b.
a hits an enemy before b is about to hit another. that resets all shots, and shot b is gone.
March 3rd, 2009 at 5:47 pm
One question:
How can i make it so after a while i get into a boss?
March 11th, 2009 at 2:58 pm
Hello this is a very good tutorial but I was wondering how I could make the shooting a click event instead of a keyboard driven one. I’m planning to make it shoot towards the cursor and i am havig trouble with making it shoot normally with out even starting the programming for making it target the cursor.
March 21st, 2009 at 10:13 pm
Is there a way to put the functions of the bullet into the frame script?
May 10th, 2009 at 7:37 pm
can you make a master code?
July 8th, 2009 at 4:15 pm
Shooting while moving diagonally doesn’t work except for right-up movement. Any idea why it works only in this direction?
I was trying to implement shooting while holding spacebar, however when I hold spacebar th mcMain stops moving diagonally. (again with exception for right-up direction)
September 6th, 2009 at 6:57 pm
I love this tutorial! It’s cool!
October 10th, 2009 at 10:34 am