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

Safe HaskellSafe-Infered

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 lenth 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.

toVector :: X -> VectorXY -> VectorSource

Converts a vector in cartesian representation into Vector.

shift :: Point -> Vector -> PointSource

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.

euclidDistSq :: X -> Vector -> Vector -> IntSource

Squared euclidean distance between two unit vectors.

diagonal :: X -> Vector -> BoolSource

Checks whether a unit vector is a diagonal direction, as opposed to cardinal.

neg :: Vector -> VectorSource

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..

displacement :: Point -> Point -> VectorSource

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 vector from a point to another. W have