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

2012/4/7

how would you create levels

-nic- -nic-

2012/4/7

#
how would you create levels ,like level one would have one enemy level two would have two and so on.., please help thx
danpost danpost

2012/4/7

#
The easiest way for this is to have a static integer in your world (to track the number of enemies in the world) that starts with the value of one. When you progress to the next level, increment the value and call 'Greenfoot.setWorld(new Arena());' (replace 'Arena' with the name of your sub-class of World).
-nic- -nic-

2012/4/7

#
sorry im a bit of a novice how would you set out the static int
danpost danpost

2012/4/7

#
In your sub-class of World (let us say you named it 'Arena'), it should start out something like this:
import greenfoot.*;

public class Arena extends World
{
    static int totalEnemies = 1;

    public Arena()
    {
        super(600, 400, 1);
        // etc.
Then, you can use that value to create the enemies with
for (int i = 0; i < totalEnemies; i++) addObject(new Enemy(), Greenfoot.getRandomNumber(getWidth() - 100) + 50, Greenfoot.getRandomNumber(getHeight() - 100) + 50);
When you want the next level:
totalEnemies++;
Greenfoot.setWorld(new Arena());
-nic- -nic-

2012/4/7

#
ok i put all of that in the world subclass but when i run the world lots of enemys apear move around and then dispear
danpost danpost

2012/4/7

#
Please post your code so we can help you with it.
-nic- -nic-

2012/4/7

#
ok i got it working
You need to login to post a reply.