Tutorial: How to make a Flight Clone
in Flight, Tutorials by santokiHere’s the next installment to the tutorial series on how to make a gsensor game.
Today we are going to learn how to make the following game:
Note: the demo game above is NOT using the gsensor(for convenience), but the mouse. This tutorial will be using the gsensor.
This tutorial is buildup from a previous Gsensor tutorial. You can find it here.
Preparations
Go on ahead and download the advancedGsensorTutorial.zip from the previous tutorial and open the .fla.
Create a new layer and label it ship.
Next draw anything that looks like a ship… here’s what mine looks like.
Go on ahead and select it and make it into a Movie Clip by right clicking and pressing Convert to Symbol.
Make sure to label the name as hero, check Export for Actionscript, and give it an Identifier name of hero. Click OK.
Great! Now you can delete the hero currently on the Stage because it will be dynamically added on to the screen (Do not delete the hero in the library).
Let’s go on ahead and prepare for blasters!
Draw a simple bullet/blaster and like the hero, let’s make it into a Movie Clip by right clicking and pressing Convert to Symbol or the shortcut F8.
Make sure to label the name as bullet, check Export for Actionscript, and give it an Identifier name of bullet. Click OK.
Like the hero, you can delete the bullet currently on the Stage because it will be dynamically added on to the screen (Do not delete the bullet in the library).
Coding
Our goal for coding will be to replace the default image with the cool hero ship we made and allow it to shoot those bullets we made earlier.
Go ahead and press F9 to open up the actions panel. Assuming you have not touched the code, find line 31 and let’s add a container.
createEmptyMovieClip("container", 0);
This code allows us to store everything into a container MovieClip and control everything in a much more structured manner.
Next find line 36 which says:
var mc:Object = _root.attachMovie("ball", "hero", _root.getNextHighestDepth());
and modify it to say the following:
var mc:Object = _root.container.attachMovie("hero", "hero", _root.container.getNextHighestDepth());
If you’ve made the changes and test the movie out (or even play it on the cowon). You should be able to play with the ship with the gsensor.
Coding the bullet will now require a little more coding, but don’t worry we’ll go one step at a time.
Start on a new line on the bottom of the same Action layer, for me it was line 112.
Let’s begin by making a function for shooting a bullet:
function shoot_bullet(obj:Object) {
bcnt++;
var mc:Object = _root.container.attachMovie("bullet", "bullet"+bcnt, _root.container.getNextHighestDepth());
//centers the mc to the middle of the object.
mc._x = obj._x;
mc._y = obj._y;
mc.spd = 10;
mc.onEnterFrame = function() {
//movement applied to this mc
this._y -= this.spd;
//bounding restrictions.
if (this._y<=0) {
this.removeMovieClip();
}
};
}
The following code creates a bullet on the center of the designated object (in our program the hero) and will move to the top of the screen at a speed of 10 pixel per frame and will be removed from the game once it reaches the y coordinate of 0.
You will notice that I am using a variable called bcnt. What is that? Well it is a counter as for how many bullets have been fired off. So let’s define the variable bcnt where all the other variables are defined. In our example, it’s line 27 right under the declaring of the variable gCurRotation add:
var bcnt:Number = 0;
Now we are settled. All we need to do is have an action or an event that calls our newly defined function. Add the following action to the bottom of the code:
onMouseDown = function(){
shoot_bullet(_root.container.hero);
}
The following code responds to every time the user presses the screen/Mouse is down, the shoot_bullet function will be called causing the hero to shoot a bullet.
Awesome! Well that completes the first installment of making a flight clone. Hope you enjoyed it.
You can download all the files here.
If you come across any trouble say it feel free to comment.







whoa! great… but I think the pro’s will be able to handle it more better.
yes!!!!!!!!! I did it!!!
probably I could make some app myself. thanks..
hope you can help with the enemies..
this thread is incomplete… or is it top secret?? haha^^