NAME
Game::TextMapper::Schroeder::Square - a role for square map generators
SYNOPSIS
# create a map
package
World;
use
Modern::Perl;
use
Mojo::Base -base;
use
Role::Tiny::With;
# use it
package
main;
my
$map
= World->new(
height
=> 10,
width
=> 10);
DESCRIPTION
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
.
METHODS
reverse
Reverses a direction.
neighbors
The list of directions for neighbours one step away (0 to 3).
neighbors2
The list of directions for neighbours two steps away (0 to 7).
random_neighbor
A random direction for a neighbour one step away (a random integer from 0 to 3).
random_neighbor2
A random direction for a neighbour two steps away (a random integer from 0 to 7).
neighbor($square, $i)
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.
$i
is a direction (0 to 3).
neighbor2($square, $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.
$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.
$i
is a direction (0 to 3).
distance($x1, $y1, $x2, $y2) or distance($coords1, $coords2)
say
$map
->distance(
"0203"
,
"0003"
);
# 2
Returns the distance between two coordinates.
arrows
A helper that returns the SVG fragments for arrows in four directions, to be used in a defs
element.
SEE ALSO
Game::TextMapper::Schroeder::Base Game::TextMapper::Schroeder::Hex