pyxen.GridMap

A GridMap is a spatial container made of cells arranged in rows and columns.

It defines the tile layout, cell size, optional tile atlas, and the collision space for GridBody.

For collision concepts, see Collision.


Constructor

GridMap(
    *,
    rows=None,
    columns=None,
    size=None,
    image=None
)

All parameters are keyword-only.


Parameters

ParameterTypeDescription
rowsintNumber of grid rows
columnsintNumber of grid columns
size(width, height)Cell size in pixels
imagestrTile atlas image name

Example

level_map = GridMap(
    rows=10,
    columns=16,
    size=(16, 16),
    image="tileset"
)

Attaching a GridMap

During spawn:

level = world.spawn(
    map=GridMap(
        rows=10,
        columns=16,
        size=(16, 16),
        image="tileset"
    )
)

Or later:

entity = world.spawn()
entity.map = GridMap(rows=8, columns=8, size=(16, 16))

Properties

map.active

PropertyTypeDefault
activeboolTrue

Controls whether collision simulation runs for this map. When False, no body movement, collisions, or callbacks are processed for any GridBody attached to this map.

# Pause collisions (e.g. pause menu)
level.map.active = False

# Resume collisions
level.map.active = True

Modifying Tiles

Use map.set() to configure tiles.

map.set(
    row=0,
    column=1,
    tile=(tile_column, tile_row),
    tag=optional_tag
)

Parameters

ParameterTypeDescription
rowintGrid row index
columnintGrid column index
tile(x, y)Tile coordinates in the atlas
tagintOptional collision tag

Example: Set a Tile

level.map.set(
    row=2,
    column=5,
    tile=(3, 1)
)

Example: Add Collision Tag

level.map.set(
    row=4,
    column=2,
    tile=(0, 0),
    tag=1  # wall
)

Grid Coordinates

  • Rows increase vertically
  • Columns increase horizontally

Indices outside bounds are safely ignored.


GridMap + GridBody

A GridBody interacts with the GridMap for collision, movement resolution, and trigger detection.

GridBody must be a child of the GridMap entity.

level = world.spawn(
    map=GridMap(
        rows=8,
        columns=8,
        size=(16, 16),
        image="tiles"
    )
)

player = world.spawn(
    body=GridBody(),
    parent=level
)

Minimal Example: Basic Level

level = world.spawn(
    map=GridMap(
        rows=8,
        columns=8,
        size=(16, 16),
        image="tiles"
    )
)

# Create floor
for r in range(8):
    for c in range(8):
        level.map.set(row=r, column=c, tile=(0, 0))

# Create walls
for c in range(8):
    level.map.set(row=0, column=c, tile=(1, 0), tag=1)
    level.map.set(row=7, column=c, tile=(1, 0), tag=1)

Tags

tag is optional metadata per tile.

Typical uses:

  • 0 — empty
  • 1 — wall
  • 2 — water
  • 3 — damage zone

Tags are interpreted by your gameplay or collision system.