Exemplo n.º 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);
      // }
    }
  }
Exemplo n.º 2
0
 public void harvest(GameThing targetThing) {
   this.targetX = targetThing.getX();
   this.targetY = targetThing.getY();
   this.targetAction = STATE_HARVESTING;
   this.targetUnitID = targetThing.getID();
   this.direction = (float) Math.atan2(targetY - y, targetX - x);
   this.changeState(STATE_HARVESTING);
 }
Exemplo n.º 3
0
 public void attack(GameThing targetThing) {
   this.targetX = targetThing.getX();
   this.targetY = targetThing.getY();
   this.targetAction = STATE_ATTACKING;
   this.targetUnitID = targetThing.getID();
   this.direction = (float) Math.atan2(targetY - y, targetX - x);
   this.changeState(STATE_WALKING);
 }
Exemplo n.º 4
0
  public void follow(GameThing target) {
    if (target.getID() == getID()) {
      return;
    }

    this.targetX = target.getX();
    this.targetY = target.getY();
    this.direction = (float) Math.atan2(targetY - y, targetX - x);
    this.targetUnitID = target.getID();
    this.targetAction = STATE_WALKING;
    this.changeState(STATE_WALKING);
  }
Exemplo n.º 5
0
  public void command(GameThing target) {
    int otherPlayerID = target.getPlayerID();

    if (otherPlayerID == getPlayerID()) {
      follow(target);
      return;
    }

    if (target instanceof Mineral) {
      harvest(target);
      return;
    }

    attack(target);
  }
Exemplo n.º 6
0
  protected void walkStep(GameThing target) {
    float dx = (target.getX() - this.getX());
    float dy = (target.getY() - this.getY());

    walkStep(dx, dy);
  }