super complicated hitTest bug
I was making a game, which you shoot fireballs from the sky and attack enemies. The fireball will explode when it touches the ground. This is the code of the explosion, which is a movie of 20 frames. I made a proccessor, named proccessor2, ( there is a proccessor1, of courese ). There is also a MC which stores variables, such as the attack1damage. the problem is, if it only hits one enemy, it should just attack once, with the first type. It would then trace 1. but if I shoot two fireballs together, it starts to attack more than once from the next. At the first time, it traces 1 2, then on the second time, it traces 1 2 2, then 1 2 2 2, etc. What's the problem? This is the code:
var attack;
var enemiesKilled;
var enemyKill;
function kill() {
enemyKill = 0;
for (var i in _root.proccessor2.enemies) {
if (this.enemiesKilled.length == 0) {
if (this.hitTest(_root.proccessor2.enemies)) {
_root.proccessor2.enemies.health -= attack;
this.enemiesKilled.push(i);
trace(1)
}
} else {
for (var j in enemiesKilled) {
if (enemiesKilled
enemyKill++;
}
}
trace(enemyKill);
if (this.hitTest(_root.proccessor2.enemies) && enemyKill == 0) {
_root.proccessor2.enemies.health -= attack;
this.enemiesKilled.push(i);
trace(2)
}
}
}
}
function onLoad() {
enemyKill = 0;
attack = _root.storage.attack1damage;
enemiesKilled = new Array();
}
function onEnterFrame() {
if (this._currentframe<20) {
kill();
}
if (this._currentframe == this._totalframes) {
this.removeMovieClip();
}
}
I know this may be a terrible way to do it, and you can do it in 10 lines of codes, but can you help? I am willing to explain the code if you don't understand, or if you want to know more. This is just a part of the whole game, so I don't want to upload the whole file. Sorry for the unconvenience.