Hi everyone!
Having BIG time problem producing an Snake game in Greenfoot. The problem is that I want to do my snake grow.
I have this in my world:
public class SnakeWorld extends World
{
...
public void makeSnakeBody()
{
snakeBodyParts = getObjects(SnakeHead.class);
sizeList = snakeBodyParts.size();
if(snakeBodyParts.isEmpty()){
snakeBodyParts.add(0, new SnakeHead());
addObject(snakeBodyParts.get(0),200,60);
for(int i=1; i<6;i++){
snakeBodyParts.add(i, new SnakeBody());
addObject(snakeBodyParts.get(i),snakeBodyParts.get(0).getX() - i*CONST,snakeBodyParts.get(0).getY());
}
snakeBodyParts.add(6, new SnakeTail());
addObject(snakeBodyParts.get(6),snakeBodyParts.get(0).getX() - 6*CONST,snakeBodyParts.get(0).getY());
}
else
{
mouse = getObjects(Mouse.class);
if(snakeBodyParts.get(0).getX()== mouse.get(0).getX() && snakeBodyParts.get(0).getY()== mouse.get(0).getY())
{
snakeBodyParts.remove(sizeList-1);
snakeBodyParts.add(sizeList-1, new SnakeBody());
addObject(snakeBodyParts.get(sizeList-1),snakeBodyParts.get(0).getX() - (sizeList-1)*CONST,snakeBodyParts.get(0).getY());
snakeBodyParts.add(sizeList, new SnakeTail());
addObject(snakeBodyParts.get(sizeList),snakeBodyParts.get(0).getX() - sizeList*CONST,snakeBodyParts.get(0).getY());
}
}
}
But when the SnakeHead detects an object she eats but not growing. I think it's because of the way that defines the " eat" in SnakeHead class.
I have this in my class:
public void eat(Class clss)
{
Actor actor = getOneObjectAtOffset(0, 0, clss);
if(actor != null) {
getWorld().removeObject(actor);
}
}
I don't know! Someone can help me??
Thank you!!

