NAME
Game::TextMapper::Schroeder::Hex - a role for hex 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 hex 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 5).
neighbors2
The list of directions for neighbours two steps away (0 to 11).
random_neighbor
A random direction for a neighbour one step away (a random integer from 0 to 5).
random_neighbor2
A random direction for a neighbour two steps away (a random integer from 0 to 11).
neighbor($hex, $i)
say
join
(
","
,
$map
->neighbor(
"0203"
, 1));
# 2,2
Returns the coordinates of a neighbor in a particular direction (0 to 5), one step away.
$hex
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 5).
neighbor2($hex, $i)
say
join
(
","
,
$map
->neighbor2(
"0203"
, 1));
# 0, 3
Returns the coordinates of a neighbor in a particular direction (0 to 11), two steps away.
$hex
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 5).
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 six directions, to be used in a defs
element.
SEE ALSO
Game::TextMapper::Schroeder::Base Game::TextMapper::Schroeder::Square