Duplicate Enemies or Parent Class or Array for enemies

Started by thehivetyrant, Thu 04/03/2010 01:35:45

Previous topic - Next topic

thehivetyrant

Hi,
    My games coming along nicely but as i'm heading deeper into it i realise i need more enemies.
At the end of the game i could have 20 or so enemies.
I am worried i will have to create 20 "characters" that are all the same.
And on top of that i have code like "if (Zombie.IsCollidingWith(Player)...)" etc
And am scared i will have to duplicate that 20 times for each character or us a lengthy amount of || (< that means OR right?)

Is there a way to place the same character in the same room, at the same time, multiple times?
For example: 3 of the same zombie characters.

If not, I've been reading about class's and array's.
I thought it would be useful to set up a parent class and have all characters be a child of that class (taking on it's code).
I'm unsure if this is doable.

I'm also confused about whether an array would work in this situation.

So basically, i need your opinions on what would be the most effective method in keeping repitition to a minimal.

Thanks in advance!
           From Me



Matti

You can't display characters multiple times, but arrays are the way to go.

Just do something like this:

Code: ags

int i=1;

while(i<21){
  character[i].DoSomething;
  i++;
}


This way you could handle 20 Zombies at once (characters 1-20). Sorry for the short answer, but I really have to go to bed right now ;)

SMF spam blocked by CleanTalk