Tutorial details:
Written by: Xavier
Difficulty Level: Advanced
Download FLA HOW TO USE CLASS AND OBJECT IN GAMES


Ok this is not very complicated but it's not simple too. You may have knowledge in what is a class and an object and how it woks. I explain it a little in my tut, but I know that somebody else has working on a tut talking about this. So look about it.

Because of the lenght of the code I divided my tut in several part. But you have to keep in mind that you CAN'T separate some code to the rest WITHOUT rewritting it. So this tut, execpt if you use it "as is", is here just to show you a good way to make a game (not necessary a spacegame). Try to understand and don't copy/paste code!!!!

I give you the working fla. The better way to really understand is to open the fla, looking which methods are call in the begining of the game (here frame 5), and follow the code like the ActionScript do. Have the printed tut near you and let's go. But it's my opinion, so do as you want!

HOW TO LOAD DECOR AND MADE A MAP OF IT

BUT IF YOU DON'T WANT TO USE CLASS AND OBJECT LOOK THIS TUT TOO. YOU'LL FIND SOME INTERESTING WAY (i think) TO I.E LOAD DYNAMICALLY BACKGROUNDS AND SCROLL IT.


Before looking for the code, we have to made the different MC to make the game working.

The first one is the ship.

This one is divided in three frame:

  • frame 1 containing the MC "navette stop" (name of the symbol in the library). The jet of the spaceship is on "stand by". The frame's label is "stop".
  • frame 2 containing the MC "navette run" (name of the symbol in the library). The jet of the spaceship is running. The frame label is "run".
  • frame 3 containing the MC "navette explose" (name of the symbol in the library). The spaceship explose. The frame label is "explose".

Look at the fla to see how are each MCs.

The second one is the MC timer.
It's simply a timer. Just write timer and convert it to a MC. The code under is on it.

//each time the MC display one of this frame.
onClipEvent (enterFrame) {
// take the new time
_root.newtime = getTimer();
// define the time between oldtime and newtime. Use to now if the player can firing one missile again.
_root.timer = _root.newtime - _root.oldtime;
}

Note that you can made it with ActionScript (AS). create a MC with _root.createEmptyMovieClip("clipName", depth).
So the code after will be:

// AS way to define the onClipEvent(EnterFrame)
_root.clipName.onEnterFrame = function () {
_root.newtime = getTimer();
_root.timer = _root.newtime - _root.oldtime;
}

The last one are the missile clip.

In my example I made 2 different missile. One simple (default one) and one who explose . You can make your own, but you always have to follow this way to made them, else they'll "don't work". You have to make a MC for each missile. For each MC you have to get 2 frames. The first one is the default one, the second one (Frame Label: explose) containing a graph (or a MC) of the explosion of the missile. In each frame you have to put this code : stop(); . Look at the fla to see how it works.

I've made too a specific MC for the "explose missile". This graph will follow the spaceship. Here the MCrepresents the limit of the explose missile. Look at the fla to see it, it's the bid res circle.

Note that all the MCs I've made are in my scene. I used to do this. In that case I see all the clip which are in my scene. If you don't want to have this clip on your scene, put a linkage name in their properties (on the library window) and each time I use MC.dupplicateMovieclip(newName,depth) use attachmovieClip(linkageName, newName, depth). See on the Flash help to see how it works!