示例#1
0
  public void onUpdateGameAction(double progress) {

    if (progressPercentageForStartOfEachSingleWalk != null) {
      for (int i = singleWalks.size() - 1; i >= 0; i--) {
        // go backwards thru the loop to find text that should be valid
        double startPercentageForWalk = progressPercentageForStartOfEachSingleWalk[i];
        double endPercentageForWalk = progressPercentageForStartOfEachSingleWalk[i + 1];

        if (progress > startPercentageForWalk) {
          double howFarInsideThisSegmentAreWe = progress - startPercentageForWalk;
          double fullSegmentLength = endPercentageForWalk - startPercentageForWalk;
          double percent = howFarInsideThisSegmentAreWe / fullSegmentLength;
          singleWalks.get(i).onUpdateGameAction(percent);
          if (singleWalks.get(i).isCancelNeededDueToGateOrNoGoZone())
            isCancelNeededDueToGateOrNoGoZone = true;
          PointF from = singleWalks.get(i).mover.getStartPtForMover();
          PointF to = singleWalks.get(i).mover.getEndPtForMover();
          MULTIWALKER.log(
              Level.ALL,
              "{0} walk to-mid  from {1} {2} to {3} {4} {5}",
              new Object[] {i, from.getX(), from.getY(), to.getX(), to.getY(), percent});
          break;
        }
      }
    }
  }
示例#2
0
  public double getRunningDuration() {
    otid = scene.getOtidByCode(ocode);

    startX = scene.getBaseMiddleXByOtid(otid);
    startY = scene.getBaseMiddleYByOtid(otid);

    if (endX == Double.NaN) endX = startX;
    if (endY == Double.NaN) endY = startY;
    List<PointF> list = scene.findPath(new PointF(startX, startY), new PointF(endX, endY));
    if (list == null) return 0;
    progressPercentageForStartOfEachSingleWalk = new Double[list.size()];
    progressPercentageForStartOfEachSingleWalk[0] = 0.0; // first startin percentage is zero.
    PointF startPoint = list.get(0);
    double totalDuration = 0;
    for (int i = 1; i < list.size(); i++) {
      PointF endPoint = list.get(i);

      MovePerformer m = new MovePerformer(ocode);
      WalkPerformer w = new WalkPerformer(ocode);
      SwitchPerformer sw = isToUseSwitchForChildren ? new SwitchPerformer(ocode) : null;
      ScalePerformer sc = new ScalePerformer(ocode);
      sc.setStartScaleForScaler(startScale);
      sc.setStartScaleForScaler(endScale);
      WalkSinglePerformer k = new WalkSinglePerformer(m, w, sw, sc);
      k.setScene(scene);
      k.setStartX(startPoint.getX());
      k.setStartY(startPoint.getY());
      k.setEndX(endPoint.getX());
      k.setEndY(endPoint.getY());
      k.setStartScale(startScale);
      k.setEndScale(endScale);
      k.setToInitialAtEnd(false);
      double duration = k.getRunningDuration();
      totalDuration += duration;
      if (i == list.size() - 1) {
        k.setToInitialAtEnd(isSetToInitialAtEnd);
      }
      singleWalks.add(k);
      progressPercentageForStartOfEachSingleWalk[i] = duration;
      startPoint = endPoint;
    }

    // normalize the lengths so we know when, in the progress, to jump in.
    double rollingStartingTime = 0;
    for (int i = 0; i < progressPercentageForStartOfEachSingleWalk.length; i++) {
      double duration = progressPercentageForStartOfEachSingleWalk[i];
      rollingStartingTime += duration;
      progressPercentageForStartOfEachSingleWalk[i] = rollingStartingTime / totalDuration;
    }

    return totalDuration;
  }