コード例 #1
0
ファイル: Creature.java プロジェクト: jasonfong/animats
  public double bearingTo(Placeable p) {
    int xdist, ydist;
    double angle;
    double bearing;

    if (p == null) {
      return 0;
    }

    xdist = p.getX() - xcoord;
    ydist = p.getY() - ycoord;

    angle = Math.atan(((double) ydist) / xdist);
    angle = angle * 180 / Math.PI;

    if (angle < 0) {
      if (xdist < 0) {
        angle = 180 + angle; // 360 + angle - 180
      } else {
        angle = 360 + angle;
      }
    } else if (xdist < 0) {
      angle = 180 + angle;
    }

    if (angle > heading) {
      bearing = angle - heading;
    } else if (angle == heading) {
      bearing = 0;
    } else {
      bearing = angle + 360 - heading;
    }

    return bearing;
  }
コード例 #2
0
  public void spawnNearPlaceable() {
    float prob, rand;
    Placeable placeable = registry.getPlaceableManager().getRandomPlacable();
    if (placeable != null
        && !placeable.getType().equals("TownHall")
        && !placeable.getType().equals("Cabin")
        && !placeable.getType().equals("Chest")) {

      Point p = placeable.getCenterPoint();
      HashMap<String, Player> players = registry.getPlayerManager().getPlayers();
      Player player = null;
      boolean playerNear = false;
      for (String key : players.keySet()) {
        player = (Player) players.get(key);
        Point p2 = new Point(player.getMapX(), player.getMapY());
        if (p.distance(p2) < mobSpawnRangeMin * 2) {
          playerNear = true;
        }
      }
      if (!playerNear) {
        for (MonsterType monsterType : MonsterType.values()) {
          if (monsterType.toString().equals("Porcupine")
              || monsterType.toString().equals("Snail")
              || monsterType.toString().equals("Snake")
              || monsterType.toString().equals("ZombieWalrus")) {
            rand = Rand.getFloat();
            prob = getShouldSpawn(monsterType, 0);
            if (rand <= prob / 3.0f) {
              // System.out.println("spawn near placeable " + monsterType.name());
              spawn(monsterType.name(), "Roaming", p.x, p.y);
            }
          }
        }
      }
    }
  }