So I'm trying to make it so when one projectile turn towards a apple or cactus. But when I run it the number goes up until its the max number. The snake makes a new projectile and depending what button is pressed it either goes for the apples or the cacti. If you want the snake code, just tell me.
public boolean toGetTF; Snake sn = new Snake(); //int maxCac = getWorld().getObjects(Cactus.class).size(); //int maxApp = getWorld().getObjects(Apple.class).size(); public void act() { move(2); if(isAtEdge()) { getWorld().removeObject(this); } try{ Actor en = getOneIntersectingObject(Cactus.class); if (en!=null && toGetTF){ getWorld().removeObject(en); getWorld().removeObject(this); setCactus(getCactus()-1); } Actor en2 = getOneIntersectingObject(Apple.class); if (en2!=null&& !toGetTF){ getWorld().removeObject(en2); getWorld().removeObject(this); setApple(getApple()-1); } whoToGet(); }catch(IllegalStateException ill){}catch(NullPointerException nul){}catch(IndexOutOfBoundsException iob){} } public void whoToGet(){ // make it so the number is in another class so i can get the nubmer like that if(toGetTF){ System.out.println(getCactus()); turnTowards(getWorld().getObjects(Cactus.class).get(getCactus()).getX(), getWorld().getObjects(Cactus.class).get(getCactus()).getY()); setCactus(getCactus()+1); }else{ System.out.println(getApple()); turnTowards(getWorld().getObjects(Apple.class).get(getApple()).getX(), getWorld().getObjects(Apple.class).get(getApple()).getY()); setApple(getApple()+1); } } public int getCactus(){ return sn.cactusNum; } public void setCactus(int given){ sn.cactusNum = given; } public int getApple(){ return sn.appleNum; } public void setApple(int given){ sn.appleNum = given; }