m trying to add a score counter in greenfoot. The following code is in my bullets class. Each time a bullet hits the rocket, the score is supposed to increase by one. I've added the necessary code to the counter class and it works normally, however when I try to add the code to my bullet class, greenfoot says that it cant find myWorld.
public void act()
{
if(!toRemove)
{
setLocation(getX()+vx,getY());
Actor actor=getOneIntersectingObject(Enemy.class);
if(actor!=null)
{
((Enemy)actor).destroyed();
GameScreen gameScreen = (GameScreen)myWorld;
Counter counter = gameScreen.getCounter();
counter.addScore();
}
if(getX()>getWorld().getWidth()+200)
{
toRemove=true;
}
}
else
{
getWorld().removeObject(this);
}
}
The part that doesn't work is GameScreen gameScreen = (GameScreen)myWorld;
if(actor!=null)
{
((Enemy)actor).destroyed();
GameScreen gameScreen = (GameScreen)myWorld;
Counter counter = gameScreen.getCounter();
counter.addScore();
}
This is in my counter method
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, greenfoot.Color.RED, greenfoot.Color.BLACK));
}
public void addScore()
{
score++;
}
}
Pls help

