Пример #1
0
  /**
   * 获取以pos为圆心,半径为radius的圆形区域内的UnitObject
   *
   * @param stageObj
   * @param pos
   * @param radius
   * @return
   */
  public List<UnitObject> getUnitObjsInCircle(StageObject stageObj, Vector2D pos, double radius) {
    List<UnitObject> result = new ArrayList<>();
    for (UnitObject uo : stageObj.getUnitObjs().values()) {
      // 判断距离是否符合要求
      Vector2D p = uo.posNow;
      if (pos.distance(p) < radius) {
        result.add(uo);
      }
    }

    return result;
  }
Пример #2
0
  /**
   * 范围内HP 最少的
   *
   * @param stageObj
   * @param exclude
   * @param pos
   * @param radius
   * @return
   */
  public UnitObject getUnitObjsInCircleHpLeast(
      StageObject stageObj, List<UnitObject> exclude, Vector2D pos, double radius) {
    int hpMax = 9999999;
    UnitObject hpLeastObj = null;
    for (UnitObject uo : stageObj.getUnitObjs().values()) {
      // 判断距离是否符合要求
      Vector2D p = uo.posNow;
      if (pos.distance(p) < radius) {
        if (uo.getUnit().getHpCur() < hpMax && !exclude.contains(uo)) {
          hpLeastObj = uo;
          hpMax = uo.getUnit().getHpCur();
        }
      }
    }

    return hpLeastObj;
  }
Пример #3
0
  public List<UnitObject> getUnitObjsInCircleProfession(
      StageObject stageObj, int profession, Vector2D pos, double radius) {
    List<UnitObject> result = new ArrayList<>();
    int pro = 0;
    if ((profession & 1) > 0) {
      pro = 1;
    } else if ((profession & 2) > 0) {
      pro = 2;
    } else if ((profession & 4) > 0) {
      pro = 3;
    }
    for (UnitObject uo : stageObj.getUnitObjs().values()) {
      // 判断距离是否符合要求
      Vector2D p = uo.posNow;
      if (pos.distance(p) < radius) {
        if (uo.profession == pro) {
          result.add(uo);
        }
      }
    }

    return result;
  }
Пример #4
0
  /**
   * 获取以pos位置为起点,target为终点的线段,往线段两边扩展width/2,并且从起始点为长度length的矩形区域内的unitObj
   *
   * @param stageObj
   * @param pos
   * @param length
   * @param width
   * @return
   */
  public List<UnitObject> getUnitObjsInRectangle(
      StageObject stageObj, Vector2D pos, Vector2D target, double height, double width) {
    List<UnitObject> result = new ArrayList<>();

    double c = pos.distance(target);

    // 利用余弦定理计算夹角a的余弦值
    double cosA = (double) (target.x - pos.x) / c;
    double sinA = (double) (target.y - pos.y) / c;

    for (UnitObject uo : stageObj.getUnitObjs().values()) {
      // 判断距离是否符合要求

      Vector2D p = uo.posNow;
      // p绕pos点旋转-A角度到新坐标
      // 如果P点绕另一点P0(x0,y0)旋转β到点P1,旋转后位置计算公式如下:
      // dx = x-x0;
      // dy = y-y0;
      // x1=cos(β)*dx-sin(β)*dy+x0;
      // y1=cos(β)*dy+sin(β)*dx+y0;
      double cosB = cosA;
      double sinB = -sinA;
      double dx = p.x - pos.x;
      double dy = p.y - pos.y;
      double x1 = cosB * dx - sinB * dy + pos.x;
      double y1 = cosB * dy + sinB * dx + pos.y;

      if (x1 >= pos.x
          && x1 <= (pos.x + width)
          && y1 <= (pos.y + height / 2)
          && pos.y >= pos.y - height / 2) {
        result.add(uo);
      }
    }

    return result;
  }