Okay here is the code from the World:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class endlvl here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class endlvl extends World
{
private Text coinsCollectedText;
private int coinsCollected = 0;
/**
* Constructor for objects of class endlvl.
*
*/
public endlvl()
{
super(10, 10, 50);
coinsCollectedText = new Text("You have collected 0/50 coins", 20);
addObject(coinsCollectedText, 5, 2);
prepare();
}
public void act()
{
Player packman = (Player) getObjects(Player.class).get(0);
if (coinsCollected < packman.getCoinsCollected()) {
coinsCollected = packman.getCoinsCollected();
coinsCollectedText.setText("You have collected "+coinsCollected+"/50 coins");
}
}
/**
* Prepare the world for the start of the program. That is: create the initial
* objects and add them to the world.
*/
private void prepare()
{
Counter counter = new Counter();
addObject(counter, 5, 5);
removeObject(counter);
Player player2 = new Player();
addObject(player2, 5, 5);
}
}
