Example #1
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);
      }
    }
  }
Example #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);
        }
      }
    }
  }