View Full Version : Space Invaders - More enemy lives
backflipdan
05-16-2007, 09:23 AM
I need help, I have made a space invaders game, the only trouble is, I want one enemy at the top of the screen to have 10 lives. I need actionscript on the movie clip of the enemy.
I have made dynamic text to give lives to the enemy (it is the boss) and in the 'Var' I put 'bosslives'
How do I apply this to the enemy so that they work and when I shoot the enemy the bosslives go down from 10, and then when it gets to zero the enemy dissapears.
Somebody gave me this coding but im not sure what else I need to put in:
if (a condition that causes lives to go up == true)
this.bosslives ++;
Someone get back to me on this, many thanks
emergency_pants
05-16-2007, 09:39 AM
I guess that you have some sort of hit detection script on all of your enemies. You provide ALL your enemies with a variable called numLives:Number
//inside your function attaching an enemy to the stage:
enemy.numLives = 10;
Whenever you hit the enemy you reduce the value of numLives by one:
//inside your function where an enemy gets hit
enemy.numLives --
if (enemy.numLives == 0){
//kill the enemy
}
That will give you the opportunity to give any enemy clip multiple lives, so you could have hard invaders which take two or three hits to kill. Flexible.
Does that sound like it might help?
backflipdan
05-16-2007, 09:49 AM
The hit detection is in here somewhere I think:
// declare global functions
//
// --------- INITIALISE ALIENS ------------- //
_global.initAliens = function(mc) {
depth = 0;
for (var i = 0; i<3; i++) {
for (var j = 0; j<10; j++) {
attachMovie(mc, mc+i+"_"+j, 100+depth);
_root[mc+i+"_"+j]._x = j*20;
_root[mc+i+"_"+j]._y = i*80-160;
depth++;
}
}
};
//
// ------- MOVE ALIENS ----------------- //
_global.moveAliens = function(mc, frame,alspeed) {
_root.deadcount = 0;
// move aliens
for (var i = 0; i<3; i++) {
for (var j = 0; j<10; j++) {
// move horizontal
_root[mc+i+"_"+j]._x += speed;
// check if aliens hit defender
if(_root[mc+i+"_"+j].hitTest(_root.defender)){
cleanup(mc);
_root.gotoAndStop(5);
}
// check if any aliens left alive
if (_root[mc+i+"_"+j] != null) {
++_root.deadcount;
}
// -------test bullet hit
bulleti = 6;
while (--bulleti>0) {
if (_root[mc+i+"_"+j].hittest(eval("_root.bullet"+bulleti))) {
_root[mc+i+"_"+j].removeMovieClip();
eval("_root.bullet"+bulleti).removeMovieClip();
_root.score += 1;
}
}
// hits left wall
if (_root[mc+i+"_"+j]._x<0) {
// set direction to right
speed = alspeed;
// drop down
dropdown = true;
break;
}
// hit right wall
if (_root[mc+i+"_"+j]._x>Stage.width) {
// set direction to left
speed = -alspeed;
// drop down
dropdown = true;
break;
}
}
}
// drop down all the rows
if (dropdown) {
for (var i = 0; i<3; i++) {
for (var j = 0; j<10; j++) {
_root[mc+i+"_"+j]._y += 20;
}
}
}
// reset flag
dropdown = false;
// if all aliens are dead
if (_root.deadcount == 0) {
// go to next level
_root.bombspeed = 0.0;
_root.gotoAndStop(7);
}
};
and if this helps the name of the enemy in my game is called 'Bug' and there is only one row of one because it is the end of my level 1.
I will try out that coding just sent
backflipdan
05-16-2007, 11:55 AM
I am still a little confused,
if I put in 'numLives' into the script does that mean I have to change the 'bosslives' in the 'Var' to 'numLives' for it to work? Even when I change it the enemy still dies in one hit, maybe because I am putting the script you gave me in the wrong place.
backflipdan
06-13-2007, 11:52 AM
I guess nobody knows how to do this properly
emergency_pants
06-22-2007, 03:36 PM
LMFAO!
:rolleyes:
whizkid1990
06-22-2007, 05:49 PM
Since you want a separate boss (from the minions), you would at least have to declare a boss instance first (by creating a new movieclip maybe??)
since the rest of the enemies are dynamically generated.....
and then you can attach the boss movieclip to the stage as you did for the rest of the invaders.
attachMovie(boss, boss1, 100+depth);
After which you can than declare a separate hittest function for the boss
if (_root.boss1.hittest(eval("_root.bullet"+bulleti))) {
enemy.numLives --
if (enemy.numLives == 0){
//kill the enemy
_root[boss1].removeMovieClip();
eval("_root.bullet"+bulleti).removeMovieClip();
_root.score += 1;
}
}
Something like that.Alternatively you can place a hittest before your current hittest, and declare the condition
if (_root[mc05].hittest(eval("_root.bullet"+bulleti))) {
_root.bosshealth--;
if(_root.bosshealth==0){
_root[mc05].removeMovieClip();
eval("_root.bullet"+bulleti).removeMovieClip();
_root.score += 1;
}
}
Oh and the solution is as clear as day to emergencypants............
;-)
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.