Tutorial: How to make a Flight Clone

in Flight, Tutorials by santoki

Here’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.

17 Comments

  1. whoa! great… but I think the pro’s will be able to handle it more better.

  2. 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^^

  3. 오.. 플래시를 사용해서 만드는것이군..
    정보 감사합니다. 제가 한국인이라서
    구글크롬으로 번식하고 했어요 ㅋ
    다 무비클립해야되군요. 감사합니다~

  4. 한국인이다!!!

  5. With this app, you can include pictures in your posts, add
    location information, and attach labels. This means you are paid for a couple
    of years’ worth of intensive bloggingwriting, posting,
    technical efforts and promoting your blogwithout any efforts at
    all.

  6. An outstanding share! I have just forwarded this onto a friend who was conducting a little
    homework on this. And he actually bought me lunch due to the fact that I found it for him…

    lol. So let me reword this…. Thanks for the meal!!

    But yeah, thanx for spending time to talk about this issue here on your web site.

  7. All things considered, it does look like it would be illegitimate doesn’t it?

    The iPhone’s camera is only 2 mega pixel, getting a maximum
    resolution of 1600 x 1200 pixels. Fedup of guests and neighbors peeping into your screen?

  8. This device is just like an have the cellular phone assistance related to
    it. So when in big trouble, you like to only vanish without a track.
    Don’t you need to be alert to your privileges.

  9. This assistance doesn’t provide you with carte blanche to maim, take, and pillage.
    They are liberated to enjoy and all that’s necessary is just a Facebook bill (also free).
    It is likewise recent and relentlessly being enhanced.

  10. You are not alone, many individuals are performing it.
    Creating use of this approach, there’s no desktop computer or some
    other application necessary. Do you have an iphone issue and require options.

  11. You’ll see a ‘Eliminate’ button appear if
    you move your mouse for the upper-right hand corner
    of the article. Individuality – With more than 600 million users, it’s not feasible merely
    to slap up any fan site, and be observed.

  12. Following fast reply, you can resume function from exactly
    where you left off. If your carried out your own gadget can restart having ios 4.Two.1 firmware.
    You can have so many icons in just a solitary folder.

  13. Just as Facebook shops your photos and Gmail shops your email.
    For us the basic plan is the second 1; the OS. I have examined the program myself, and I was very
    statisfied with my findings.

  14. Audio started playing as soon as I opened up this blog, so annoying!
    cheap Miller #58 Jersey
    [url=http://wealthtechs.com/index.asp?keyword=cheap-Miller-#58-Jersey&id=6178]cheap Miller #58 Jersey[/url]

  15. Michael Kors Outlet Online
    Ugg Black Friday
    Michael Kors Outlet
    Coach Black Friday
    Cheap Uggs
    Ugg Boots
    Coach Outlet
    Michael Kors Outlet
    锘?a href=http://www.coachonline-outlet.us.com/>Coach Outlet
    Coach Outlet
    Michael Kors Black Friday
    Uggs Black Friday
    Michael Kors Outlet
    Ugg Boots
    Michael Kors Outlet
    Ugg Boots Black Friday
    Coach Outlet
    Coach Outlet Store Online
    Ugg Boots
    Michael Kors Outlet
    Cheap Uggs
    Coach Outlet Online
    Michael Kors Outlet Online
    Canada Goose Jackets
    Michael Kors Black Friday
    Cheap Ugg Boots
    Canada Goose Jacket
    Coach Outlet Online
    Michael Kors Outlet
    Michael Kors Black Friday
    Cheap Ugg Boots
    Michael Kors Outlet
    Cheap Uggs
    Michael Kors Outlet
    Ugg Boots
    Cheap Uggs
    Ugg Boots
    Ugg Boots
    Michael Kors Outlet
    Michael Kors Outlet
    Michael Kors Outlet Online
    Ugg Boots Black Friday
    Michael Kors Outlet
    Uggs Black Friday
    Coach Outlet Store Online
    Michael Kors Black Friday
    Coach Outlet Online
    Uggs Black Friday
    Ugg Boots
    Coach Outlet
    Ugg Black Friday
    Coach Outlet
    Ugg Boots Black Friday
    Michael Kors Outlet
    Ugg Boots Black Friday
    Michael Kors Outlet
    Uggs
    Coach Outlet Store Online
    Coach Outlet Online
    Michael Kors Bags
    Coach Outlet
    Coach Outlet
    Coach Outlet Store Online
    Uggs
    Coach Outlet
    Coach Black Friday
    Coach Outlet Store Online
    Uggs
    Michael Kors Black Friday
    锘?a href=http://www.coachonline-outlet.us.com/>Coach Outlet
    Coach Outlet
    Cheap Ugg Boots
    Michael Kors Outlet Online
    Michael Kors Outlet
    Michael Kors Outlet

  16. San – Disk and Toshiba today announced the fruits
    gmail.com sign in Gmail their collaboration on a
    whole new fabrication plant: a.

  17. Hi there everyone, it’s my first go to see at this site, and paragraph is in fact fruitful designed for me, keep up posting
    these types of articles.

    Here is my web page :: VinaMHuewe

Leave a Comment