Quote:
Originally Posted by neilmmm
welcome artS
please post your appopriate code at the same time - you much more likely to get a response
|
This is the code inside the first frame:
// DEFINE UNIQUE VARIABLE FOR ATTACHMOVIE FUNCTION
id = 0;
This is the code inside my ship(only the code for shooting bullets):
onClipEvent (load) {
// DEFINE ASCII CODING FOR THE SHOOT KEY - click here for references
shootkey = 65;
// DEFINE OTHER VARIABLES
fps = 24;
delay = 0.25;
fdelay = fps * delay;
count = fdelay;
// CREATE A NEW FUNCTION CALLED "SHOOT" WITH INPUT VARIABLE NAMED "ROTA"
shoot = function (rota) {
// INCREASES "ID" VARIABLE BY ONE TO ENSURE UNIQUENESS OF EACH ATTACHED CLIP
_root.id++;
// CREATE A NEW OBJECT CALLED "INITOBJECT"
initObject = new Object();
// GIVE IT COORDINATES ACCORDING TO THE SHOOTER
initObject._x = _x;
initObject._y = _y;
// GIVE IT A ROTATION (DEGREES) ACCORDING TO THE INPUT VARIABLE "ROTA"
initObject._rotation = rota;
// ATTACH BULLET CLIP TO INITOBJECT
_root.attachMovie("bullet", "bullet" + _root.id, _root.id, initObject);
// END "SHOOT" FUNCTION
};
// END "LOAD" FUNCTION
}
// "ENTERFRAME" REPEATS THE FOLLOWING STATEMENTS WHEN CLIP IS ON STAGE
onClipEvent (enterFrame) {
// IF BULLET IS NOT DELAYED LONG ENOUGH...
if (count < fdelay) {
// COUNT UP BY ONE
count++;
// OTHERWISE, IF BULLET IS DELAYED LONG ENOUGH AND SHOOT KEY IS PUSHED DOWN...
} else if (Key.isDown(shootkey)) {
// RESET COUNT
count = 0;
// SHOOT BULLETS... EXAMPLE - HERE I HAVE ONE STRAIGHT AND TWO SIDE BULLETS
shoot(0);
}
// END "ENTERFRAME" FUNCTION
}
This is the code inside the bullets movie clip
// DEFINE VARIABLES
speed = 20;
xmin = -_width;
ymin = -_height;
xmax = Stage.width + _width;
ymax = Stage.height + _height;
// "ENTERFRAME" REPEATS THE FOLLOWING STATEMENTS WHEN CLIP IS ON STAGE
this.onEnterFrame = function() {
// TRAVEL ACCORDING TO ROTATION
_x += speed * Math.sin(_rotation * Math.PI / 180);
_y -= speed * Math.cos(_rotation * Math.PI / 180);
// REMOVE ITSELF WHEN IT GETS OFFSTAGE
if (_x < xmin || _x > xmax || _y < ymin || _y > ymax) {
this.removeMovieClip();
}
// END "ENTERFRAME" FUNCTION
};
if(this.hitTest(_root.enemigo)){
//direccion de la animacion
_root.enemigo.nextFrame();
unloadMovie(this);
}