Popcorning Guinea Pig
Search Results for

    Show / Hide Table of Contents

    Class TileGrid

    Manages a 2D grid of GameTiles for grid-based games. Provides efficient access, spatial queries, and occupancy management.

    Inheritance
    object
    TileGrid
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: PopcorningGuineaPig.Engine.Gameplay
    Assembly: PopcorningGuineaPig.Engine.dll
    Syntax
    public class TileGrid

    Constructors

    | Edit this page View Source

    TileGrid(int, int, Vector2, Vector3)

    Creates a new tile grid with specified dimensions and tile size.

    Declaration
    public TileGrid(int width, int height, Vector2 tileSize, Vector3 gridOrigin = default)
    Parameters
    Type Name Description
    int width

    Number of tiles horizontally

    int height

    Number of tiles vertically

    Vector2 tileSize

    Size of each tile (width, height)

    Vector3 gridOrigin

    World position of the grid center

    Properties

    | Edit this page View Source

    GridOrigin

    Declaration
    public Vector3 GridOrigin { get; }
    Property Value
    Type Description
    Vector3
    | Edit this page View Source

    Height

    Declaration
    public int Height { get; }
    Property Value
    Type Description
    int
    | Edit this page View Source

    TileSize

    Declaration
    public Vector2 TileSize { get; }
    Property Value
    Type Description
    Vector2
    | Edit this page View Source

    Width

    Declaration
    public int Width { get; }
    Property Value
    Type Description
    int

    Methods

    | Edit this page View Source

    ClearOccupant(int, int)

    Clears the occupant from the tile at the specified coordinates.

    Declaration
    public object? ClearOccupant(int x, int y)
    Parameters
    Type Name Description
    int x

    Grid X coordinate

    int y

    Grid Y coordinate

    Returns
    Type Description
    object

    The removed occupant, if any

    | Edit this page View Source

    FindPath(int, int, int, int)

    Finds a path between two tiles using simple A* pathfinding. Useful for AI movement in 2D games.

    Declaration
    public List<GameTile> FindPath(int startX, int startY, int endX, int endY)
    Parameters
    Type Name Description
    int startX

    Start grid X coordinate

    int startY

    Start grid Y coordinate

    int endX

    End grid X coordinate

    int endY

    End grid Y coordinate

    Returns
    Type Description
    List<GameTile>

    List of tiles representing the path, or empty list if no path found

    | Edit this page View Source

    GetAllTiles()

    Gets all tiles in the grid.

    Declaration
    public IEnumerable<GameTile> GetAllTiles()
    Returns
    Type Description
    IEnumerable<GameTile>

    Collection of all tiles

    | Edit this page View Source

    GetEmptyTiles()

    Gets all tiles that are empty (no occupants).

    Declaration
    public IEnumerable<GameTile> GetEmptyTiles()
    Returns
    Type Description
    IEnumerable<GameTile>

    Collection of empty tiles

    | Edit this page View Source

    GetNeighbors(int, int)

    Gets all neighboring tiles of the specified tile (4-directional).

    Declaration
    public IEnumerable<GameTile> GetNeighbors(int x, int y)
    Parameters
    Type Name Description
    int x

    Grid X coordinate

    int y

    Grid Y coordinate

    Returns
    Type Description
    IEnumerable<GameTile>

    Collection of neighboring tiles

    | Edit this page View Source

    GetNeighbors8(int, int)

    Gets all neighboring tiles of the specified tile (8-directional).

    Declaration
    public IEnumerable<GameTile> GetNeighbors8(int x, int y)
    Parameters
    Type Name Description
    int x

    Grid X coordinate

    int y

    Grid Y coordinate

    Returns
    Type Description
    IEnumerable<GameTile>

    Collection of neighboring tiles including diagonals

    | Edit this page View Source

    GetOccupiedTiles()

    Gets all tiles that currently have occupants.

    Declaration
    public IEnumerable<GameTile> GetOccupiedTiles()
    Returns
    Type Description
    IEnumerable<GameTile>

    Collection of occupied tiles

    | Edit this page View Source

    GetTile(int, int)

    Gets the tile at the specified grid coordinates.

    Declaration
    public GameTile? GetTile(int x, int y)
    Parameters
    Type Name Description
    int x

    Grid X coordinate

    int y

    Grid Y coordinate

    Returns
    Type Description
    GameTile

    GameTile at the specified coordinates, or null if out of bounds

    | Edit this page View Source

    GetTileAtWorldPosition(Vector3)

    Gets the tile that contains the specified world position.

    Declaration
    public GameTile? GetTileAtWorldPosition(Vector3 worldPosition)
    Parameters
    Type Name Description
    Vector3 worldPosition

    3D world position

    Returns
    Type Description
    GameTile

    GameTile containing the position, or null if outside grid

    | Edit this page View Source

    RenderDebug(bool, bool)

    Renders debug visualization of the tile grid.

    Declaration
    public void RenderDebug(bool showOccupied = true, bool showBounds = true)
    Parameters
    Type Name Description
    bool showOccupied

    Whether to highlight occupied tiles (ignored - kept for compatibility)

    bool showBounds

    Whether to show tile boundaries

    | Edit this page View Source

    ToString()

    Returns a string that represents the current object.

    Declaration
    public override string ToString()
    Returns
    Type Description
    string

    A string that represents the current object.

    Overrides
    object.ToString()
    | Edit this page View Source

    TryMoveOccupant(int, int, int, int)

    Attempts to move an occupant from one tile to another.

    Declaration
    public bool TryMoveOccupant(int fromX, int fromY, int toX, int toY)
    Parameters
    Type Name Description
    int fromX

    Source grid X coordinate

    int fromY

    Source grid Y coordinate

    int toX

    Destination grid X coordinate

    int toY

    Destination grid Y coordinate

    Returns
    Type Description
    bool

    True if move was successful, false if invalid coordinates

    | Edit this page View Source

    TryPlaceOccupant(int, int, object)

    Attempts to place an occupant on the tile at the specified coordinates.

    Declaration
    public bool TryPlaceOccupant(int x, int y, object occupant)
    Parameters
    Type Name Description
    int x

    Grid X coordinate

    int y

    Grid Y coordinate

    object occupant

    Object to place on the tile

    Returns
    Type Description
    bool

    True if placement was successful, false if tile is invalid

    • Edit this page
    • View Source
    In this article
    Back to top © 2024 Popcorning Guinea Pig Game Engine. A custom C# game engine for indie developers.