LambdaHack-0.7.0.0: A game engine library for roguelike dungeon crawlers

Game.LambdaHack.Common.Vector

Contents

Description

Basic operations on bounded 2D vectors, with an efficient, but not 1-1 and not monotonic Enum instance.

Synopsis

Documentation

data Vector Source #

2D vectors in cartesian representation. Coordinates grow to the right and down, so that the (1, 1) vector points to the bottom-right corner of the screen.

Constructors

 Vector Fieldsvx :: X vy :: Y

Instances

 Source # MethodstoEnum :: Int -> Vector #enumFrom :: Vector -> [Vector] #enumFromThen :: Vector -> Vector -> [Vector] #enumFromTo :: Vector -> Vector -> [Vector] #enumFromThenTo :: Vector -> Vector -> Vector -> [Vector] # Source # Methods(==) :: Vector -> Vector -> Bool #(/=) :: Vector -> Vector -> Bool # Source # Methods(<) :: Vector -> Vector -> Bool #(<=) :: Vector -> Vector -> Bool #(>) :: Vector -> Vector -> Bool #(>=) :: Vector -> Vector -> Bool #max :: Vector -> Vector -> Vector #min :: Vector -> Vector -> Vector # Source # Methods Source # MethodsshowsPrec :: Int -> Vector -> ShowS #showList :: [Vector] -> ShowS # Source # Associated Typestype Rep Vector :: * -> * # Methodsfrom :: Vector -> Rep Vector x #to :: Rep Vector x -> Vector # Source # Methodsput :: Vector -> Put #putList :: [Vector] -> Put # Source # Methodsrnf :: Vector -> () # type Rep Vector Source # type Rep Vector = D1 * (MetaData "Vector" "Game.LambdaHack.Common.Vector" "LambdaHack-0.7.0.0-3XPyz9bw1i28qJIoWU6CaM" False) (C1 * (MetaCons "Vector" PrefixI True) ((:*:) * (S1 * (MetaSel (Just Symbol "vx") NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 * X)) (S1 * (MetaSel (Just Symbol "vy") NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 * Y))))

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

Checks whether a unit vector is a diagonal direction, as opposed to cardinal. If the vector is not unit, it checks that the vector is not horizontal nor vertical.

Reverse an arbirary vector.

The lenght of a vector in the chessboard metric, where diagonal moves cost 1.

Squared euclidean distance between two vectors.

moves :: [Vector] Source #

Vectors of all unit moves in the chessboard metric, clockwise, starting north-west.

Vectors of all cardinal direction unit moves, clockwise, starting north.

Vectors of all diagonal direction unit moves, clockwise, starting north.

Arguments

 :: X -> Y limit the search to this area -> Point position to find neighbours of -> [Point]

All (8 at most) closest neighbours of a point within an area.

Arguments

 :: X -> Y limit the search to this area -> Point position to find neighbours of -> [Point]

All (4 at most) cardinal direction neighbours of a point within an area.

Translate a point by a vector.

shiftBounded :: X -> Y -> Point -> Vector -> Point Source #

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

trajectoryToPath :: Point -> [Vector] -> [Point] Source #

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

trajectoryToPathBounded :: X -> Y -> Point -> [Vector] -> [Point] Source #

A list of points that a list of vectors leads to, bounded by level size.

The vector between the second point and the first. We have

shift pos1 (pos2 vectorToFrom pos1) == pos2

The arguments are in the same order as in the underlying scalar subtraction.

pathToTrajectory :: [Point] -> [Vector] Source #

A list of vectors between a list of points.

Rotate a vector by the given angle (expressed in radians) counterclockwise and return a unit vector approximately in the resulting direction.

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.

Internal operations

Maximal supported vector X and Y coordinates.

Currently unused.

Given a vector of arbitrary non-zero length, produce a unit vector that points in the same direction (in the chessboard metric). Of several equally good directions it picks one of those that visually (in the euclidean metric) maximally align with the original vector.