This site requires JavaScript, please enable it in your browser!
Greenfoot back
NakedSnakeCQC
NakedSnakeCQC wrote ...

2016/4/22

Help, too many enemies spawning

NakedSnakeCQC NakedSnakeCQC

2016/4/22

#
Hi I am trying to and have almost finished a game on greenfoot. I want the game to add in 4 new enemies when i kill the first wave of enemies, this is 4 at the start. I am using this code but whenever i kill 4 i am getting unlimited enemies spawning from it, here is the code
            KillCount1 kc1 = getKillCount1();
            
            if(kc1.dead1 ==4)
            {
                addObject(new AtrixoLV1(), 400, 400);
                addObject(new AtrixoLV1(), 100, 200);
                addObject(new AtrixoLV1(), 700, 300);
                addObject(new AtrixoLV1(), 800, 400);
                
            }
danpost danpost

2016/4/22

#
You should probably use the fact the no AtrixolLV1 objects are in the world instead of using the 'dead1' count (which will stay at four and continue spawning until another kill is registered).
NakedSnakeCQC NakedSnakeCQC

2016/4/22

#
Could you explain how I could do that, I don't think i have used the no objects way?
danpost danpost

2016/4/22

#
NakedSnakeCQC wrote...
Could you explain how I could do that, I don't think i have used the no objects way?
// instead of
if (kc1.dead1 ==4)

// use
if (getObjects(AtrixoLV1.class).isEmpty())
NakedSnakeCQC NakedSnakeCQC

2016/4/22

#
Thank you very much I have my spawning working perfectly now i will post the code i have used as it is a mixture of the code i already had and what you sent me and again thank you very much.
public void act()
    
{

      
       KillCount1 kc1 = getKillCount1();
            
            
            if (getObjects(AtrixoLV1.class).isEmpty() && kc1.dead1 ==4)
            {
                addObject(new AtrixoLV1(), 400, 400);
                addObject(new AtrixoLV1(), 100, 200);
                addObject(new AtrixoLV1(), 700, 300);
                addObject(new AtrixoLV1(), 800, 400);
                
            }
            
            if (getObjects(AtrixoLV1.class).isEmpty() && kc1.dead1 ==8)
            {
                addObject(new AtrixoLV1(), 400, 400);
                addObject(new AtrixoLV1(), 100, 200);
                addObject(new AtrixoLV1(), 340, 300);
                addObject(new AtrixoLV1(), 600, 400);
                
            }
            
}  
You need to login to post a reply.