Skip to main content
Known Participant
May 8, 2007
Question

Controlling fire in Space Invaders game

  • May 8, 2007
  • 1 reply
  • 512 views
Hi again,

still working through the tutorial on Space Invaders in Flash MX 2004 (bit out of date, I know).

I've got the player craft under mouse control. What I don't like about the game is that you can fire as rapidly as you wan't, though the number of bullets is limited. You can change this limit in the variable - I would rather have it though that you can only have a set number of bullets in play at a time (at the moment, if you go over the limit, the uppermost bullets just disapear).

Here is the code:

// 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;
}

What code could I use to have it so that you can only have, say, 3 bullets in play at once, and you can't fire again until they've hit / left the screen?

regards,

g
This topic has been closed for replies.

1 reply

Known Participant
May 8, 2007
I would like to rephrase my question a little - I'd like it so that you can only fire over a limited period - only one bullet every second, for example.

Anyone got any ideas about this?
May 8, 2007
Why not just keep track of the bullets fired in an array/counter and only when length of the array of value of the counter is less than 3 is there firing allowed.
Known Participant
May 8, 2007
I don't know how to do that - this tutorial, and the advice I've gotten relating to it are my first attempts with flash, so it's all learning.

Could you explain how to do what you suggested?

cheers,

g