Class Grid

java.lang.Object
io.github.srcimon.screwbox.core.Grid
All Implemented Interfaces:
Serializable

public class Grid extends Object implements Serializable
A Grid to raster your game world. The Grid is a two dimensional area with blocked and free Grid.Nodes that is aligned to the game world.
See Also:
  • Constructor Details

    • Grid

      public Grid(Bounds area, int gridSize)
    • Grid

      public Grid(Bounds area, int gridSize, boolean useDiagonalSearch)
  • Method Details

    • clearedInstance

      public Grid clearedInstance()
      Returns a new instance without any blocked Grid.Nodes.
    • area

      public Bounds area()
      Returns the area of this Grid in the World.
    • nodeAt

      public Grid.Node nodeAt(int x, int y)
      Returns the Grid.Node at the given Position. May return Grid.Nodes out of grid. This can be checked via isInGrid(Node).
    • isFree

      public boolean isFree(int x, int y)
      Retruns true if the given position is not blocked and inside the Grid.
    • isFree

      public boolean isFree(Grid.Node node)
    • worldPosition

      public Vector worldPosition(Grid.Node node)
    • worldArea

      public Bounds worldArea(Grid.Node node)
      Returns the corresponding area of the Grid.Node in the Grid in the game world. Returns valid areas, even if the Grid.Node is out of the Grid.
    • toGrid

      public Grid.Node toGrid(Vector position)
    • freeArea

      public void freeArea(Bounds area)
    • freeAt

      public void freeAt(Vector position)
    • blockAt

      public void blockAt(Vector position)
    • block

      public void block(Grid.Node node)
    • block

      public void block(int x, int y)
    • blockArea

      public void blockArea(Bounds area)
    • width

      public int width()
    • height

      public int height()
    • blockedNeighbors

      public List<Grid.Node> blockedNeighbors(Grid.Node node)
    • neighbors

      public List<Grid.Node> neighbors(Grid.Node node)
    • reachableNeighbors

      public List<Grid.Node> reachableNeighbors(Grid.Node node)
    • nodes

      public List<Grid.Node> nodes()
      Returns all Grid.Nodes in the Grid.
    • nodeCount

      public int nodeCount()
      Returns the count of Grid.Nodes in the Grid.
    • blockedCount

      public int blockedCount()
    • freeCount

      public int freeCount()
    • backtrack

      public List<Grid.Node> backtrack(Grid.Node node)
    • snap

      public Vector snap(Vector position)
    • isBlocked

      public boolean isBlocked(int x, int y)
    • isBlocked

      public boolean isBlocked(Grid.Node node)
    • gridSize

      public double gridSize()