Exemplo n.º 1
0
 private void updateBreathBar(
     DrownsComponent drownsComponent, DrowningComponent drowningComponent) {
   if (drownsComponent != null && drowningComponent != null) {
     float breath = drowningComponent.getPercentageBreath(time.getGameTimeInMs());
     if (breath <= 0) {
       for (UIImage breathBubble : breathBubbles) {
         breathBubble.setVisible(true);
         breathBubble.setTextureOrigin(new Vector2f(25f, 18f));
       }
     } else {
       breath *= NUM_BUBBLE_ICONS;
       for (int i = 0; i < breathBubbles.length; ++i) {
         breathBubbles[i].setVisible(true);
         if (NUM_BUBBLE_ICONS - i - 1 < breath) {
           breathBubbles[i].setTextureOrigin(new Vector2f(16f, 18f));
         } else {
           breathBubbles[i].setTextureOrigin(new Vector2f(25f, 18f));
         }
       }
     }
   } else {
     for (UIImage breathBubble : breathBubbles) {
       breathBubble.setVisible(false);
     }
   }
 }
Exemplo n.º 2
0
  /** Init. the HUD. */
  public UIScreenHUD() {
    setId("hud");
    maximize();
    time = CoreRegistry.get(Time.class);

    // Create hearts
    hearts = new UIImage[NUM_HEART_ICONS];
    for (int i = 0; i < NUM_HEART_ICONS; i++) {
      hearts[i] = new UIImage(Assets.getTexture("engine:icons"));
      hearts[i].setVisible(true);
      hearts[i].setTextureSize(new Vector2f(9f, 9f));
      hearts[i].setTextureOrigin(new Vector2f(52f, 0.0f)); // 106f for poison
      hearts[i].setSize(new Vector2f(18f, 18f));
      hearts[i].setVerticalAlign(EVerticalAlign.BOTTOM);
      hearts[i].setHorizontalAlign(EHorizontalAlign.CENTER);
      hearts[i].setPosition(new Vector2f(18f * i - 212f, -52f));

      addDisplayElement(hearts[i]);
    }

    breathBubbles = new UIImage[NUM_BUBBLE_ICONS];
    for (int i = 0; i < NUM_BUBBLE_ICONS; ++i) {
      breathBubbles[i] = new UIImage(Assets.getTexture("engine:icons"));
      breathBubbles[i].setVisible(true);
      breathBubbles[i].setTextureSize(new Vector2f(9f, 9f));
      breathBubbles[i].setTextureOrigin(new Vector2f(16f, 18f));
      breathBubbles[i].setSize(new Vector2f(18f, 18f));
      breathBubbles[i].setVerticalAlign(EVerticalAlign.BOTTOM);
      breathBubbles[i].setHorizontalAlign(EHorizontalAlign.CENTER);
      breathBubbles[i].setPosition(new Vector2f(-18f * i + 210f, -52f));

      addDisplayElement(breathBubbles[i]);
    }

    crosshair = new UIImage(Assets.getTexture("engine:gui"));
    crosshair.setId("crosshair");
    crosshair.setTextureSize(new Vector2f(20f, 20f));
    crosshair.setTextureOrigin(new Vector2f(24f, 24f));
    crosshair.setSize(new Vector2f(40f, 40f));
    crosshair.setHorizontalAlign(EHorizontalAlign.CENTER);
    crosshair.setVerticalAlign(EVerticalAlign.CENTER);
    crosshair.setVisible(true);

    addDisplayElement(crosshair);

    localPlayer = CoreRegistry.get(LocalPlayer.class);

    update();
    layout();
  }
Exemplo n.º 3
0
  /** Init. the HUD. */
  public UIScreenHUD() {
    maximize();

    _hearts = new UIImage[10];

    // Create hearts
    for (int i = 0; i < 10; i++) {
      _hearts[i] = new UIImage(AssetManager.loadTexture("engine:icons"));
      _hearts[i].setVisible(true);
      _hearts[i].setTextureSize(new Vector2f(9f, 9f));
      _hearts[i].setTextureOrigin(new Vector2f(52f, 0.0f)); // 106f for poison
      _hearts[i].setSize(new Vector2f(18f, 18f));
      _hearts[i].setVerticalAlign(EVerticalAlign.BOTTOM);
      _hearts[i].setHorizontalAlign(EHorizontalAlign.CENTER);
      _hearts[i].setPosition(new Vector2f(18f * i - 212f, -52f));

      addDisplayElement(_hearts[i]);
    }

    crosshair = new UIImage(AssetManager.loadTexture("engine:gui"));
    crosshair.setTextureSize(new Vector2f(20f, 20f));
    crosshair.setTextureOrigin(new Vector2f(24f, 24f));
    crosshair.setSize(new Vector2f(40f, 40f));
    crosshair.setHorizontalAlign(EHorizontalAlign.CENTER);
    crosshair.setVerticalAlign(EVerticalAlign.CENTER);
    crosshair.setVisible(true);

    debugLine1 = new UIText();
    debugLine1.setPosition(new Vector2f(4, 4));
    debugLine2 = new UIText();
    debugLine2.setPosition(new Vector2f(4, 22));
    debugLine3 = new UIText();
    debugLine3.setPosition(new Vector2f(4, 38));
    debugLine4 = new UIText();
    debugLine4.setPosition(new Vector2f(4, 54));

    toolbar = new UIItemContainer(9);
    toolbar.setVisible(true);
    toolbar.setHorizontalAlign(EHorizontalAlign.CENTER);
    toolbar.setVerticalAlign(EVerticalAlign.BOTTOM);

    minionbar = new UIMinionbar();
    minionbar.setVisible(true);

    messagequeue = new UIMessageQueue();
    messagequeue.setVisible(true);

    buffBar = new UIBuff();
    buffBar.setVisible(true);

    addDisplayElement(crosshair, "crosshair");
    addDisplayElement(debugLine1);
    addDisplayElement(debugLine2);
    addDisplayElement(debugLine3);
    addDisplayElement(debugLine4);

    addDisplayElement(toolbar);
    addDisplayElement(minionbar);
    addDisplayElement(messagequeue);
    addDisplayElement(buffBar);

    CoreRegistry.get(EventSystem.class).registerEventHandler(this);

    update();
    layout();
  }