hi guys I followed a tutorial to make a scoreboard and it worked fine, I remade it in a different game and now it will not work, I know i'm being daft but I cannot for the life of me find the error in the code. Here is the code;
Code from the counter;
public class Counter extends Actor
{
int score = 0;
/**
* Act - do whatever the Counter wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setImage(new GreenfootImage("Score : " + score, 24, Color.GREEN, Color.BLACK));
}
public void addScore()
{
score++;
}
}
code from the object;
public class Car extends Actor
{
/**
* Act - do whatever the Car wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
moveAndTurn();
eat();
}
public void moveAndTurn()
{
if(Greenfoot.isKeyDown("right")) setLocation(getX()+1, getY());
if(Greenfoot.isKeyDown("left")) setLocation(getX()-1, getY());
if(Greenfoot.isKeyDown("down")) setLocation(getX(), getY()+1);
if(Greenfoot.isKeyDown("up")) setLocation(getX(), getY()-1);
}
public void eat()
{
Actor FuelCanister;
FuelCanister = getOneObjectAtOffset(0,0,FuelCanister.class);
if (FuelCanister !=null)
{
World world;
world = getWorld();
world.removeObject(FuelCanister);
GameScreen gamescreen = (GameScreen)world;
Counter counter = gamescreen.getCounter();
counter.addScore();
}
}
}
GameScreen is the name of the world with the counter on, FuelCanister is the pickup and the Counter is Counter
Any ideas?
