Exemplo n.º 1
0
  @Override
  public List<ConsoleManager.ConsoleCommand> getConsoleCommands() {
    List<ConsoleManager.ConsoleCommand> outList = new ArrayList<>();
    outList.addAll(player.getConsoleCommands());

    return outList;
  }
Exemplo n.º 2
0
  private void BoxCollides(Rectangle playerBox, Rectangle enemyBox) {
    if (overlaps(playerBox, enemyBox)) {
      Rectangle r1 = playerBox;
      Rectangle r2 = enemyBox;
      Rectangle intersection = new Rectangle();
      Intersector.intersectRectangles(r1, r2, intersection);
      // Player intersects with bottom side
      if (intersection.y + intersection.height < r1.y + r1.height) {

      }
      // Player intersects with right side
      else if (intersection.x > r1.x) {
        player.takeDamage(1);
      }
      // Player intersects with top side
      else if (intersection.y > r1.y) {
        player.takeDamage(1);
      }
      // Player intersects with left side
      else if (intersection.x + intersection.width < r1.x + r1.width) {
        player.takeDamage(1);
      }
    }
  }
Exemplo n.º 3
0
  public GameScreen(Jalf jalf, Map map) {
    super(jalf);
    this.map = map;
    this.timeLabel = new Label("", skin, "ingame-font", Color.BLACK);
    this.livesLabel = new Label("", skin, "ingame-font", Color.BLACK);

    // Maprenderer initialisieren
    Gdx.app.log(
        LOG,
        "Loading "
            + (map.isDefault() ? "defaultmap " : "usermap ")
            + map.getName()
            + " from "
            + map.getPath());
    boolean mapIsValid = map.loadMap();

    // Spieler initialisieren
    player =
        new Player(
            map.getSpawnPosition().x * UNITSCALE,
            map.getSpawnPosition().y * UNITSCALE,
            10,
            10,
            3,
            15,
            3,
            5,
            this);
    player.addListener(this);
    addInputProcessor(player);

    // Gegnerliste initialisieren
    entityList = new ArrayList<AbstractEntity>();
    for (Vector2 spawn : map.getMobSpawnPositions()) {
      entityList.add(new Enemyredstickman001(spawn.x * UNITSCALE, spawn.y * UNITSCALE, this));
    }
    // Poolable Entity List
    poolableEntityList = new ArrayList<AbstractEntity>();

    // Startzeit festlegen
    startTime = System.currentTimeMillis();
  }
Exemplo n.º 4
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();
  }