@Override
 public void layout() {
   image.setPosition(0, 0);
   image.setSize(64, 64);
   txtName.setPosition(64, getPrefHeight() - txtName.getPrefHeight() - 5);
   txtName.setSize(txtName.getPrefWidth(), txtName.getPrefHeight());
   txtSoul.setPosition(64, txtName.getY() - txtSoul.getPrefHeight() + 5);
   txtSoul.setSize(txtSoul.getPrefWidth(), txtSoul.getPrefHeight());
 }
Esempio n. 2
0
  @Override
  public void show() {
    super.show();

    // Game-Labels initialisieren
    timeLabel.setFontScale(0.5f);
    timeLabel.setPosition(
        SCREEN_WIDTH - (timeLabel.getPrefWidth() * 3), SCREEN_HEIGHT - timeLabel.getPrefHeight());
    uiStage.addActor(timeLabel);

    livesLabel.setFontScale(0.5f);
    livesLabel.setPosition(
        SCREEN_WIDTH - (timeLabel.getPrefWidth() * 4) - livesLabel.getPrefWidth(),
        SCREEN_HEIGHT - livesLabel.getPrefHeight());
    uiStage.addActor(livesLabel);
  }
Esempio n. 3
0
 public TextLabel(String title, Color color, BitmapFont font, int align) {
   style = new Label.LabelStyle(font, color);
   label = new Label(title, style);
   label.setAlignment(align);
   addActor(label);
   this.setSize(label.getPrefWidth(), label.getPrefHeight());
 }
Esempio n. 4
0
 public TextLabel(String title, Color color) {
   style = new Label.LabelStyle(Assets.getInstance().getMidFont(), color);
   label = new Label(title, style);
   label.setAlignment(Align.center);
   addActor(label);
   this.setSize(label.getPrefWidth(), label.getPrefHeight());
 }
Esempio n. 5
0
  @Override
  public void render(float delta) {
    Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    camera.update();
    batch.setProjectionMatrix(camera.combined);
    batch.begin();

    backgroundImage.draw(batch, 1);
    preUIrender(delta);

    batch.end();

    // Update FPS-Counter
    fpsLabel.setText("FPS: " + String.valueOf(Gdx.graphics.getFramesPerSecond()));
    fpsLabel.setPosition(
        uiStage.getWidth() - fpsLabel.getPrefWidth(),
        uiStage.getHeight() - fpsLabel.getPrefHeight() / 2);

    uiStage.act(delta);
    uiStage.draw();
  }
Esempio n. 6
0
  @Override
  public void preUIrender(float delta) {
    // Game-Labels updaten
    timeLabel.setText("TIME: " + String.valueOf((System.currentTimeMillis() - startTime) / 1000));
    timeLabel.setPosition(0, uiStage.getHeight() - timeLabel.getPrefHeight() / 2);

    livesLabel.setText("LIVES: " + String.valueOf(player.getLives()));
    livesLabel.setPosition(
        (uiStage.getWidth() / 2) - (livesLabel.getPrefWidth() / 2),
        uiStage.getHeight() - timeLabel.getPrefHeight() / 2);

    // Kamera auf Spieler-X ausrichten, auf Map setzen und Map rendern
    float playerCenterPos = player.getX() + player.getEntityWidth() / 2;
    boolean playerOutLeft = playerCenterPos < (SCREEN_WIDTH / 2);
    boolean playerOutRight =
        playerCenterPos > (getMap().getMapWidthAsScreenUnits() - (SCREEN_WIDTH / 2));

    if (!playerOutLeft && !playerOutRight)
      camera.position.x = player.getX() + player.getEntityWidth() / 2;
    else {
      if (playerOutLeft) camera.position.x = SCREEN_WIDTH / 2;
      else camera.position.x = getMap().getMapWidthAsScreenUnits() - (SCREEN_WIDTH / 2);
    }
    camera.update();

    OrthogonalTiledMapRenderer renderer = map.getRenderer();
    renderer.setView(camera);
    renderer.render();

    renderer.getSpriteBatch().begin();

    // Spieler rendern
    player.render(renderer.getSpriteBatch());

    for (AbstractEntity enemy : entityList) {
      // Position des Players:
      float playerWidthPosXLeft = player.getX();
      float playerHeightPosLeft = player.getY();
      // Position des Gegners:
      float enemyWidthPosXLeft = enemy.getX();
      float enemyHeightPosYLeft = enemy.getY();
      // Initialisierung der Spieler-Box und Gegner-Box
      PlayerBox =
          new Rectangle(
              playerWidthPosXLeft, playerHeightPosLeft, player.getWidth(), player.getHeight());
      EnemyBox =
          new Rectangle(
              enemyWidthPosXLeft, enemyHeightPosYLeft, enemy.getWidth(), enemy.getHeight());

      // Gegner rendern
      enemy.render(renderer.getSpriteBatch());

      // Kollisionsfunktion zwischen dem Spieler und Gegnern
      BoxCollides(PlayerBox, EnemyBox);
    }

    // Entitys rendern
    for (AbstractEntity entity : poolableEntityList) entity.render(renderer.getSpriteBatch());

    renderer.getSpriteBatch().end();
  }
Esempio n. 7
0
 public void setText(String text) {
   label.setText(text);
   this.setSize(label.getPrefWidth(), label.getPrefHeight());
 }