i want to make it possibel for the crab to hide behind another object, and make sure the lobster cant eat it when its hidding, i use the lookForCrab metod from the book. Any suggestion to how i can make the code???
//in your crab class; public boolean isProtected() { return getOneIntersectingObject(Protector.class) != null; } //instead of Protector you should use the classname of the object with which you want to crab to protected.
//in the eat method of your lobster class; public void eat(Class clss) { Actor actor = getOneObjectAtOffset(0, 0, clss); if(actor != null) { if (actor instanceof Crab && !((Crab) actor).isProtected()) { getWorld().removeObject(actor); } else { getWorld().removeObject(actor); } }
public void lookForMouse() { Mouse mouse = (Mouse) getOneObjectAtOffset(0,0, Mouse.class); if(mouse != null && !mouse.isProtected()) { getWorld().removeObject(mouse); } }