Beispiel #1
0
  @Override
  public void update(float elapsed) {
    if (!isInNetwork && health.isDead()) {
      terminate();
      return;
    }

    regenerate();
    spellManager.update(elapsed);

    ElementalShield curShield = spellManager.getCurrentShield();
    if (curShield != null && curShield.getElementType() == ElementType.Fire)
      manager.handleAreaOfEffectSpell(
          this, curShield.getDamage(), ElementType.Fire, curShield.getAOErect());

    if (state == DynamicObjectState.Attacking) {
      curAnim.update(elapsed);
      return;
    }

    if (state == DynamicObjectState.Hit) {
      curAnim.update(elapsed);
      curHitDuration -= 1;
      if (curHitDuration <= 0) {
        setState(DynamicObjectState.Idle);
        curHitDuration = maxHitDuration;
        health.setInvul(false);
      }

      return;
    }

    if (controllerActive) handleControllerInput(elapsed);

    // DEBUG PURPOSE
    if (controllerActive) {
      if (controller.isPressed(KeyEvent.VK_SHIFT)) supressEnemyCollision = true;
      else supressEnemyCollision = false;
    }
    // -------------

    if (velocity.x > 0.01f || velocity.x < -0.01f || velocity.y > 0.01f || velocity.y < -0.01f) {
      collisionRect.x += velocity.x;
      collisionRect.y += velocity.y;

      boolean collidingStatic = collision.isCollidingStatic(this);
      boolean collidingDynamic = false;
      if (!supressEnemyCollision) collidingDynamic = collision.isCollidingDynamic(this);

      if (collidingStatic || collidingDynamic) {
        collisionRect.x -= velocity.x;
        collisionRect.y -= velocity.y;
        stopMovement();
      } else {
        collision.checkTriggers(this);
        screenPosition.x += velocity.x;
        screenPosition.y += velocity.y;
        curAnim.update(elapsed);
      }
    }

    if (isInNetwork && controllerActive) {
      sendPositionMessage();
    }
  }