public void update() { if (getJustDied()) { // for loop to give out lots of food and to take away a body part FoodEntityLevel1 entity = new FoodEntityLevel1( getXFromCenterToRear(TAIL_DISTANCE * 5), getYFromCenterToRear(TAIL_DISTANCE * 5)); NonHostileAIController controller = new NonHostileAIController(entity); entity.setController(controller); entity.setWorld(getWorld()); getWorld().addEntity(entity); setJustDied(false); } if (!checkDead()) { super.update(); Entity inFront = this; Entity temp; for (int i = 0; i < getBodyParts().size(); i++) { temp = getBodyParts().get(i); temp.setTarget(inFront.getRearX(), inFront.getRearY()); temp.setAngle(temp.getTargetAngle()); temp.setMaxVelocity(inFront.getMaxVelocity()); temp.setVelocity(inFront.getVelocity()); if (inFront.getDistance(temp) >= FAT_DISTANCE) temp.update(); inFront = temp; } } else if (getController().getType() == Controller.PLAYER) { setJustDied(true); setDead(false); addValue(50); LevelChangerEntity entity = new LevelChangerEntity(getX(), getY()); entity.setValue(-1); entity.setDead(true); entity.setWorld(getWorld()); getWorld().addEntity(entity); } if (digesting) { currTime = timer.milliTime(); accumulator += currTime - prevTime; prevTime = currTime; if (digesting && (accumulator > TIME_TO_DIGEST)) { digesting = false; mouth.setClosed(false); timer.reset(); accumulator = 0; getWorld().checkCollisions(this); } } else getWorld().checkCollisions(this); if (enlargedMouth) { if (mouthTimer.milliTime() > MOUTH_TIME) shrinkMouth(); } mouth.update(); }
public void spawnExcrement(int value) { Entity entity = null; Vector<Entity> fats = getBodyParts(); Entity last = fats.get(fats.size() - 1); switch (value) { case 50: entity = new FoodEntityLevel1(); break; case 100: entity = new FoodEntityLevel2(); break; case 150: entity = new FoodEntityLevel3(); break; case 200: entity = new FoodEntityLevel4(); break; case 250: entity = new FoodEntityLevel5(); break; } if (entity != null) { entity.setX(last.getRearX()); entity.setY(last.getRearY()); NonHostileAIController controller = new NonHostileAIController(entity); entity.setController(controller); entity.setWorld(getWorld()); getWorld().addEntity(entity); } }
/** * adds a fat. * * @param value fat's value. * @param big fat's size. */ public void addFat(int value, boolean big) { Entity inFront = getBodyParts().get(getBodyParts().size() - 1); Fat temp = new Fat(value, big); temp.setFrontX(inFront.getRearX()); temp.setY(inFront.getYFromCenterToRear(FAT_DISTANCE + NECK_RADIUS)); addBodyPart(temp); }
@Override public int addValue(int value) { for (Entity e : getBodyParts()) value = e.addValue(value); if (value > 0) { value -= 50; Vector<Entity> fats = getBodyParts(); Entity last = fats.get(fats.size() - 1); if (fats.size() < MAX_FATS) { Fat fat = new Fat(); fat.setAngle(last.getAngle()); fat.setFrontX(last.getRearX()); fat.setY(last.getYFromCenterToRear(FAT_DISTANCE + NECK_RADIUS)); fat.setMaxVelocity(0); addBodyPart(fat); } else for (int i = 0; i < fats.size(); ++i) if (!((Fat) fats.get(i)).getBig()) { ((Fat) fats.get(i)).setBig(true); break; } for (int i = 0; i < fats.size(); ++i) fats.get(i).setValue(((Fat) fats.get(i)).getBig() ? 50 : 0); } if (value > 0) spawnExcrement(value); return 0; }
public EelEntity(int x, int y) { this(); setX(x); setY(y); Entity inFront = this; Entity temp; for (int i = 0; i < getBodyParts().size(); i++) { temp = getBodyParts().get(i); temp.setAngle(inFront.getAngle()); temp.setFrontX(inFront.getRearX()); temp.setY(inFront.getYFromCenterToRear(FAT_DISTANCE + NECK_RADIUS)); temp.setMaxVelocity(0); inFront = temp; } setTurningSpeed(getTurningSpeed() * 1.5); setValue(getValue()); }