Be a Supporter!

Handeling Multiple Enemies

  • 265 Views
  • 6 Replies
New Topic Respond to this Topic
kizza0
kizza0
  • Member since: Oct. 13, 2007
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Handeling Multiple Enemies 2009-08-26 07:49:11 Reply

Bassicaly, Im making a flash game for my multimedia class where you shoot an continuous stream of zombies. Every time you shoot i would like every alive zombie to be tested for a collision on the bullets path. Iv got the collision detection down but handling more than one enemy has got me down.

They will be added to the stage at random intervals and their will likely be 100's appearing in each game with less than 15 on the screen at any time. Iv thought about using an array to hold each spawned zombies name but I'm not sure how to remove that name once they die.
Any help would be appreciated.


BOOM HEADSHOT

BBS Signature
Sam
Sam
  • Member since: Oct. 1, 2005
  • Offline.
Forum Stats
Moderator
Level 19
Programmer
Response to Handeling Multiple Enemies 2009-08-26 08:53:38 Reply

If your using duplicate/attach movieclip the simplest way would be to write the collision code on the zombie movieclip.

And to remove:

removeMovieClip(this);
kizza0
kizza0
  • Member since: Oct. 13, 2007
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Handeling Multiple Enemies 2009-08-26 08:54:55 Reply

Using actionscript 3.0 so that isnt an option :(
Thanks anyway.


BOOM HEADSHOT

BBS Signature
Sam
Sam
  • Member since: Oct. 1, 2005
  • Offline.
Forum Stats
Moderator
Level 19
Programmer
Response to Handeling Multiple Enemies 2009-08-26 08:57:08 Reply

At 8/26/09 08:54 AM, kizza0 wrote: Using actionscript 3.0 so that isnt an option :(
Thanks anyway.

How about inside the movieclip and on it's frame? I'm pretty sure you could do something like that.

henke37
henke37
  • Member since: Sep. 10, 2004
  • Offline.
Forum Stats
Member
Level 30
Blank Slate
Response to Handeling Multiple Enemies 2009-08-26 10:09:02 Reply

The issue is more like that there is no such method in as 3, he needs to use removeChild on the container in combination with manually unregistering any listeners and clearing any reference to the MovieClip instance.


Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.

GeoKureli
GeoKureli
  • Member since: Apr. 1, 2003
  • Offline.
Forum Stats
Supporter
Level 19
Game Developer
Response to Handeling Multiple Enemies 2009-08-26 11:55:52 Reply

At 8/26/09 07:49 AM, kizza0 wrote: Bassicaly, Im making a flash game for my multimedia class where you shoot an continuous stream of zombies. Every time you shoot i would like every alive zombie to be tested for a collision on the bullets path. Iv got the collision detection down but handling more than one enemy has got me down.

They will be added to the stage at random intervals and their will likely be 100's appearing in each game with less than 15 on the screen at any time. Iv thought about using an array to hold each spawned zombies name but I'm not sure how to remove that name once they die.
Any help would be appreciated.
for(var i:int = 0; i < myArray.length; i++)
    if(myArray[i].dead){//if enemy is dead
        rootMC.removeChild(rootMC.getChildByName(myArray[i].name);//remove chid from parent
        if(i+1 < myArray.length)//if not the last index in array
            myArray[i] = myArray.pop();//remove child from array by moving last index to overwrite it 
        else//if this is the last index
            myArray.pop()//remove it
    }
kizza0
kizza0
  • Member since: Oct. 13, 2007
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Handeling Multiple Enemies 2009-08-27 01:37:29 Reply

Thanks dude.


BOOM HEADSHOT

BBS Signature