dark acalyte
11-06-2007, 10:58 PM
var health = 100;
onClipEvent (enterFrame) {
for (i=0; i<_root.nrEnemies && _root.health>0; i++) {
if (this.hitTest(_root["Enemy"+i])) {
this.gotoAndPlay("ghostHit");
_root.health -= random(11)+5;
if (_root.health<=0) {
this.gotoAndPlay("ghostDeath");
_root.health = 0;
_root.lives -= 1;
}
for (k=0; k<_root.nrEnemies; k++) {
_root["Enemy"+k].reset();
}
}
}
im working on a game where the health starts at 100 and goes to 0 through various hits from an enemy that spews out random damage ranging from 5-12; i had a problem earlier where when the health reached zero and i was still hitting the enemy my health would go past 0 into the negatives, but i fixed that and it stops at 0 because when the health >0 the health stays at 0 till the maincharacter movieclip resets. my problem is is that when the maincharacter's health reaches exactly 0 ( as in the enemies hits that are random 5-12 add up to exactly zero and not negative 1) he respawns invincible and isnt affected by the enemies anymore, the above code is what deals with the health, any help would be appreciated.
onClipEvent (enterFrame) {
for (i=0; i<_root.nrEnemies && _root.health>0; i++) {
if (this.hitTest(_root["Enemy"+i])) {
this.gotoAndPlay("ghostHit");
_root.health -= random(11)+5;
if (_root.health<=0) {
this.gotoAndPlay("ghostDeath");
_root.health = 0;
_root.lives -= 1;
}
for (k=0; k<_root.nrEnemies; k++) {
_root["Enemy"+k].reset();
}
}
}
im working on a game where the health starts at 100 and goes to 0 through various hits from an enemy that spews out random damage ranging from 5-12; i had a problem earlier where when the health reached zero and i was still hitting the enemy my health would go past 0 into the negatives, but i fixed that and it stops at 0 because when the health >0 the health stays at 0 till the maincharacter movieclip resets. my problem is is that when the maincharacter's health reaches exactly 0 ( as in the enemies hits that are random 5-12 add up to exactly zero and not negative 1) he respawns invincible and isnt affected by the enemies anymore, the above code is what deals with the health, any help would be appreciated.