Here is the fireShot function explained, line by line:
--------------------------------------------------------------------------------
------------
[quoted text, click to view] >MovieClip.prototype.fireShot = function(idName, tDist, jumpSize) {
This makes a method for the movieclip, so that you can specify any movieclip
and it will fire another movieclip.
[quoted text, click to view] >if(this.maxShots==undefined)this.maxShots = 10;
>if(this.cShots==undefined)this.cShots = 0;
>if (this.fnum == undefined)this.fnum = -1;
This sets up the default settings for the movieclip.
[quoted text, click to view] >if (this.cShots>=this.maxShots)return;
Stops the fireball from being shot if there already are the max amount of
fireballs
[quoted text, click to view] >this.cShots++;
>this.fnum++;
>var cf = this._parent.attachMovie(idName, this._name+'_f'+this.fnum,
>this._parent.getNextHighestDepth());
-cShots represents the number of shots that have been fired, and that are
still on the screen. (later in the code, cShots is decreased when the fire is
gone).
-fnum is a number that is used to label each fireball so that it is unique.
-Then a movieclip is created, which is a movieclip located in the libarary,
and is given a unique name.
[quoted text, click to view] >cf._x = cf.i_x = this._x;
>cf._y = cf.i_y = this._y;
This moves the fireball to the position of the movieclip that is firing it.
And it also sets an i_x and i_y variable which contains the starting point of
where the movieclip was fired from.
[quoted text, click to view] >cf.piece = this;
I made a variable for the fireball so that it can easily refernce to the piece
it fired from.
[quoted text, click to view] >var moveIt = function (mc, dir, step, dist) {
Creates a function to move a movieclip specified by mc, towards the direction
(degress) specified by dir, by the amount of pixels specified by step. Dist
represents how far the movieclip should travel before it dissappears.
[quoted text, click to view] >degs = dir;
>rads = degs/180*Math.PI;
>sin = Math.sin(rads);
>cos = Math.cos(rads);
>stepY = sin*step;
>stepX = cos*step;
>mc._x += stepX;
>mc._y += stepY;
>updateAfterEvent();
Uses trigonometry to move the movieclip in the specified direction by a
certain amount of pixels.
[quoted text, click to view] >distH = mc._x-mc.i_x;
>distV = mc._y-mc.i_y;
>distT = Math.sqrt(Math.pow(distH, 2)+Math.pow(distV, 2));
Uses Pythagorean Theorem to calculate the distance the movieclip has traveled.
[quoted text, click to view] >if (distT>=dist) {
>clearInterval(mc.intID);
>mc.piece.cShots--;
>mc.unloadMovie();
>}
Checks to see if the distance traveled is farther than (or equal to) the
distance that it should disappear. If it is true, it stops the moveIt function,
decreases cShots because the fireball is finished, and finally removes the
fireball.
[quoted text, click to view] >};
Ends the moveIt function.
[quoted text, click to view] >trace(this)
>cf.intID = setInterval(moveIt, 1, cf, this._rotation, jumpSize, tDist);
-The trace is unnecessary (I forgot to remove it ;)).
-The moveIt function is called in a setInterval with the fireball set as the
current fireball, the direction set as the movieclip's rotation, the size of
the jump to the one specified when calling the fireShot function, and the
distance to travel also specified when calling the fireShot function.
[quoted text, click to view] >};
Ends the fireShot function
[quoted text, click to view] >someMC.maxShots = 3;
Sets the max number of shots allowed to be on the screen fired by that
movieclip.
[quoted text, click to view] >someMC.fireShot('fire', 600, 5);
Fires a movieclip (with linkage id: 'fire') from someMC, and travels 600
pixels, jumping 5 pixels every millisecond.
--------------------------------------------------------------------------------
------------
Hope that helps you understand my code better!