Esempio n. 1
0
 /** Is any part of the lowest enemy ship on the players row? */
 private void calculateEnemyReachingPlayer() {
   int y = EnemyHandler.getSmallestY(enemies);
   if (y < player1.y + player1.height) {
     System.out.println("******************");
     System.out.println("Smallest Y: " + y);
     System.out.println("Player X: " + player1.x);
     System.out.println("Player Y: " + player1.y);
     gameStatus = GameConstants.GAME_STATUS_OUTRO;
   }
 }
Esempio n. 2
0
  /**
   * Calculates the minimun number of steps left for enemies to reach player
   *
   * @return
   */
  private int calculateStepsLeft() {
    boolean goingRight = enemies.get(0).goingRight;
    int smallestX = EnemyHandler.getSmallestX(enemies);
    int largestX = EnemyHandler.getLargestX(enemies);
    int smallestY = EnemyHandler.getSmallestY(enemies);
    int width = currentLevel.getEnemyWidth();
    int height = currentLevel.getEnemyHeight();
    int stepsLeftOnRow = 0;

    if (goingRight) {
      stepsLeftOnRow = (GameConstants.WINDOW_WIDTH - (largestX + width)) / width;
    } else {
      stepsLeftOnRow = smallestX / width;
    }

    int stepsOnEachRow = (GameConstants.WINDOW_WIDTH - (largestX + width - smallestX)) / width;

    int rowsLeft = (smallestY - player1.height) / height;

    return stepsLeftOnRow + (stepsOnEachRow * rowsLeft) + rowsLeft;
  }
Esempio n. 3
0
  /**
   * Sets (or resets) game variables And loads level data
   *
   * @param levelNo
   */
  public void loadLevel(int levelNo) {
    score = 0;
    startTime = System.currentTimeMillis();
    lastShot = -shotTime;
    lastEnemyUpdate = 0;
    projectiles = new ArrayList<>();
    animationFrame = 1;
    /*if(enemies != null)
    enemies.clear();*/
    enemies = new ArrayList<>();

    if (levelNo == 1) {
      currentLevel = new Level1Data();
      enemies = spawnPit.getEnemies(currentLevel, imageHandler);
    }

    explosions = new ArrayList<>();

    int pWidth = currentLevel.getPlayerWidth();
    int pHeight = currentLevel.getPlayerHeight();
    player1 =
        new Player(
            (GameConstants.WINDOW_WIDTH / 2) - pWidth / 2,
            10,
            pWidth,
            pHeight,
            imageHandler.getTexture(ImageConstants.PLAYER),
            imageHandler.getTexture(ImageConstants.PLAYER_LEFT),
            imageHandler.getTexture(ImageConstants.PLAYER_RIGHT));

    gameStatus = GameConstants.GAME_STATUS_INTRO;
    int smallY = EnemyHandler.getSmallestY(enemies);
    intro_enemy_offset = GameConstants.WINDOW_HEIGHT - smallY + intro_speed;
    intro_player_offset = player1.y + 1 + player1.height;

    if (enemy_hero != null) {
      enemy_hero = null;
    }
  }