Пример #1
0
  /**
   * Does the necessary jiggery pokery to figure out where the specified object's associated
   * location is.
   *
   * @param tilemgr a tile manager that can be used to look up the tile information.
   * @param tileId the fully qualified tile id of the object tile.
   * @param tx the object's x tile coordinate.
   * @param ty the object's y tile coordinate.
   * @param orient - the orientation to use in the returned location, or {@link #OBJECT_ORIENTATION}
   *     if the tile's orientation should be used
   */
  public static StageLocation locationForObject(
      TileManager tilemgr, int tileId, int tx, int ty, int orient) {
    try {
      int tsid = TileUtil.getTileSetId(tileId);
      int tidx = TileUtil.getTileIndex(tileId);
      TrimmedObjectTileSet tset = (TrimmedObjectTileSet) tilemgr.getTileSet(tsid);
      if (tset == null || (orient == OBJECT_ORIENTATION && tset.getSpotOrient(tidx) < 0)) {
        return null;
      }
      if (orient == OBJECT_ORIENTATION) {
        orient = tset.getSpotOrient(tidx);
      }

      Point opos =
          MisoUtil.tilePlusFineToFull(
              _metrics, tx, ty, tset.getXSpot(tidx), tset.getYSpot(tidx), new Point());

      //             Log.info("Computed location [set=" + tset.getName() +
      //                      ", tidx=" + tidx + ", tx=" + tx + ", ty=" + ty +
      //                      ", sx=" + tset.getXSpot(tidx) +
      //                      ", sy=" + tset.getYSpot(tidx) +
      //                      ", lx=" + opos.x + ", ly=" + opos.y +
      //                      ", fg=" + _metrics.finegran + "].");
      return new StageLocation(opos.x, opos.y, (byte) orient);

    } catch (Exception e) {
      log.warning("Unable to look up object tile for scene object", "tileId", tileId, e);
    }
    return null;
  }
Пример #2
0
  /**
   * Looks up the base tile set for the specified fully qualified tile identifier and returns true
   * if the associated tile is passable.
   */
  public static boolean isPassable(TileManager tilemgr, int tileId) {
    // non-existent tiles are not passable
    if (tileId <= 0) {
      return false;
    }

    try {
      int tsid = TileUtil.getTileSetId(tileId);
      int tidx = TileUtil.getTileIndex(tileId);
      BaseTileSet tset = (BaseTileSet) tilemgr.getTileSet(tsid);
      return tset.getPassability()[tidx];

    } catch (Exception e) {
      log.warning("Unable to look up base tile", "tileId", tileId, e);
      return true;
    }
  }
Пример #3
0
  /**
   * Fills in the footprint, in absolute tile coordinates, for the specified object with origin as
   * specified.
   *
   * @return true if the object was successfully looked up and the footprint filled in, false if an
   *     error occurred trying to look up the associated object tile.
   */
  public static boolean getObjectFootprint(
      TileManager tilemgr, int tileId, int ox, int oy, Rectangle foot) {
    try {
      int tsid = TileUtil.getTileSetId(tileId);
      int tidx = TileUtil.getTileIndex(tileId);
      BaseSizableTileSet tset = (BaseSizableTileSet) tilemgr.getTileSet(tsid);
      if (tset == null) {
        return false;
      }

      int bwidth = tset.getBaseWidth(tidx);
      int bheight = tset.getBaseHeight(tidx);
      foot.setBounds(ox - bwidth + 1, oy - bheight + 1, bwidth, bheight);
      return true;

    } catch (Exception e) {
      log.warning("Unable to look up object tile for scene object", "tileId", tileId, e);
      return false;
    }
  }