예제 #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);
      }
    }
  }
  @Override
  protected void onUpdateControlKnob(final float pRelativeX, final float pRelativeY) {
    if (pRelativeX == 0 && pRelativeY == 0) {
      super.onUpdateControlKnob(0, 0);
      return;
    }

    if (this.mAllowDiagonal) {
      final float angle = MathUtils.radToDeg(MathUtils.atan2(pRelativeY, pRelativeX)) + 180;
      if (DigitalOnScreenControl.testDiagonalAngle(0, angle)
          || DigitalOnScreenControl.testDiagonalAngle(360, angle)) {
        super.onUpdateControlKnob(-EXTENT_SIDE, 0);
      } else if (DigitalOnScreenControl.testDiagonalAngle(45, angle)) {
        super.onUpdateControlKnob(-EXTENT_DIAGONAL, -EXTENT_DIAGONAL);
      } else if (DigitalOnScreenControl.testDiagonalAngle(90, angle)) {
        super.onUpdateControlKnob(0, -EXTENT_SIDE);
      } else if (DigitalOnScreenControl.testDiagonalAngle(135, angle)) {
        super.onUpdateControlKnob(EXTENT_DIAGONAL, -EXTENT_DIAGONAL);
      } else if (DigitalOnScreenControl.testDiagonalAngle(180, angle)) {
        super.onUpdateControlKnob(EXTENT_SIDE, 0);
      } else if (DigitalOnScreenControl.testDiagonalAngle(225, angle)) {
        super.onUpdateControlKnob(EXTENT_DIAGONAL, EXTENT_DIAGONAL);
      } else if (DigitalOnScreenControl.testDiagonalAngle(270, angle)) {
        super.onUpdateControlKnob(0, EXTENT_SIDE);
      } else if (DigitalOnScreenControl.testDiagonalAngle(315, angle)) {
        super.onUpdateControlKnob(-EXTENT_DIAGONAL, EXTENT_DIAGONAL);
      } else {
        super.onUpdateControlKnob(0, 0);
      }
    } else {
      if (Math.abs(pRelativeX) > Math.abs(pRelativeY)) {
        if (pRelativeX > 0) {
          super.onUpdateControlKnob(EXTENT_SIDE, 0);
        } else if (pRelativeX < 0) {
          super.onUpdateControlKnob(-EXTENT_SIDE, 0);
        } else if (pRelativeX == 0) {
          super.onUpdateControlKnob(0, 0);
        }
      } else {
        if (pRelativeY > 0) {
          super.onUpdateControlKnob(0, EXTENT_SIDE);
        } else if (pRelativeY < 0) {
          super.onUpdateControlKnob(0, -EXTENT_SIDE);
        } else if (pRelativeY == 0) {
          super.onUpdateControlKnob(0, 0);
        }
      }
    }
  }