Documentation ¶
Index ¶
- Variables
- func DirectionTypeStrings() []string
- func Distance(h1, h2 *Hex) float64
- func DistanceSquared(h1, h2 *Hex) float64
- func Equal(a, b *Key) bool
- func RelativeDirectionStrings() []string
- type DirectionType
- type Field
- func (f *Field) At(x, y float64) *Hex
- func (f *Field) Center() (float64, float64)
- func (f *Field) DistanceBetween(a, b Key) float64
- func (f *Field) Get(k Key) *Hex
- func (f Field) HexHeight() int
- func (f Field) HexWidth() int
- func (f *Field) Hexes() []*Hex
- func (f *Field) Ktow(k Key) (float64, float64)
- func (f *Field) Load(keys []Key) error
- func (f *Field) Wtok(x, y float64) Key
- type Hex
- type Key
- func (k Key) Adjacent() map[DirectionType]Key
- func (k Key) ExpandBy(min, max int) []Key
- func (k Key) HexesFrom(other Key) int
- func (k Key) Neighbors() map[Key]DirectionType
- func (k Key) String() string
- func (k Key) ToDirection(dir DirectionType) Key
- func (k Key) ToN() Key
- func (k Key) ToNE() Key
- func (k Key) ToNW() Key
- func (k Key) ToS() Key
- func (k Key) ToSE() Key
- func (k Key) ToSW() Key
- type RelativeDirection
Constants ¶
This section is empty.
Variables ¶
var FlatField = NewField(5, 8, 15)
FlatField is a default Field where the pixel-projection distance between hexes is equal (or close to) in all directions. The hexagons end up being 21 pixels wide by 15 pixels tall.
var FlatFieldDistance = FlatField.DistanceBetween(Key{}, Key{}.ToN())
var Opposite = map[DirectionType]DirectionType{ S: N, SW: NE, NW: SE, N: S, NE: SW, SE: NW, }
Opposite provides the 180 degree opposite to any cardinal DirectionType.
Functions ¶
func DirectionTypeStrings ¶
func DirectionTypeStrings() []string
DirectionTypeStrings returns a slice of all String values of the enum
func DistanceSquared ¶
DistanceSquared returns the distance between two Hexagons multiplied by itself. This is useful to use as a pathfinding heuristic when these values only need to be compared to other outputs of this function, and the cost of finding the square root adds nothing.
func Equal ¶
Equal determines if the M and N values of the passed pointers differ. If either value is nil, then it only returns true if the other is also nil. TODO: this may make more sense in the combat package as that is its only usage.
func RelativeDirectionStrings ¶
func RelativeDirectionStrings() []string
RelativeDirectionStrings returns a slice of all String values of the enum
Types ¶
type DirectionType ¶
type DirectionType int
DirectionType enumerates directions.
const ( N DirectionType = iota NE SE S SW NW )
DirectionTypes represent the 6 edges of a hexagon.
func Actualize ¶
func Actualize(facing DirectionType, relative RelativeDirection) DirectionType
Actualize a relative direction and a concrete direction together to form a new concrete direction. N and Behind make S. S and Forward make S etc.
func DirectionTypeString ¶
func DirectionTypeString(s string) (DirectionType, error)
DirectionTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func DirectionTypeValues ¶
func DirectionTypeValues() []DirectionType
DirectionTypeValues returns all values of the enum
func FindDirection ¶
func FindDirection(origin, projection Key) DirectionType
FindDirection returns the direction one would have to travel in from origin to arrive at projection. Returned values are rounded when the precise value is not one of the 6 hexagonal directions.
func (DirectionType) IsADirectionType ¶
func (i DirectionType) IsADirectionType() bool
IsADirectionType returns "true" if the value is listed in the enum definition. "false" otherwise
func (DirectionType) MarshalJSON ¶
func (i DirectionType) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for DirectionType
func (DirectionType) String ¶
func (i DirectionType) String() string
func (*DirectionType) UnmarshalJSON ¶
func (i *DirectionType) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for DirectionType
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field of hexagons. Provides information about world coordinates.
func NewField ¶
NewField creates an empty Field. The parameters configure the shape of the Hexagons in the Field.
func (*Field) At ¶
At looks for a Hexagon that is located at the world coordinates x,y. Returns nil if there is no Hexagon for those coordinates.
func (*Field) Center ¶
Center returns a world coordinate that half the loaded hexagons are above, half below, half to the left, and half to the right.
func (*Field) DistanceBetween ¶
DistanceBetween calculates the distance between two keys in the field.
type Hex ¶
type Hex struct {
// contains filtered or unexported fields
}
Hex is a part of a Field.
type Key ¶
type Key struct {
M, N int
}
Key is a way of referencing a Hexagon in a Field.
func (Key) Adjacent ¶
func (k Key) Adjacent() map[DirectionType]Key
Adjacent calculates the neighbors of a Key and returns them keyed by direction.
func (Key) ExpandBy ¶
ExpandBy determines the Keys that are between min and max away from the Key. The order is randomised.
func (Key) Neighbors ¶
func (k Key) Neighbors() map[Key]DirectionType
Neighbors calculates the neighbors of a Key and returns them keyed by their Keys.
func (Key) ToDirection ¶
func (k Key) ToDirection(dir DirectionType) Key
type RelativeDirection ¶
type RelativeDirection int
const ( Forward RelativeDirection = iota Behind ForwardLeft ForwardRight BackLeft BackRight )
func RelativeDirectionString ¶
func RelativeDirectionString(s string) (RelativeDirection, error)
RelativeDirectionString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func RelativeDirectionValues ¶
func RelativeDirectionValues() []RelativeDirection
RelativeDirectionValues returns all values of the enum
func (RelativeDirection) IsARelativeDirection ¶
func (i RelativeDirection) IsARelativeDirection() bool
IsARelativeDirection returns "true" if the value is listed in the enum definition. "false" otherwise
func (RelativeDirection) MarshalJSON ¶
func (i RelativeDirection) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for RelativeDirection
func (RelativeDirection) String ¶
func (i RelativeDirection) String() string
func (*RelativeDirection) UnmarshalJSON ¶
func (i *RelativeDirection) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for RelativeDirection