Class Area

  • All Implemented Interfaces:
    Locatable

    public class Area
    extends java.lang.Object
    implements Locatable
    • Constructor Detail

      • Area

        public Area​(Tile... tiles)
        Creates an area from the provided tiles.

        Each tile is a vertex of a Polygon and should be in order. The area is closed automatically by connecting the final tile to the first.

        Validity rules:

        • All areas created with a single non-null tile are valid
        • For areas with two or more tiles, they should be ordered in a consistent order
        • To avoid undefined behavior, the resultant polygon of tiles should be simple (non-self-intersecting)

        Note: Polygon (and this constructor) does not validate or enforce these rules, and will happily create degenerate Areas that will give you unexpected results for methods like contains(int, int) or getTiles().

        Parameters:
        tiles - one or more tiles
      • Area

        public Area​(Tile northeastTile,
                    Tile southwestTile)
        Creates an Area based on the northeast and southwest corner tiles (both inclusive)
        Parameters:
        northeastTile - Northeast tile
        southwestTile - Southwest tile
      • Area

        public Area​(int x1,
                    int y1,
                    int x2,
                    int y2)
        Creates a rectangular area using basic coordinates for plane 0. The x and y positions provided do not need to be any specific corner.
        Parameters:
        x1 - X of first corner
        y1 - Y of first corner
        x2 - X of second corner
        y2 - Y of second corner
      • Area

        public Area​(int x1,
                    int y1,
                    int x2,
                    int y2,
                    int z)
        Creates a rectangular area using basic coordinates. The x and y positions provided do not need to be any specific corner.
        Parameters:
        x1 - X of first corner
        y1 - Y of first corner
        x2 - X of second corner
        y2 - Y of second corner
        z - The plane.
    • Method Detail

      • generateArea

        public static Area generateArea​(int radius,
                                        Tile center)
      • setZ

        public void setZ​(int plane)
      • getTiles

        public Tile[] getTiles()
        Gets all of the tiles contained in the Area
        Returns:
        An array of Tile's contained within the Area
      • getNearestTile

        public Tile getNearestTile​(Entity entity)
        Gets the closest Tile in the Area to the provided entity
        Parameters:
        entity - The entity
        Returns:
        The Tile closest to the provided entity
      • getRandomTile

        public Tile getRandomTile()
        Gets a random Tile inside the Area
        Returns:
        A random Tile from the Area
      • getCenter

        public Tile getCenter()
        Gets the center Tile of the Area
        Returns:
        The center Tile of the Area, or null if the area contains no tiles
      • getPolygonArea

        public java.awt.Polygon getPolygonArea()
        Gets the polygon shape of the Area
        Returns:
        The polygon shape of the Area
      • getBoundingBox

        public java.awt.Rectangle getBoundingBox()
        Gets the bounding box of the area
        Returns:
        The rectangle bounding box
      • contains

        public boolean contains​(int x,
                                int y)
        Checks if the Area contains the x and the y points
        Parameters:
        x - X value of Tile
        y - Y value of Tile
        Returns:
        True if the area contains the point, otherwise False
      • contains

        public boolean contains​(Tile tile)
        Checks if the Area contains the provided Tile
        Parameters:
        tile - Tile to check for
        Returns:
        True if the Area contains Tile, otherwise False
      • contains

        public boolean contains​(Entity entity)
        Checks if an Area contains the provided Entity
        Parameters:
        entity - Entity to check
        Returns:
        True if the Area contains the Entity, otherwise False
      • withArea

        public Area withArea​(Area area)
        Creates a new Area containing the tiles from this area and the given area
        Parameters:
        area - Area to append the tiles from to this area
        Returns:
        new Area instance containing tiles from both this area and the given area
      • getBoundaryPoints

        public java.util.List<Tile> getBoundaryPoints()
        Gets the boundary Tiles, or a list of the area's defined points
        Returns:
        List of Tiles that make up the area's boundary/defined points. Empty if no points defined.
      • getTile

        public Tile getTile()
        Description copied from interface: Locatable
        Gets tile of the object.
        Specified by:
        getTile in interface Locatable
        Returns:
        the object tile.