Esempio n. 1
0
  /**
   * This method actually notifies which enemies need to update their paths
   *
   * @param inMiddleOfWave
   * @param enemy
   */
  private void updateEnemyPaths(boolean inMiddleOfWave, Enemy enemy) {
    if (inMiddleOfWave) {
      Log.i("Updating path", "Updating path");
      enemy.setNeedToUpdatePath(true);

      for (Enemy child : enemy.childArray) {
        child.setNeedToUpdatePath(true);
      }

    } else {

      Path p = null;
      Enemy en = null;
      for (Enemy e : currentWave.getEnemies()) {
        if (e.getClass() != BeachballEnemy.class) {
          p = aStarHelper.getPath(e);
          en = e;
          break;
        }
      }

      // We have a wave full of beach-ball enemies
      if (en == null) return;

      if (p == null) {
        removeCurrentTower(true);
        p = aStarHelper.getPath(en);
      }

      for (Enemy e : currentWave.getEnemies()) {
        if (e.getClass() != BeachballEnemy.class) e.setPath(p.deepCopy());
        else aStarHelper.getPath(e);
      }
    }
  }
Esempio n. 2
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);
      }
    }
  }