ZakMcCracken
November 30th, 2007, 04:26 AM
Hey so I've made a vertical shooter in space where you fire at falling enemies with the ability for multiple bullets to be on the screen at a time.
Everything was running smooth up to the hitTest on the enemies detecting a hit from a laser. Not all of the lasers fired would unload the enemies and I've come to realize that only the most recent fired shot can actually work.
Code I've used for the enemy is:
function enemy_clover(){
attachMovie("clover","clover"+enemyDepth,enemyDepth)
clover = eval("clover"+enemyDepth)
enemyDepth++
clover._x = Math.floor(Math.random()*(25-425))+425;
clover._y = -50
clover.enemySpeed = Math.floor(Math.random()*(2-4))+4;
clover.enemyRotation = Math.floor(Math.random()*(-15-15))+15;
clover.onEnterFrame = function(){
this._y+=this.enemySpeed;
this._rotation += this.enemyRotation
if(enemyDepth>4000){
enemyDepth = 3000;
}
if (this.hitTest(_root.laserShot)) {
this.removeMovieClip();
_root.laserShot.removeMovieClip();
score+= 5;
}
}
}.....and the code for the laser:
_root.attachMovie("shot","shot"+laserDepth,laserDepth);
laserShot = eval("shot"+laserDepth);
laserDepth++;
.....I realize that the "laserShot" being tested for in the hitTest on the enemy is only the most recent and highest "laserDepth".
Is there another way I can call the lasers? I would appreciate any help.
Thanks :rocker:
Everything was running smooth up to the hitTest on the enemies detecting a hit from a laser. Not all of the lasers fired would unload the enemies and I've come to realize that only the most recent fired shot can actually work.
Code I've used for the enemy is:
function enemy_clover(){
attachMovie("clover","clover"+enemyDepth,enemyDepth)
clover = eval("clover"+enemyDepth)
enemyDepth++
clover._x = Math.floor(Math.random()*(25-425))+425;
clover._y = -50
clover.enemySpeed = Math.floor(Math.random()*(2-4))+4;
clover.enemyRotation = Math.floor(Math.random()*(-15-15))+15;
clover.onEnterFrame = function(){
this._y+=this.enemySpeed;
this._rotation += this.enemyRotation
if(enemyDepth>4000){
enemyDepth = 3000;
}
if (this.hitTest(_root.laserShot)) {
this.removeMovieClip();
_root.laserShot.removeMovieClip();
score+= 5;
}
}
}.....and the code for the laser:
_root.attachMovie("shot","shot"+laserDepth,laserDepth);
laserShot = eval("shot"+laserDepth);
laserDepth++;
.....I realize that the "laserShot" being tested for in the hitTest on the enemy is only the most recent and highest "laserDepth".
Is there another way I can call the lasers? I would appreciate any help.
Thanks :rocker: