World > Tiled Elements#
TiledWorld exposes tile helper classes for grid-based projects. They are most
useful when you need to inspect or customize tiles, edges, or corners directly.
TileFactory#
TileBase#
- class miniworlds.worlds.tiled_world.tile_elements.TileBase(position, world=None)[source]#
Base class for Tiles and TileDelimiters (like Corners, Edges).
- property cost: float#
Cost of entering this tile for path finding (default 1).
Must not be negative. A cost of 0 makes the tile free to enter.
Examples
swamp.cost = 3 road.cost = 0.5
- Type:
- property data: dict#
Free-form game data stored on this tile.
Use it for anything your game needs per tile, for example a resource, an owner, or a dice number. The dict is created on first access and stays attached to the tile.
Examples
tile = world.get_tile((2, 3)) tile.data["dice_number"] = 8 print(tile.data.get("dice_number"))
- Type:
- classmethod from_pixel(pixel_position, world)[source]#
Finds the nearest tile to a given pixel coordinate.
This method uses caching to avoid redundant recalculation of the mapping between tile grid positions and their corresponding pixel coordinates for a given world. It also uses squared distance instead of Euclidean distance for better performance.
- abstract classmethod from_position(position, world)[source]#
Create a tile from a world-relative position.
- Return type:
- static get_local_center_coordinate(world)[source]#
Returns the center point offset for a tile, in local pixel coordinates.
- static get_position_pixel_dict(world)[source]#
Returns a mapping of tile positions to pixel coordinates.
- Return type:
- classmethod invalidate_position_pixel_cache(world)[source]#
Drop the cached position-pixel mapping of a world.
The cache maps tile positions to pixel coordinates for from_pixel lookups. It must be dropped whenever tiles, corners, or edges are added or removed, otherwise lookups return stale positions.
- Return type:
- property is_blocking: bool#
Whether path finding treats this tile as impassable.
Actors with is_blocking = True block their tile as well; this flag blocks a tile without needing an actor, for example water.
Examples
water_tile.is_blocking = True
- Type:
- property terrain#
The terrain name of this tile, or None (stored as data[“terrain”]).
Examples
tile.terrain = "forest" if tile.terrain == "forest": print("wood")
Tile#
- class miniworlds.worlds.tiled_world.tile.Tile(position, world=None)[source]#
- corner_vectors: OrderedDict[str, Tuple[float, float]] = {'no': (-0.5, 0.5), 'nw': (0.5, 0.5), 'so': (-0.5, -0.5), 'sw': (0.5, -0.5)}#
- edge_vectors: dict[str, Tuple[float, float]] = {'n': (0, -0.5), 'o': (0.5, 0), 's': (0, 0.5), 'w': (-0.5, 0)}#
- classmethod from_pixel(pixel_position, world=None)[source]#
Finds the nearest tile to a given pixel coordinate.
This method uses caching to avoid redundant recalculation of the mapping between tile grid positions and their corresponding pixel coordinates for a given world. It also uses squared distance instead of Euclidean distance for better performance.
- classmethod from_position(position, world)[source]#
Create a tile from a world-relative position.
- Return type:
- static get_position_pixel_dict(world)[source]#
Returns a mapping of tile positions to pixel coordinates.
- Return type:
- tile_vectors: dict[str, Tuple[int, int]] = {'no': (-1, 1), 'nw': (1, 1), 'o': (-1, 0), 'so': (-1, -1), 'sw': (1, -1), 'w': (1, 0)}#
Edge#
- class miniworlds.worlds.tiled_world.edge.Edge(position, direction, world)[source]#
- angles: Dict[str, int] = {'n': 3, 'o': 0, 's': 1, 'w': 2}#
- direction_angles: Dict[str, int] = {'n': 90, 'o': 0, 's': 90, 'w': 0}#
- static get_position_pixel_dict(world)[source]#
Returns a mapping of tile positions to pixel coordinates.
- tile_vectors: dict = {'n': [(0, 0.5), (0, -0.5)], 'o': [(-0.5, 0), (0.5, 0)], 's': [(0, 0.5), (0, -0.5)], 'w': [(-0.5, 0), (0.5, 0)]}#
Corner#
- class miniworlds.worlds.tiled_world.corner.Corner(position, direction, world)[source]#
- angles: Dict[str, int] = {'no': 0, 'nw': 1, 'so': 3, 'sw': 2}#
- direction_angles: Dict[str, int] = {'no': 0, 'nw': 0, 'so': 0, 'sw': 0}#
- classmethod from_pixel(position, world=None)[source]#
Finds the nearest tile to a given pixel coordinate.
This method uses caching to avoid redundant recalculation of the mapping between tile grid positions and their corresponding pixel coordinates for a given world. It also uses squared distance instead of Euclidean distance for better performance.