Package tdl :: Module map :: Class Map |
[frames] | no frames]

# Class Map

source code

    object --+
             |
            Map

Fast field-of-view and path-finding on stored data.

Set map conditions with the walkable and transparency attributes, this object can be iterated and checked for containment similar to consoles.

For example, you can set all tiles and transparent and walkable with the following code:

       map = tdl.map.Map(80, 60)
       for x,y in map:
           map.transparent[x,y] = true
           map.walkable[x,y] = true

Since: 1.5.0

Instance Methods
__init__(self, width, height) Create a new Map with width and height. | source code
__del__(self) | source code
iter((x, y), ...) |
compute_fov(self, x, y, fov=`'``PERMISSIVE``'`, radius=None, light_walls=True, sphere=True, cumulative=False) Compute the field-of-view of this Map and return an iterator of the points touched. | source code
[(x, y), ...] |
compute_path(self, start_x, start_y, dest_x, dest_y, diagonal_cost=1.41421356237) Get the shortest path between two points. | source code
__iter__(self) | source code
__contains__(self, position) | source code
Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Instance Variables
| fov Map tiles touched by a field-of-view computation, access this attribute with map.fov[x,y]
| transparent Map transparency, access this attribute with map.transparent[x,y]
| walkable Map accessibility, access this attribute with map.walkable[x,y]

Properties
Inherited from `object`: `__class__`

Method Details

### __init__(self, width, height) (Constructor) | source code
Create a new Map with width and height. Parameters: `width` (int) - Width of the new Map instance, in tiles. `width` (int) - Height of the new Map instance, in tiles. `height` (int) Overrides: object.__init__

### compute_fov(self, x, y, fov=`'``PERMISSIVE``'`, radius=None, light_walls=True, sphere=True, cumulative=False) | source code
Compute the field-of-view of this Map and return an iterator of the points touched. Parameters: `x` (int) - x center of the field-of-view `y` (int) - y center of the field-of-view `fov` (string) - The type of field-of-view to be used. Available types are: 'BASIC', 'DIAMOND', 'SHADOW', 'RESTRICTIVE', 'PERMISSIVE', 'PERMISSIVE0', 'PERMISSIVE1', ..., 'PERMISSIVE8' `radius` (int) - Raduis of the field-of-view. `light_walls` (boolean) - Include or exclude wall tiles in the field-of-view. `sphere` (boolean) - True for a spherical field-of-view. False for a square one. `cumulative` (boolean) Returns: iter((x, y), ...) An iterator of (x, y) points of tiles touched by the field-of-view. Unexpected behaviour can happen if you modify the Map while using the iterator. You can use the Map's fov attribute as an alternative to this iterator.

### compute_path(self, start_x, start_y, dest_x, dest_y, diagonal_cost=1.41421356237) | source code
Get the shortest path between two points. The start position is not included in the list. Parameters: `diagnalCost` (float) - Multiplier for diagonal movement. Can be set to zero to disable diagonal movement entirely. Returns: [(x, y), ...] Returns a the shortest list of points to get to the destination position from the starting position

Instance Variable Details

### fov Map tiles touched by a field-of-view computation, access this attribute with map.fov[x,y] Is True if a the tile is if view, otherwise False. You can set to this attribute if you want, but you'll typically be using it to read the field-of-view of a compute_fov call.

### transparent Map transparency, access this attribute with map.transparent[x,y] Set to True to allow field-of-view rays, False will block field-of-view. Transparent tiles only affect field-of-view.

### walkable Map accessibility, access this attribute with map.walkable[x,y] Set to True to allow path-finding through that tile, False will block passage to that tile. Walkable tiles only affect path-finding.