Esempio n. 1
0
  @Override
  public void draw(Batch batch, float alpha) {

    if (!isPositionSet()
        && getParent().getStage() != null
        && positionXOffsetWidth != 0
        && positionYOffsetHeight != 0) {

      // Reposition when health is decreased
      setPositionSet(true);
      halfParentWidth = (getParent().getStage().getWidth() / 2);
      parentHeight = getParent().getStage().getHeight();

      topLeftWingX = halfParentWidth - (topLeftWingSprite.getWidth() + (positionXOffsetWidth / 4));
      topLeftWingY = (parentHeight - topLeftWingSprite.getHeight()) - (positionYOffsetHeight / 5);

      backBarX = halfParentWidth - (backBarSprite.getWidth() + (positionXOffsetWidth / 2.73f));
      backBarY = (parentHeight - backBarSprite.getHeight()) - (positionYOffsetHeight / 3.97f);

      bottomLeftWingX =
          halfParentWidth
              - (bottomLeftWingSprite.getWidth() * 1.1f - (positionXOffsetWidth / 50.5f));

      bottomLeftWingY =
          topLeftWingY
              - (bottomLeftWingSprite.getHeight() * 1.30f)
              + (positionYOffsetHeight / 175.7f);

      healthBarX = halfParentWidth - (healthBarSprite.getWidth() + (positionXOffsetWidth / 3.4f));
      healthBarY = (parentHeight - healthBarSprite.getHeight()) - (positionYOffsetHeight / 4.1f);

      healthBarSprite.setPosition(healthBarX, healthBarY);
      topLeftWingSprite.setPosition(topLeftWingX, topLeftWingY);
      backBarWarningSprite.setPosition(backBarX, backBarY);
      bottomLeftWingSprite.setPosition(bottomLeftWingX, bottomLeftWingY);
      backBarSprite.setPosition(backBarX, backBarY);

      lifeManager.setStartingXPosition(bottomLeftWingX + (bottomLeftWingSprite.getWidth() / 4.5f));
      lifeManager.setStartingYPosition(bottomLeftWingY + (bottomLeftWingSprite.getHeight() / 5f));

      // Turn on health warning
      if (!warningMode && totalHealth < HEALTH_WARNING_AMOUNT) {
        warningMode = true;
      } else if (warningMode && totalHealth >= HEALTH_WARNING_AMOUNT) {
        warningMode = false;
        backBarSprite.setTexture(backBarTexture);
      }
    }

    if (warningMode) {
      elapsedTime += Gdx.graphics.getDeltaTime();
      backBarWarningSprite.setRegion(backbarAnimation.getKeyFrame(elapsedTime, true));
      backBarWarningSprite.draw(batch);
    } else {
      backBarSprite.draw(batch);
      ;
    }

    healthBarSprite.draw(batch);

    game.getCurrentGameScreen().getLevel().armorBar.drawArmor(batch, alpha);

    topLeftWingSprite.draw(batch);
    bottomLeftWingSprite.draw(batch);
    lifeManager.draw(batch, alpha);
  }