Exemple #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);
      }
    }
  }
Exemple #2
0
  private void addEnemiesToTowerQueues() {

    for (ITower tower : towers) {
      tower.clearQueue();

      for (Enemy enemy : enemies) {
        if (enemy.isDead() || enemy.getUserData() == "dead") continue;

        if (tower.inSights(enemy.getXReal(), enemy.getYReal())) {
          tower.addEnemyToQueue(enemy);
        }
      }
    }
  }
Exemple #3
0
  /** Each tower fires at the first enemy in their respective queue Runs every .025 seconds */
  private void collisionDetect() {

    for (ITower t : towers) {
      Enemy enemy = t.getLockedOn();

      if (enemy == null) {
        t.onIdleInWave();
        continue;
      }

      if (enemy.isDead()) {
        t.removeEnemyFromQueue(enemy);
        continue;
      }

      if (t.inSights(enemy.getXReal(), enemy.getYReal())) {

        t.onImpact(enemy);
        t.shoot(enemy);

        /** TODO: Make a "canRotate" variable for each class so this isn't such a hack */
        if (t.getClass() == IceTower.class || t.getClass() == SpikeTower.class) continue;

        dx = t.getEntity().getX() - (enemy.getX() - enemy.getWidthScaled() / 3.5f);
        dy = t.getEntity().getY() - (enemy.getY() - enemy.getHeightScaled() / 3.5f);
        angle = MathUtils.atan2(dy, dx);
        realAngle = (float) (angle * (180.0f / Math.PI));
        t.getEntity().setRotation(realAngle);
      } else {
        t.removeEnemyFromQueue(enemy);
        t.onEnemyOutOfRange(enemy);
      }
    }
  }
Exemple #4
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);
      }
    }
  }
Exemple #5
0
  /** Initializes paths and move modifiers of all enemies in the next wave */
  public void initializeNextWave() {

    Log.i("Init wave", "here");

    // If the previous wave was eliminated even before all enemies technically started, the time
    // handler
    // that handles their first move modifier would never get unregistered, putting the game in
    // limbo
    this.unregisterUpdateHandler(waveGenerator.getTimeHandler());

    if (startButton.getCurrentTileIndex() > 1)
      startButton.setCurrentTileIndex(startButton.getCurrentTileIndex() - 2);

    // The player wins the game!!
    if (waveCount == 70 && lives != 0) {
      displayWinScreen();
      return;
    }

    waveGenerator.initWave(waveCount);
    currentWave = waveGenerator.get(waveCount);
    enemies = (CopyOnWriteArrayList<Enemy>) currentWave.getEnemies();
    waveCount++;
    panel.setWaveText(waveCount);

    this.aStarHelper.finishWave();
    this.deadEnemies = 0;

    /** Just for debugging */
    for (Enemy enemy : currentWave.getEnemies()) {
      if (enemy == null) continue;
      enemy.setUserData(null);
      enemy.returnHealthToNormal();
    }
    for (ITower tower : towers) {
      tower.onWaveEnd();
    }
  }