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

2017/6/6

Max Score

joseph.volfman joseph.volfman

2017/6/6

#
How do I set a max score for a level and then change levels when it reaches that number?
Yehuda Yehuda

2017/6/6

#
That depends on what your levels are (different world, just remove objects and place new ones, etc.). If your score to switch levels is 100 and you have an int field named "score" holding the current score, then you can use those in an if statement to change the level.
//in current World's act method
if (score >= 100) {
    //new level
    Greenfoot.setWorld(new Level2()); //change worlds
    level2(); //or a method which takes care of removing and adding the correct objects
}

private void level2() {
    removeObjects(getObjects(Block.class)); //this will remove all the instances of Block
    addObject(new Block(), 25, 375); //place new block at specified loaction
}
You need to login to post a reply.