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

2015/1/3

Take Score to the next Level - How to do it?

Riegsche Riegsche

2015/1/3

#
Hey guys, we programmed a game in which a piranha moves through the world. The piranha can eat certain enemy-types and gets hurt by others. We planned to have 3 Levels in total. After the first level is accomplished (not dying in 60 seconds and eating fish for a score) the player should be able to chose from two "power-up's". For Level 2 the player gets to chose if his piranha gets more health-points or is able to move faster. We want that the end-score from Level 1 to be the start-score of Level 2. How can we do that? Thanks for your help in advance. :)
danpost danpost

2015/1/3

#
You probably have a line like the following to go to the Level 2 world:
Greenfoot.setWorld(new Level2());
That line is short for this:
Level2 level2 = new Level2();
Greenfoot.setWorld(level2);
The expanded code gives you a reference to the new Level 2 world created. You can access any public field and execute any public method in that Level2 world right between those lines. For example:
level2.getScoreCounter().add(score); // method calls
// or
level2.score = score; // field access
You need to login to post a reply.