tuxemon.map_loader module

class tuxemon.map_loader.TMXMapLoader[source]

Bases: object

Maps are loaded from standard tmx files created from a map editor like Tiled. Events and collision regions are loaded and put in the appropriate data structures for the game to understand.

Tiled: http://www.mapeditor.org/

collision_lines_from_object(tiled_object, tile_size)[source]
Parameters:
  • tiled_object (TiledObject) –

  • tile_size (Tuple[int, int]) –

Return type:

Generator[Tuple[Tuple[int, int], Literal[‘up’, ‘down’, ‘left’, ‘right’]], None, None]

extract_tile_collisions(tiled_object, tile_size)[source]
Parameters:
  • tiled_object (TiledObject) –

  • tile_size (Tuple[int, int]) –

Return type:

Generator[Tuple[Tuple[int, int], Mapping[str, Any] | None], None, None]

load(filename)[source]

Load map data from a tmx map file.

Loading the map data is done using the pytmx library.

Specifications for the TMX map format can be found here: https://github.com/bjorn/tiled/wiki/TMX-Map-Format

The list of tiles is structured in a way where you can access an individual tile by index number.

The collision map is a set of (x,y) coordinates that the player cannot walk through. This set is generated based on collision regions defined in the map file.

Examples:

In each map, there are three types of objects: collisions, conditions, and actions*. Here is how an action would be defined using the Tiled map editor:

autogen/images/map/map_editor_action01.png
Parameters:

filename (str) – The path to the tmx map file to load.

Returns:

The loaded map.

Return type:

TuxemonMap

load_event(obj, tile_size)[source]

Load an Event from the map.

Parameters:
  • obj (TiledObject) – Tiled object that represents an event.

  • tile_size (Tuple[int, int]) – Size of a tile.

Returns:

Loaded event.

Return type:

EventObject

process_line(line, tile_size)[source]

Identify the tiles on either side of the line and block movement along it.

Parameters:
  • line (TiledObject) –

  • tile_size (Tuple[int, int]) –

Return type:

Generator[Tuple[Tuple[int, int], Tuple[int, int], Literal[‘horizontal’, ‘vertical’]], None, None]

static region_tiles(region, grid_size)[source]

Apply region properties to individual tiles.

Right now our collisions are defined in our tmx file as large regions that the player can’t pass through. We need to convert these areas into individual tile coordinates that the player can’t pass through. Loop through all of the collision objects in our tmx file. The region’s bounding box will be snapped to the nearest tile coordinates.

Parameters:
  • region (TiledObject) – The Tiled object which contains collisions and movement modifiers.

  • grid_size (Tuple[int, int]) – The tile grid size.

Yields:

Tuples with form (tile position, properties).

Return type:

Generator[Tuple[Tuple[int, int], Mapping[str, Any] | None], None, None]

class tuxemon.map_loader.YAMLEventLoader[source]

Bases: object

Support for reading game events from a YAML file.

load_events(path)[source]

Load EventObjects from YAML file.

Parameters:

path (str) – Path to the file.

Return type:

Iterator[EventObject]