Ejemplo n.º 1
0
  public float getDistanceRemaining() {
    if (!hasWayPoint()) {
      return 0;
    }

    float dist = getDistanceTo(getWayPoint());

    for (int i = mWayPointIndex + 1; i < mPath.count(); i++) {
      Vector2 wThis = mPath.get(i);
      Vector2 wLast = mPath.get(i - 1);

      dist += wThis.copy().sub(wLast).len();
    }

    return dist;
  }
Ejemplo n.º 2
0
  public Vector2 getPositionAfter(float sec) {
    if (mPath == null) {
      return getPosition();
    }

    float distance = sec * getSpeed();
    int index = mWayPointIndex;
    Vector2 position = getPosition().copy();

    while (index < mPath.count()) {
      Vector2 toWaypoint = mPath.get(index).copy().sub(position);
      float toWaypointDist = toWaypoint.len();

      if (distance < toWaypointDist) {
        return position.add(toWaypoint.mul(distance / toWaypointDist));
      } else {
        distance -= toWaypointDist;
        position.set(mPath.get(index));
        index++;
      }
    }

    return position;
  }
Ejemplo n.º 3
0
 protected boolean hasWayPoint() {
   return mPath != null && mWayPointIndex < mPath.count();
 }