I am making a snake game and I want to add a rock into the world every 10 points.
This is the code in my Rock class:
I know the code is wrong, because it is showing an error, but I dont know what to change. I'm unsure how to call the getScore() method from my Score class
public class Rock extends Actor
{
public int currentscore;
public Rock(){
GreenfootImage img = getImage();
img.scale(img.getWidth()*1/14, img.getHeight()*1/14);
setImage(img);
}
/**
* Act - do whatever the Rock wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
MyWorld world = (MyWorld)getWorld();
Actor snake = getOneIntersectingObject(SnakeHead.class);
if (snake !=null){
world.die();
}
addRocks();
}
public void addRocks(){
MyWorld world = (MyWorld)getWorld();
Score score = score.getScore();
if (score == 10){
world.addObject(new Rock(), 20,10);
}
if (score == 20){
world.addObject(new Rock(), 3,6);
}
}

