1. Member
Join Date
Nov 2011
Posts
12
Rep Power
0

## Survival wave game

Hi all, I'm making a simple wave based survival game for a programming class and I'm having a bit of trouble, heres some background: I've chosen Velociraptors as my basic attacker in the game i.e. what you need to kill to advance to the next wave, and of stuffed a bunch of them into an array, what I want is to spawn the second wave after the first is completely eliminated, heres my code to do so:

this initiates the first wave:
Java Code:
for (int i=0; i<5; i++)
{
if(raptors[i].isAlive==true)
{
g.drawImage(raptorPic,raptors[i].xpos,raptors[i].ypos,this);
}
}

for (int i=0; i<5; i++)
{
if(raptors[i].isAlive==true)
{
raptors[i].move();
}
}
this is supposed to initiate the second wave
Java Code:
for (int i=0; i<5; i++)//draw wave 2
{
for (int x=5; x<15; x++)
{
if(raptors[i].isAlive==false&&raptors[x].isAlive==true)
{
g.drawImage(raptorPic,raptors[x].xpos,raptors[x].ypos,this);
}
}
}//end of draw wave 2

for (int i=0; i<5; i++)//move wave 2
{
for (int x=5; x<15; x++)
{
if(raptors[i].isAlive==false&&raptors[x].isAlive==true)
{
raptors[x].move();
}
}
}//end of move wave 2
The problem is after a single raptor from the first wave dies, the second wave is instantly drawn and moved, obviously I need every object in the first wave to die before the second wave spawns, any help would be appreciated, thanks in advance.

2. ## Re: Survival wave game

Use a List instead of an array. When a raptor is killed remove it from the List. When the List is empty call the second wave.

3. Member
Join Date
Nov 2011
Posts
12
Rep Power
0

## Re: Survival wave game

That sounds a lot simpler than my array, unfortunately, I have no idea how to use a list, and although I'm sure I could easily find a guide online, I need an array in the game as a requirement for my project.

4. ## Re: Survival wave game

In that case loop over the array and check if each raptor is alive. If you find one that is alive DON'T initiate the second wave. This would be best done in a method that returns a boolean.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•