PDA

View Full Version : Space Invaders problem



patmul
March 7th, 2005, 03:51 PM
Space Invaders problem
Doing a project in flash at the minute in Space Invaders but don't really know too much about flash mx. The problem I have is that when i shoot the attackers from my ship they're not blowing up and I don't know how the code to do this .My code at the minute for shooting is
onClipEvent(load){

moveSpeed=10;

}
onClipEvent (enterFrame) {

if (Key.isDown(Key.RIGHT)) {
this._x+=moveSpeed;
} else if (Key.isDown(Key.LEFT)) {
this._x-=moveSpeed;
}
}

// when the mouse cliks
onClipEvent(mouseDown)
{
// duplicate the bullet mc
_root.bullet.duplicateMovieClip("bullet" + bulletNum,bulletNum);
// set the coords to the mouse clik
eval("_root.bullet" + bulletNum)._x = this._x;
eval("_root.bullet" + bulletNum)._y = this._y;
// increment the bullet number
bulletNum++;
// if more than 50 bullets , start again at 0
if(bulletNum>50)
bulletNum = 0;
}

and for the attacker is
onClipEvent(load){
this._y =0;
speed=10;
}
onClipEvent(enterFrame){
if(this._x <0)
{
// set direction to right
speed=10;
// drop down
this._y +=30;
}
if(this._x > Stage.width)
{
// set direction to left
speed=-10;
// drop down
this._y += 30;
}
// move horizontal
this._x += speed;

}

If anyone could help me with some of the code I would much appreciate it

Templarian
March 7th, 2005, 04:01 PM
in the bullet code
onClipEvent(enterFrame){
for(var enemycount=0;enemycount<10;enemycount++){
if(this.hittest(_root['enemy'+enemycount){
//use the remove Movie CLip function for the enemy
//add points for killing it
//remove movie clip (this)
}
}
}
}
yah, remeber to name your enemy ships like enemy0,enemy1,enemy2 etc and the code should help. u just have to fix it a little bit

patmul
March 8th, 2005, 08:04 AM
Cheers Templarian for the reply. Should be a help