示例#1
0
  protected void stepWalking(GameWorld world) {
    float dx = this.targetX - this.x;
    float dy = this.targetY - this.y;
    // float d = (float) Math.sqrt(dx * dx + dy * dy);
    GameThing thing = null;

    if (this.targetUnitID != 0) {
      thing = world.getThing(this.targetUnitID);
    }

    if (thing == null) {
      // Target unit doesn't exist so just walk to the location

      if (withinRange(this.targetX, this.targetY)) {
        finishWalking(world, thing);
        return;
      }

      walkStep(dx, dy);
    } else {
      if (withinRange(thing)) {
        finishWalking(world, thing);
        return;
      }

      dx = thing.getX() - this.x;
      dy = thing.getY() - this.y;
      walkStep(dx, dy);

      // if (withinRange(thing)) {
      // finishWalking(world, thing);
      // }
    }
  }
示例#2
0
  protected void stepAttacking(GameWorld world) {
    GameThing target = world.getThing(targetUnitID);

    if (target == null) {
      // Thing being attacked is gone
      finishAttacking(world);
      return;
    }

    // if (target instanceof Mineral) {
    // stepAttackingMineral(world, (Mineral) target);
    // } else

    if (target instanceof Unit) {
      stepAttackingUnit(world, (Unit) target);
    }
  }
示例#3
0
  protected void stepHarvesting(GameWorld world) {
    GameThing target = world.getThing(targetUnitID);

    if (carryingMinerals >= 10) {
      stepHarvestingReturn(world);
      return;
    }

    if (target == null) {
      // Thing being attacked is gone
      // finishAttacking(world);
      return;
    }

    if (!withinRange(target)) {
      walkStep(target);
      return;
    }

    if (target instanceof Mineral) {
      stepAttackingMineral(world, (Mineral) target);
    }
  }