When one of my objects eats another, the image is off based on the position of where the object eats the other object. So, half of the image that is supposed to be eating the other object will just pass through it harmlessly. What should I do?
Here is the code.
public void act()
{
lookForMarble();
checkForEdge();
getWorld();
}
public void checkForEdge()
{
if (atWorldEdge() )
{
getWorld().removeObject(this);
}
else
{
setLocation(getX(), getY() - 5);
}
}
public boolean atWorldEdge()
{
if(getX() < 20 || getX() > getWorld().getWidth() - 20)
return true;
if(getY() < 20 || getY() > getWorld().getHeight() - 20)
return true;
else
return false;
}
public boolean canSee(Class clss)
{
Actor actor = getOneObjectAtOffset(65, 0, clss);
return actor != null;
//Coding from "Little Crab"
}
public void eat(Class clss)
{
Actor actor = getOneObjectAtOffset(65, 0, clss);
if(actor != null) {
getWorld().removeObject(actor);
}
}
public void lookForMarble()
{
if ( canSee(Marble.class) )
{
eat (Marble.class);
//Coding from "Little Crab"
Greenfoot.stop();
}
}
}
