LambdaHack-0.2.10.5: A roguelike game engine in early and active development

Game.LambdaHack.Common.Vector

Description

Basic operations on 2D vectors represented in an efficient, but not unique, way.

Synopsis

# Documentation

data Vector Source

2D vectors represented as offsets in the linear framebuffer indexed by `Point`.

A newtype is used to prevent mixing up the type with `Point` itself. Note that the offset representations of a vector is usually not unique. E.g., for vectors of length 1 in the chessboard metric, used to denote geographical directions, the representations are pairwise distinct if and only if the level width and height are at least 3.

Instances

 Eq Vector Ord Vector Read Vector Show Vector Binary Vector

Converts a vector in cartesian representation into `Vector`.

Converts a unit vector in cartesian representation into `Vector`.

Translate a point by a vector.

Particularly simple and fast implementation in the linear representation.

shiftBounded :: X -> (X, Y, X, Y) -> Point -> Vector -> PointSource

Translate a point by a vector, but only if the result fits in an area.

moves :: X -> [Vector]Source

Vectors of all unit moves, clockwise, starting north-west.

isUnit :: X -> Vector -> BoolSource

Tells if a vector has length 1 in the chessboard metric.

Squared euclidean distance between two unit vectors.

Checks whether a unit vector is a diagonal direction, as opposed to cardinal. If the vector is not unit, it reject horizontal and vertical vectors.

Reverse an arbirary vector.

towards :: X -> Point -> Point -> VectorSource

Given two distinct positions, determine the direction (a unit vector) in which one should move from the first in order to get closer to the second. Ignores obstacles. Of several equally good directions (in the chessboard metric) it picks one of those that visually (in the euclidean metric) maximally align with the vector between the two points.

A vector from a point to another. We have

``` shift pos1 (displacement pos1 pos2) == pos2
```

Particularly simple and fast implementation in the linear representation.

displacePath :: [Point] -> [Vector]Source

A list of vectors between a list of points.

shiftPath :: Point -> [Vector] -> [Point]Source

A list of points that a list of vectors leads to.