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#

class miniworlds.worlds.tiled_world.tile_factory.TileFactory[Quellcode]#

TileBase#

class miniworlds.worlds.tiled_world.tile_elements.TileBase(position, world=None)[Quellcode]#

Base class for Tiles and TileDelimiters (like Corners, Edges).

add_actor(actor)[Quellcode]#

Places an actor on this tile.

corner_vectors: dict = {}#
classmethod from_pixel(pixel_position, world)[Quellcode]#

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.

Rückgabetyp:

TileBase

Parameter:
  • pixel_position (Tuple[float, float]) – The (x, y) pixel position.

  • world (world_mod.World) – The world instance containing the tile layout.

Rückgabe:

The tile object closest to the given pixel position.

Rückgabetyp:

TileBase

abstract classmethod from_position(position, world)[Quellcode]#

Create a tile from a world-relative position.

Rückgabetyp:

TileBase

get_actors()[Quellcode]#

Returns all actors currently on this tile.

Rückgabetyp:

List

static get_local_center_coordinate(world)[Quellcode]#

Returns the center point offset for a tile, in local pixel coordinates.

Rückgabetyp:

Tuple[float, float]

get_local_corner_points()[Quellcode]#

Returns corner point offsets for rendering.

get_neighbour_tiles()[Quellcode]#

Returns neighboring tiles around this tile.

Rückgabetyp:

List[Tile]

static get_position_pixel_dict(world)[Quellcode]#

Returns a mapping of tile positions to pixel coordinates.

Rückgabetyp:

dict

merge(other)[Quellcode]#

Merge tile positions from another tile at the same location.

tile_vectors: dict = {}#

Tile#

class miniworlds.worlds.tiled_world.tile.Tile(position, world=None)[Quellcode]#
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)}#
distance_to(other)[Quellcode]#
Rückgabetyp:

float

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_actor(actor)[Quellcode]#
Rückgabetyp:

Tile

classmethod from_pixel(pixel_position, world=None)[Quellcode]#

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.

Rückgabetyp:

Tile

Parameter:
  • pixel_position (Tuple[float, float]) – The (x, y) pixel position.

  • world (world_mod.World) – The world instance containing the tile layout.

Rückgabe:

The tile object closest to the given pixel position.

Rückgabetyp:

TileBase

classmethod from_position(position, world)[Quellcode]#

Create a tile from a world-relative position.

Rückgabetyp:

Tile

get_neighbour_corners()[Quellcode]#
Rückgabetyp:

List[Corner]

static get_position_pixel_dict(world)[Quellcode]#

Returns a mapping of tile positions to pixel coordinates.

Rückgabetyp:

dict

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)}#
to_center()[Quellcode]#
Rückgabetyp:

Tuple[float, float]

to_pixel()[Quellcode]#
Rückgabetyp:

Tuple[float, float]

Edge#

class miniworlds.worlds.tiled_world.edge.Edge(position, direction, world)[Quellcode]#
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 direction_vectors()[Quellcode]#

Returns the available directions.

classmethod from_position(position, world)[Quellcode]#

Create a tile delimiter (override expected).

static get_position_pixel_dict(world)[Quellcode]#

Returns a mapping of tile positions to pixel coordinates.

start_angle()[Quellcode]#

Override: starting angle offset for layouting (e.g. hex rotation).

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)[Quellcode]#
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}#
static direction_vectors()[Quellcode]#

Returns the available directions.

classmethod from_pixel(position, world=None)[Quellcode]#

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.

Parameter:
  • pixel_position (Tuple[float, float]) – The (x, y) pixel position.

  • world (world_mod.World) – The world instance containing the tile layout.

Rückgabe:

The tile object closest to the given pixel position.

Rückgabetyp:

TileBase

classmethod from_position(position, world)[Quellcode]#

Create a tile delimiter (override expected).

classmethod from_tile(position, direction_string)[Quellcode]#
start_angle()[Quellcode]#

Override: starting angle offset for layouting (e.g. hex rotation).