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

2021/3/14

How to make the spawnrate go faster over time?

KeLLox KeLLox

2021/3/14

#
Hello, i want my enemies (Balloons) to spawn faster over time here is my code:
private int Spawnrate = 100; //je höher desto langsmamer
    Balloon balloon = new Balloon();
    Leben counter = new Leben();
    Geldanzahl geldanzahl = new Geldanzahl();
    Kauf_Tower turm = new Kauf_Tower();
    Tower tower = new Tower();
    /**
     * Constructor for objects of class MyWorld.
     * 
     */
    public MyWorld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(850, 550, 1);
        addObject(counter, 325, 50);
        addObject(geldanzahl, 525, 50);
        addObject(turm, 750, 300);
    }

    public void act(){
    Spawnrate--;
    if(Spawnrate <= 0){
    addObject(new Balloon(), 14, 239);
    Spawnrate = 100;
    }
}
AnJoMorto AnJoMorto

2021/3/14

#
Total DIY code written by a total amateur without testing but if it works it might help you until someone more competent answers:
int totalSpawnrate = 100; //before the act()

spawnrate --;
if (spawnrate <= 0)
{
addObject(new Balloon(), 14, 239);
spawnrate = totalSpawnrate - 1;
totalSpawnrate = totalSpawnrate -1;
}
You need to login to post a reply.