Esempio n. 1
0
  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();
    }
  }
Esempio n. 2
0
  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();
  }
Esempio n. 3
0
  /** Enlarges the Eel's mouth. */
  public void enlargeMouth() {
    if (enlargedMouth) return;

    mouthTimer.reset();
    mouthTimer.start();
    mouth.setMaxWidth(MOUTH_WIDTH * 2);
    mouth.setHeight(MOUTH_HEIGHT * 2);
    mouth.setClosed(false);
    this.setRadius(getRadius() * 2);
    enlargedMouth = true;
  }