I want to make a score for the collected Items, but the following code for the score is not changing even though you´ve collected new items.
(The Variable in the Player class is : int collects = 0; and it gets changed by 1 when collecting an Item)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Score here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Score extends Player
{
int score = 0;
/**
* Act - do whatever the Score wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
String text = "Score: " + score;
GreenfootImage image = new GreenfootImage(text, 20, Color.WHITE, new Color(0,0,0,0));
this.setImage(image);
int score = ((Player)getWorld().getObjects(Player.class).get(0)).collects;
}
}