Esempio n. 1
0
  /**
   * When placing a tower on the field, this checks if the path needs to be updated for each enemy
   *
   * @param current
   * @param inMiddleOfWave
   */
  private void updateAffectedEnemies(TMXTile current, boolean inMiddleOfWave) {
    List<Enemy> enemies = currentWave.getEnemies();
    Path p;
    float pX;
    float pY;
    outer:
    for (Enemy enemy : enemies) {
      if (enemy == null) continue;
      p = enemy.getPath();
      for (int i = 0; i < p.getCoordinatesX().length; i++) {
        pX = p.getCoordinatesX()[i];
        pY = p.getCoordinatesY()[i];

        TMXTile tile = this.tmxLayer.getTMXTileAt(pX - enemy.getOffsetX(), pY - enemy.getOffsetY());
        if (current.equals(tile)) {
          updateEnemyPaths(inMiddleOfWave, enemy);
          if (!inMiddleOfWave) break outer;
          else break;
        }
      }
    }

    if (inMiddleOfWave) {
      Enemy dummy = new Enemy();
      dummy.setUserData("dummy");
      Path path = aStarHelper.getPath(dummy);

      if (path == null) {
        removeCurrentTower(true);
      }
    }
  }
Esempio n. 2
0
 /**
  * This just makes sure the drag tower isn't set on the start tile, end tile, or any tile already
  * occupied by another tower. There is still the fact that a player can place a tower that will
  * block the enemies in.
  *
  * <p>I am taking a reactive approach to this scenario since it is just too costly to recalculate
  * the enemy paths for each tile the dragtower is placed.
  *
  * @param currentTile
  * @return
  */
 private boolean inLegitimatePosition(TMXTile currentTile) {
   return !(currentTile.equals(endTile)
       || currentTile.equals(startTile)
       || blockedTileList.contains(currentTile));
 }