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

2011/6/1

Levels

CLLV CLLV

2011/6/1

#
Im new to greenfoot and have to create a game with levels. I have tried a counter but it does not seem to work. Is there another way to do it?
davmac davmac

2011/6/1

#
Upload your code! Then we can look at it and see what went wrong.
DonaldDuck DonaldDuck

2011/6/1

#
A simple level counter is this method, using a switch in the world class...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
int current_level = 0
 
public void setLevel(int level)
{
     current_level = level;
     clean_world();
 
     switch(level)
     {
          case 0: level_one();
          case 1: level_two();
     }
}
 
public void nextLevel()
{
     current_level++;
     setLevel(current_level);
}
 
public void clean_world()
{
     removeObjects(getObjects(player.class));
}
 
public void level_one()
{
     System.out.println("level one");
}
Then you can setLevel(level) in your player, or just say nextLevel()
You need to login to post a reply.