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

Game.LambdaHack.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 Show Vector Binary Vector

Converts a vector in cartesian representation into `Vector`.

Translate a point by a vector.

Particularly simple and fast implementation in the linear representation.

shiftBounded :: X -> Area -> 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.

movesWidth :: [X -> Vector]Source

Vectors of all unit moves, clockwise, starting north-west, parameterized by level width.

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.

Reverse an arbirary vector.

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

Given two distinct locations, 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 loc1 (displacement loc1 loc2) == loc2
```

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.