CLASS AMISSILE

Ok, let's start!

First of all you have to create your class. Here is the way to proceed!

// Make the var AMissile exist
function AMissile() {};
// and define it as a lower class of the class Movieclip.
AMissile.prototype = new MovieClip();

"MyClass.prototype = new Aclass()" is use to create a class MyClass from the upper class Aclass. Ok ?

Now, you have to write the methods of this class. The first one setting all the var used by the object to they're default value.
Understanding that this var is created for each object created with this class.

// creating the methods InitMissile
AMissile.prototype.InitMissile = function (porteur, MonDecor) {
// and setting the var
this.vitesse = 0; //missile's speed
this.Vivant = false; //missile isn't "alive"
this.CopieMissile (porteur, MonDecor);
}

You'll see that I calling another method in the InitMissile. Simply to have less code to write after. In that case to create and move a missile I only have to "InitMissile" it and let's go!

So here is the CopieMissile method which dupplicate the missiles. (Don't forget that the method created here is for all objects or lower class of the class AMissile)

// create the method CopieMissile for the class AMissile. "Porteur" is the spaceship having this messile, "MonDecor" is the decor
AMissile.prototype.CopieMissile = function (porteur, MonDecor) {
/* I've got a timer in my main scene telling how many times spend since the last call.
so I look if I can firing one more missile (times between two fire is upper than a certain time that you choose, here tempsTir)
the if instruction can be proceed if the var have just been set; oldtime == 0 */
if (_root.timer > _root.tempsTir || _root.oldtime == 0) {
// niveau is an integer telling me the depth of the MC dupplicated
_root.niveau++;
//present is the number of ACTIVE missile which are in the scene (used after in my tut)
_root.present ++;
//duplicate Missile
this.duplicatemovieclip(porteur.ligne+""+porteur.colonne+"Missile"+_root.niveau, _root.niveau);
//bullet - 1. EnleveTir take away one bullet of my weapon/missile
porteur.EnleveTir();
//Property of Missile. define the _x and _y pos of the missile. In that case it seems to be firing by the spaceship (here porteur).
_root[porteur.ligne+""+porteur.colonne+"Missile"+_root.niveau]._x = porteur._x;
_root[porteur.ligne+""+porteur.colonne+"Missile"+_root.niveau]._y = porteur._y;
_root[porteur.ligne+""+porteur.colonne+"Missile"+_root.niveau]._rotation = porteur._rotation;
/*And now I move my missile. But if you look we don't have any method called deplacementMissile.
Look under to see why! Joy of the OOP.*/
_root[porteur.ligne+""+porteur.colonne+"Missile"+_root.niveau].deplacementMissile (porteur, MonDecor);
// redefine my oldtime and newtime
oldtime = getTimer();
newtime = oldtime;
//check if we already have bullet -- we will see that methods later.
if (porteur.CheckMunitions() == false) {
porteur.ChangeArmes();
}
}
};


And now here is the coolest code. We'll made as much lower class as Missile/weapon we have. For the example I've made two type of missile (so two lower class). One use by default by the player, and another one. Why because each missile have it's own behaviour. Here is the code!

//As before, I create my lower class SimpleMissile from the class AMissile,
  so It inherit ALL the method define in the AMissile class. OK?

  function SimpleMissile() {};

  SimpleMissile.prototype = new AMissile();

  /* And now look, we define the method deplacementMissile for the SimpleMissile
  ONLY.Made the

  same thing after for the other weapon, in that case each weapon have a behaviour*/


  SimpleMissile.prototype.deplacementMissile = function (porteur, MonDecor) {

  //init the var only for the object create with this class

  this.vitesse = 15; //Simple missile's speed

  this.Vivant = true; // missile exist
//in each frame of the MC associated to the class (we'll see that later)

  this.onEnterFrame = function () {

  // look for the collision with the decor (wall).

  checkcolision (porteur, this, MonDecor);

  // if it still alive

  if (this.Vivant == true) {

  // moves the missile

  this._x += (Math.cos(Math.PI/180 * this._rotation) * this.vitesse);

  this._y += (Math.sin(Math.PI/180 * this._rotation) * this.vitesse);

  //checks if it is out of sight

  if (this._y < 0 || this._y > 600 || this._x < 0 || this._x > 600)
  {

  this.removeMovieClip();

  } // check if its position cross wall position

  } else if (this.Vivant == false) {

  _root.present--; //a missile has diseapered

  }

  };

  };
/*************************************/

  // this is the same thing for the class ExplosionMissile, exept that this class
  made it's object moving differently

  function ExplosionMissile() {};

  ExplosionMissile.prototype = new AMissile();

  ExplosionMissile.prototype.deplacementMissile = function (porteur, MonDecor)
  {

  this.vitesse = 8; // speed of EXPLOSION missile

  this.Vivant = true;

  var distanceexplose = 0; //this missile explose after moving 200 pixel from
  it'
s original _x and _y

  //the _x and _y where the missile has been fired

  var orgX = porteur._x;

  var orgY = porteur._y;

 

  this.onEnterFrame = function () {

  //check if its position cross wall position

  checkcolision (porteur, this, MonDecor);

 

  if (this.Vivant == true) {

  // moves the Explosion Missile

  this._x += (Math.cos(Math.PI/180 * this._rotation) * this.vitesse);

  this._y += (Math.sin(Math.PI/180 * this._rotation) * this.vitesse);

  distanceexplose = Math.sqrt( Math.pow((orgX - this._x), 2) + Math.pow((orgY
  - this._y), 2) );

  //checks if it is out of sight

  if (this._y < 0 || this._y > 600 || this._x < 0 || this._x > 600)
  {

  this.removeMovieClip();

  }

  } else if (this.Vivant == false) {

  _root.present--; //a missile disappear

  }

 

  //if the distance is upper than 200 then

  if (distanceexplose > 200) {

  this._name = ["oldmissile"+j];

  this.Vivant = false;

  this.gotoAndStop("explose");

  _root.present--;

  }

  };

  };
// Now you have to associate a symbol with a class. Here the symbol Msimple
  is associate to the class SimpleMissile and Mexplosion to ExplosionMissile

  Object.registerClass("Msimple",SimpleMissile);

  Object.registerClass("Mexplosion",ExplosionMissile);

SO HERE YOU HAVE TWO INSTANCE OF THE CLASS AMISSILE. YOU CAN MAKE NOW YOUR OWN. I'LL BE HAPPY TO SEE ONE OF YOURS. TELL ME IF I CAN USE IT, BECAUSE I'M OUT OF IDEA AND HAVEN'T GOT THE TIME TO LOOK FOR NEW ONE.
THANX!