Class GridGroup

java.lang.Object
dev.prozilla.pine.core.component.Component
dev.prozilla.pine.core.component.sprite.GridGroup
All Implemented Interfaces:
Destructible, Printable, ApplicationContext, ApplicationProvider, ComponentsContext, ComponentsProvider, EntityContext, EntityProvider, SceneContext, SceneProvider

public class GridGroup extends Component
A component that groups 2D tiles together and aligns them in a grid pattern.
  • Field Details

  • Constructor Details

    • GridGroup

      public GridGroup(int size)
  • Method Details

    • getName

      public String getName()
      Overrides:
      getName in class Component
    • addTile

      public TileRenderer addTile(TilePrefab tilePrefab, Vector2i coordinate)
    • addTile

      public TileRenderer addTile(TilePrefab tilePrefab, int x, int y)
    • addTile

      public TileRenderer addTile(Prefab prefab)
    • addTile

      public TileRenderer addTile(Entity entity)
    • addTile

      Adds a tile to this grid based on the tile's current coordinate.
      Parameters:
      tile - Tile to add to this grid
      Throws:
      IllegalStateException - If there is already a tile in this grid with the same coordinate
      NullPointerException
    • destroyTile

      public boolean destroyTile(Vector2i coordinate)
    • destroyTile

      public boolean destroyTile(Entity entity)
    • destroyTile

      public boolean destroyTile(TileRenderer tile)
    • removeTile

      public boolean removeTile(Vector2i coordinate)
    • removeTile

      public boolean removeTile(Entity entity)
    • removeTile

      public boolean removeTile(TileRenderer tile)
    • hasTile

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

      public boolean hasTile(Vector2i coordinate)
    • getTile

      public TileRenderer getTile(int x, int y)
    • getTile

      public TileRenderer getTile(Vector2i coordinate)
    • moveTile

      public void moveTile(Vector2i oldCoordinate, Vector2i newCoordinate)
    • isHovering

      public boolean isHovering(TileRenderer tile)
    • isHovering

      public boolean isHovering(Entity entity)
    • positionToCoordinate

      public Vector2i positionToCoordinate(Vector2f position)
    • positionToCoordinate

      public Vector2i positionToCoordinate(float x, float y)
    • coordinateToPosition

      public Vector2f coordinateToPosition(Vector2i coordinate)
    • coordinateToPosition

      public Vector2f coordinateToPosition(int x, int y)
    • subgrid

      public static Vector2i[] subgrid(Vector2i dimensions, Vector2i offset)
      Returns an array of coordinates of a subgrid defined by the given dimensions, with a given offset.
      Parameters:
      dimensions - The dimensions of the subgrid
      offset - The offset of the subgrid
      Returns:
      The coordinates of the subgrid
      See Also:
    • subgrid

      public static Vector2i[] subgrid(Vector2i dimensions)
      Returns an array of coordinates of a subgrid defined by the given dimensions.
      Parameters:
      dimensions - The dimensions of the subgrid
      Returns:
      The coordinates of the subgrid
      See Also:
    • subgrid

      public static Vector2i[] subgrid(int width, int height)
      Returns an array of coordinates of a subgrid defined by the given dimensions.

      The x-coordinates go from 0 to width - 1 and the y-coordinates go from 0 to height - 1.

      The array is sorted first based on the x-coordinate, then the y-coordinate.

      Parameters:
      width - The width of the subgrid
      height - The height of the subgrid
      Returns:
      The coordinates of the subgrid