コード例 #1
0
ファイル: Enemy.java プロジェクト: RyDroid/android-anuto
  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;
  }
コード例 #2
0
ファイル: Mortar.java プロジェクト: RyDroid/android-anuto
  @Override
  public void tick() {
    super.tick();

    if (getTarget() != null && isReloaded()) {
      Vector2 targetPos = getTarget().getPositionAfter(MortarShot.TIME_TO_TARGET);
      targetPos.add(Vector2.polar(getGame().getRandom(mInaccuracy), getGame().getRandom(360f)));
      Vector2 shotPos = getPosition().copy().add(Vector2.polar(SHOT_SPAWN_OFFSET, mAngle));
      mAngle = getAngleTo(targetPos);

      getGame().add(new MortarShot(this, shotPos, targetPos, getDamage(), mExplosionRadius));

      setReloaded(false);
      mRebounding = true;
    }

    if (mRebounding && mSpriteCanon.tick()) {
      mRebounding = false;
    }
  }
コード例 #3
0
ファイル: Enemy.java プロジェクト: RyDroid/android-anuto
  public void sendBack(float dist) {
    int index = mWayPointIndex - 1;
    Vector2 pos = getPosition().copy();

    while (index > 0) {
      Vector2 wp = mPath.get(index);
      Vector2 toWp = Vector2.fromTo(pos, wp);
      float toWpLen = toWp.len();

      if (dist > toWpLen) {
        dist -= toWpLen;
        pos = wp;
        index--;
      } else {
        pos = toWp.norm().mul(dist).add(pos);
        setPosition(pos);
        mWayPointIndex = index + 1;
        return;
      }
    }

    setPosition(mPath.get(0));
    mWayPointIndex = 1;
  }
コード例 #4
0
ファイル: Enemy.java プロジェクト: RyDroid/android-anuto
  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;
  }