TCOD::Map - A grid of cells for field-of-view calculations
use TCOD; my $map = TCOD::Map->new( 10, 10 ); $map->set_properties( 6, 5, 0, 0 ); # Opaque cell $map->compute_fov( 5, 5 ); $map->is_in_fov( 7, 5 ); # False: [ 6, 5 ] is opaque and obstructs the view from [ 5, 5 ]
A TCOD::Map represents a grid of cells that can be used for path-finding and field-of-view calculations.
$map = TCOD::Map->new( $width, $height );
Construct a new TCOD::Map. Takes the width and height of the map in cells as positional arguments.
$map->set_properties( $x, $y, $walkable, $transparent );
Set the properties of a cell in the map. Specifically, $walkable should be true if this cell does not obstruct the pathfinder, and $transparent should be true if this cell does not obstruct the field of vision algorithm.
$walkable
$transparent
$map->clear( $walkable, $transparent );
Resets all of a map's cells to have the specified attributes.
$source->copy( $destination );
Copy the cells of one map into another. The destination map should be at least large enough to hold the source map.
$map->compute_fov( $x, $y, $radius, $light_walls, $algorithm );
Compute the field of view from the specified cell. The value in the $radius parameter will determine how far to extend the line of sight, while the value in $light_walls will determine whether walls adjacent to visible cells should themselves be visible.
$radius
$light_walls
The value in $algorithm should be one of the values in the FOV enum. If no value is set, it will default to TCOD::FOV_BASIC.
$algorithm
TCOD::FOV_BASIC
$bool = $map->is_in_fov( $x, $y );
After computing the field of view for this map, this method queries whether a particular cell is visible or not.
$bool = $map->is_transparent( $x, $y );
Returns true if the specified cell has the attribute transparent set to a true value.
transparent
$bool = $map->is_walkable( $x, $y );
Returns true if the specified cell has the attribute walkable set to a true value.
walkable
$width = $map->get_width;
Returns the width of the map in cells. This is the same value used during object construction.
$height = $map->get_height;
Returns the height of the map in cells. This is the same value used during object construction.
Copyright 2021 José Joaquín Atria
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.
To install TCOD, copy and paste the appropriate command in to your terminal.
cpanm
cpanm TCOD
CPAN shell
perl -MCPAN -e shell install TCOD
For more information on module installation, please visit the detailed CPAN module installation guide.