Game::TextMapper::Schroeder::Square - a role for square map generators
# create a map package World; use Modern::Perl; use Mojo::Base -base; use Role::Tiny::With; with 'Game::TextMapper::Schroeder::Base'; with 'Game::TextMapper::Schroeder::Square'; # use it package main; my $map = World->new(height => 10, width => 10);
This role provides basic functionality for map generation with square maps: the number of neighbours within one or two regions distance, how to pick a random neighbour direction, how to compute the coordinates of these neighbours, how to draw arrows towards these neighbours.
This inherits attributes and methods from Game::TextMapper::Schroeder::Base, such as width and height.
width
height
Reverses a direction.
The list of directions for neighbours one step away (0 to 3).
The list of directions for neighbours two steps away (0 to 7).
A random direction for a neighbour one step away (a random integer from 0 to 3).
A random direction for a neighbour two steps away (a random integer from 0 to 7).
say join(",", $map->neighbor("0203", 1)); # 2,2
Returns the coordinates of a neighbor in a particular direction (0 to 3), one step away.
$square is an array reference of coordinates or a string that can be turned into one using the xy method from Game::TextMapper::Schroeder::Base.
$square
xy
$i is a direction (0 to 3).
$i
say join(",", $map->neighbor2("0203", 1)); # 1, 2
Returns the coordinates of a neighbor in a particular direction (0 to 7), two steps away.
say $map->distance("0203", "0003"); # 2
Returns the distance between two coordinates.
A helper that returns the SVG fragments for arrows in four directions, to be used in a defs element.
defs
Game::TextMapper::Schroeder::Base Game::TextMapper::Schroeder::Hex
To install Game::TextMapper, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Game::TextMapper
CPAN shell
perl -MCPAN -e shell install Game::TextMapper
For more information on module installation, please visit the detailed CPAN module installation guide.