tuxemon.map module

class tuxemon.map.PathfindNode(value, parent=None)[source]

Bases: object

Used in path finding search.

Parameters:
  • value (Tuple[int, int]) –

  • parent (Optional[PathfindNode]) –

get_depth()[source]
Return type:

int

get_parent()[source]
Return type:

PathfindNode | None

get_value()[source]
Return type:

Tuple[int, int]

set_parent(parent)[source]
Parameters:

parent (PathfindNode) –

Return type:

None

class tuxemon.map.RegionProperties(*args, **kwargs)[source]

Bases: dict

continue: Literal['up', 'down', 'left', 'right']
enter: Sequence[Literal['up', 'down', 'left', 'right']]
exit: Sequence[Literal['up', 'down', 'left', 'right']]
key: str
class tuxemon.map.RegionPropertiesOptional(*args, **kwargs)

Bases: dict

continue: Literal['up', 'down', 'left', 'right']
key: str
class tuxemon.map.TuxemonMap(events, inits, interacts, surfable_map, collision_map, collisions_lines_map, tiled_map, maps, filename)[source]

Bases: object

Contains collisions geometry and events loaded from a file.

Supports entity movement and pathfinding.

Parameters:
  • events (Sequence[EventObject]) –

  • inits (Sequence[EventObject]) –

  • interacts (Sequence[EventObject]) –

  • surfable_map (Sequence[Tuple[int, int]]) –

  • collision_map (MutableMapping[Tuple[int, int], Optional[RegionProperties]]) –

  • collisions_lines_map (Set[Tuple[Tuple[int, int], Direction]]) –

  • tiled_map (TiledMap) –

  • maps (dict) –

  • filename (str) –

initialize_renderer()[source]

Initialize the renderer for the map and sprites.

Returns:

Renderer for the map.

Return type:

None

reload_tiles()[source]

Reload the map tiles.

Return type:

None

tuxemon.map.angle_of_points(point0, point1)[source]

Find angle between two points.

Parameters:
  • point0 (Tuple[int, int]) – First point.

  • point1 (Tuple[int, int]) – Second point.

Returns:

Angle between the two points.

Return type:

float

tuxemon.map.extract_region_properties(properties)[source]

Given a dictionary from Tiled properties, return a dictionary suitable for collision detection.

Uses exit_to, enter_from, and continue keys.

Parameters:

properties (Mapping[str, str]) – Dictionary of data from Tiled for object, tile, etc.

Returns:

New dictionary for collision use.

Return type:

RegionProperties | None

tuxemon.map.get_direction(base, target)[source]
Parameters:
  • base (Vector2 | Tuple[int, int]) –

  • target (Vector2 | Tuple[int, int]) –

Return type:

Literal[‘up’, ‘down’, ‘left’, ‘right’]

tuxemon.map.orientation_by_angle(angle)[source]

Return “horizontal” or “vertical”.

Parameters:

angle (float) – Angle with the horizontal axis.

Returns:

Whether the orientation is horizontal or vertical.

Return type:

Literal[‘horizontal’, ‘vertical’]

tuxemon.map.point_to_grid(point, grid_size)[source]

Snap pixel coordinate to grid, then convert to tile coords.

Parameters:
  • point (Tuple[int, int]) – Point to snap.

  • grid_size (Tuple[int, int]) – Grid size.

Returns:

Snapped point.

Return type:

Tuple[int, int]

tuxemon.map.proj(point)[source]

Project 3d coordinates to 2d.

Not necessarily for use on a screen.

Parameters:

point (Vector3) – The 3d vector to project.

Returns:

2d projection vector.

Return type:

Vector2

tuxemon.map.snap_interval(value, interval)[source]
Parameters:
  • value (float) –

  • interval (int) –

Return type:

int

tuxemon.map.snap_outer_point(point, grid_size)[source]

Snap point to nearest grid intersection.

  • If point is rounded up, the coords are 1 less on each axis.

Parameters:
  • point (Tuple[int, int]) – Point to snap.

  • grid_size (Tuple[int, int]) – Grid size.

Returns:

Snapped point.

Return type:

Tuple[int, int]

tuxemon.map.snap_point(point, grid_size)[source]

Snap point to nearest grid intersection.

Parameters:
  • point (Tuple[int, int]) – Point to snap.

  • grid_size (Tuple[int, int]) – Grid size.

Returns:

Snapped point.

Return type:

Tuple[int, int]

tuxemon.map.snap_rect(rect, grid_size)[source]

Align all vertices to the nearest point.

Parameters:
  • rect (RectTypeVar) – Rect to snap.

  • grid_size (Tuple[int, int]) – Grid size.

Returns:

Snapped rect.

Return type:

RectTypeVar

tuxemon.map.tiles_inside_rect(rect, grid_size)[source]

Iterate all tile positions within this rect.

The positions will be changed from pixel/map coords to tile coords.

Parameters:
  • rect (ReadOnlyRect) – Area to get tiles in.

  • grid_size (Tuple[int, int]) – Size of each tile.

Yields:

Tile positions inside the rect.

Return type:

Generator[Tuple[int, int], None, None]

tuxemon.map.translate_short_path(path, position=(0, 0))[source]

Translate condensed path strings into coordinate pairs.

Uses a string of U D L R characters; Up Down Left Right. Passing a position will make the path relative to that point.

Parameters:
  • path (str) – String of path directions; ie “uldr”.

  • position (Tuple[int, int]) – Starting point of the path.

Yields:

Positions in the path.

Return type:

Generator[Tuple[int, int], None, None]