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

2017/11/11

Spawning Mobs wave by wave

KauTC KauTC

2017/11/11

#
Hi i not sure where to start but i wish to know how to spawn like the mobs wave by wave like example first wave will have around 10 mobs and once they all get killed the next mobs will be spawn. I was thinking that i make a scoreboard which first stage one mob will be like 5 point and first will spawn 3 level 1 mobs if 2 killed another 3 will spawn. Then when all 10 killed will continue with next stage. Can help with the coding ? Sorry if my explanation is not good
danpost danpost

2017/11/11

#
First determine what variables (instance fields) you might need to accomplish it. You will probably need one for the number of mobs to spawn at the current level; one to count how many have been spawned this level (or, instead, and maybe easier, one to count down how many more need to be spawned this level); and, of course, one for the score and one for the level number. You pretty much named the conditions for spawning -- if down to one mob, spawn more, limited by number remaining to spawn with maximum of 3. Try writing a method for spawning mob objects applying the conditions required coded in your World subclass. An act method in the class should call the method.
KauTC KauTC

2017/11/12

#
how to write the code so that the mobs will spawn when your score = 5
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Background here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Background extends World
{
    Counter counter = new Counter();
    private int wave;
    /**
     * Constructor for objects of class Background.
     * 
     */
    public Background()
    {   
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(700, 600, 1); 
        prepare();
    }
    
    public Counter getCounter()
    {
        return counter;
    }
    
    
    private void prepare()
    {        
        addObject(counter, 100, 40);
        Prince prince = new Prince();
        addObject(prince, 339,554);
        First first = new First();
        addObject(first, 41, 65);
        First first1 = new First();
        addObject(first1, 41, 256);
        First first2 = new First();
        addObject(first2, 41, 483);
        First first3 = new First();
        addObject(first3, 656, 162);
        First first4 = new First();
        addObject(first4, 656 ,386);
    }
    
    private void spawn()
    {
        Second[] seconds = new Second[5];
        for(int i=0; i<seconds.length;i++)
        {
            seconds[i] = new Second();
            int SecondX = Greenfoot.getRandomNumber(getWidth());
            int SecondY = Greenfoot.getRandomNumber(getHeight());
            addObject(seconds[i], SecondX, SecondY);
        }
    }
    
}
danpost danpost

2017/11/12

#
KauTC wrote...
how to write the code so that the mobs will spawn when your score = 5
public void act()
{
    if (wave == 0 && counter.getValue() == 5)
    {
        wave = 1;
        spawn();
    }
}
You need to login to post a reply.