Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By Junky

Thread: Survival wave game

  1. #1
    beijct is offline Member
    Join Date
    Nov 2011
    Posts
    12
    Rep Power
    0

    Default 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. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,762
    Rep Power
    7

    Default 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. #3
    beijct is offline Member
    Join Date
    Nov 2011
    Posts
    12
    Rep Power
    0

    Default 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. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,762
    Rep Power
    7

    Default 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.
    Dark likes this.

Similar Threads

  1. Large Wave Files
    By dane1193 in forum New To Java
    Replies: 2
    Last Post: 02-18-2011, 10:59 PM
  2. Need help with Drawing Sound Wave
    By zit1343 in forum Java Applets
    Replies: 1
    Last Post: 02-14-2011, 02:16 AM
  3. Creating a Triagular Wave in Java
    By locorecto in forum Java Applets
    Replies: 1
    Last Post: 03-08-2010, 07:22 AM
  4. Replies: 4
    Last Post: 02-26-2010, 03:18 AM
  5. Wave Sounds
    By Doctor Cactus in forum New To Java
    Replies: 2
    Last Post: 10-22-2008, 01:44 PM

Posting Permissions

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