I am making a platform game in flash cs4 as3 and am having a lot of trouble getting my different classes to work right together. I have a bullet class, enemy class, and a bumper class which determines the boundaries for the enemy. When the bullet hits the enemy the enemies death animation plays and then both are removed from the game. When the last enemy on that level gets removed though, i get this error saying a term is undefined and has no properties. Also if I kill the enemies out of the order they are called things don't work properly my codes must have some errors. Here is my code between the bullet and enemy classes:
if (enemyList.length>0) {
for (var i:int = 0; i < enemyList.length; i++) {
if (bulletList.length>0) {
for (var j:int = 0; j < bulletList.length; j++) {
if (enemyList[i].hitTestObject(bulletList[j])) {
trace("Bullet and Enemy are colliding");
enemyList[i].gotoAndPlay("dead");
bulletList[j].removeSelf();
enemyList[i].xSpeedConst=0;
enemyList[i].isDead = true;
} else {
enemyList[i].isDead = false;
}
}
}
}
}
}
and also between the player and enemy and bumper and enemy.
if (enemyList[k].isDead == false && enemyList.length>0) {
for (var k:int = 0; k < enemyList.length; k++) {
if (enemyList[k].isDead == false && bumperList.length>0) {
for (var h:int = 0; h < bumperList.length; h++) {
if (enemyList[k].hitTestObject(bumperList[h])) {
enemyList[k].changeDirection();
}
}
}
}
}
if (enemyList[m].isDead == false && enemyList.length>0) {
for (var m:int = 0; m < enemyList.length; m++) {
if (enemyList[m].hitTestObject(player)) {
trace("player collided with enemy");
currentHP-=5;
if (currentHP<=0) {
currentHP=0;
trace("you died");
gotoAndStop(1);
}
updateHealthBar();
}
}
}
Sorry it's kinda long I just feel like Im missing something obvious in here or maybe all my code is just poorly structured. Either way any help would be greatly appreciated thanks!
if (enemyList[k].isDead == false && enemyList.length>0) {
should beif (enemyList.length>0) {
. – Yasuyuki Unoelse {enemyList[i].isDead = false;}
is redundant. It sometimes overwriteisDead=true
tofalse
, causes doesn't dead the enemy.(ex. If bulletList[4] hits enemy, enemy is dead. if bulletList[5] doesn't hit the enemy, enemy revive.) – Yasuyuki UnoremoveSelf()
– null