Esempio n. 1
0
  public void move(Map world) {
    setOldPos(getPos());
    if (frindly) {
      int des = 1 + rand.nextInt(4);

      switch (des) {
        case 1:
          moveTo(new Position(getPos().getX() - 1, getPos().getY()), world);
          break;
        case 2:
          moveTo(new Position(getPos().getX() + 1, getPos().getY()), world);
          break;
        case 3:
          moveTo(new Position(getPos().getX(), getPos().getY() - 1), world);
          break;
        case 4:
          moveTo(new Position(getPos().getX(), getPos().getY() + 1), world);
          break;
        case 5:
          break;
        default:
      }
    } else {
      if (path != null) {
        if (path.hasNext()) moveTo(path.getNext(), world);
      }
      if (target == null) {
        target = world.find_player(getPos());
      } else {
        path = world.getGraph(getPos(), target.getPos()).findShortestPath();
      }
    }
    if (getPos() == getOldPos()) setMoving(no_move);
  }
Esempio n. 2
0
  public void takeDamage(int dmg) {
    // battle text points
    damageTaken.setText("-" + Integer.toString(dmg));
    damageTaken.pack();
    deltaDamage = show_damage_time;

    int x = getPos().getX() - targeted.getPos().getX();
    int y = getPos().getY() - targeted.getPos().getY();

    int center_x = 7 * 50 + 10;
    int center_y = 5 * 50 + 10;
    x = center_x + x * 50 + 30;
    y = center_y + y * 50 + 10;

    damageTaken.setLocation(x, y);

    this.hp -= dmg;
    if (this.hp < 1) {
      this.hp = 0;
      setDead(true);
    }
  }