Can anyone make this actor move automatically forward 60px and back 60px like super mario
Heres the code:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class GoldenBall here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Lobster extends Actor
{
/**
* Act - do whatever the GoldenBall wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
checkGoldenBall();
}
public boolean canMove(int x, int y)
{
Actor sand;
sand=getOneObjectAtOffset(x,y,sandroad.class);
//the section below checks if there is a block you can move to
// if there is it sets sand to a vlaue otherwise it says null
// The errors are in this section
boolean flag=false;
if (sand !=null)
{
flag=true;
}
return flag;
}
/**
* Check if Lobster eats the ball
*/
private void checkGoldenBall()
{
Actor GoldenBall= getOneIntersectingObject(GoldenBall.class);
if (GoldenBall !=null )
{
getWorld().removeObject(GoldenBall);
}
}
}

