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

2018/7/25

how to change worlds between levels

liverpoolfc liverpoolfc

2018/7/25

#
could you please tell me how to change worlds between levels when my enemy is dead
Agent40 Agent40

2018/7/25

#
You can set up a boolean or integer value to determine whether or not the enemy has been removed from the world in the method that states the enemy needs to be removed. After that you need to make that variable act upon the loss of the enemy: For Example:
1
2
3
4
if ([Boolean/Integer Name] == [0/true]) // use Integer if there is more than 1 enemy/multiple enemy classes
{
      Greenfoot.setWorld(new [World Name]()); // This is the world changed to
}
danpost danpost

2018/7/26

#
If you remove the enemy from the world when it dies, all you need is something like the following in your World subclass act method:
1
2
3
4
if (getObjects(Enemy.class).isEmpty())
{
    // change worlds here
}
liverpoolfc liverpoolfc

2018/7/26

#
What is the command to change between one world and another.Should we just write
1
world = newWorld
danpost danpost

2018/7/26

#
liverpoolfc wrote...
What is the command to change between one world and another.Should we just write
If World2 was the name of the world to proceed to, then:
1
Greenfoot.setWorld(new World2());
would create and set active a new World2 object.
liverpoolfc liverpoolfc

2018/7/26

#
I want the new world to come about 10 seconds after printing"you are proceeding to the next level"
liverpoolfc liverpoolfc

2018/7/26

#
my current code is
1
2
3
4
5
6
if (getObjects(enemy.class).isEmpty())
    {
    showText("You Are Proceeding to the next level", 400, 300);
    Greenfoot.setWorld(new MouseWorldLevel2);
            
}
Super_Hippo Super_Hippo

2018/7/27

#
You could add a 'Greenfoot.delay(600);' between lines 3 and 4 if you want to delay the whole scenario. If not, you need to set a timer and let it run for those 10 seconds and set the new world when it reached 0.
You need to login to post a reply.