public void collision(Entity entity) { if (entity.getType() == LEVEL_CHANGER && getController() instanceof PlayerController) { getWorld().changeLevel(entity.getValue()); digesting = true; mouth.setClosed(true); timer.start(); prevTime = timer.milliTime(); } for (int x = 0; x < getBodyParts().size(); x++) if (entity == getBodyParts().get(x)) return; if (entity.getType() == FAT) { addValue(entity.removeValue()); setValue(getValue()); digesting = true; mouth.setClosed(true); timer.start(); prevTime = timer.milliTime(); } else if (entity.getType() == FOOD) { addValue(entity.removeValue()); setValue(getValue()); digesting = true; mouth.setClosed(true); timer.start(); prevTime = timer.milliTime(); } else if (entity.getType() == EVOLVER) { if (entity.getValue() == EvolverEntity.EVOLVER_VAL) evolve(); else if (entity.getValue() == EvolverEntity.MOUTH_VAL) enlargeMouth(); } }
@Override public int getValue() { int temp = 0; for (Entity e : getBodyParts()) if (((Fat) e).getBig() && ((Fat) e).getEdible()) temp += e.getValue(); return temp; }
public boolean evolve() { // Need to evolve // Go to the last fat that has a value and evolve // If this fat is fully evolved then evolve the first fat that // is not fully evolved, starting with the one behind the mouth. // Health of fat is disregarded. Vector<Entity> fats = getBodyParts(); Entity aFat; boolean evolved; for (int i = fats.size() - 1; i >= 0; --i) { aFat = fats.get(i); if (aFat.getValue() > 0) { if (aFat.evolve()) return true; else { for (int x = 0; x < fats.size(); ++x) { aFat = fats.get(x); if (aFat.evolve()) return true; } } } } return false; }