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

Game.LambdaHack.Common.Point

Description

Basic operations on 2D points represented as linear offsets.

Synopsis

# Documentation

data Point Source

The type of positions on the 2D level map, heavily optimized.

We represent the (level map on the) screen as a linear framebuffer, where `Point` is an `Int` offset counted from the first cell. We do bounds check for the X size whenever we convert between representations and each subsequent array access performs another check, effectively for Y size. After dungeon is generated (using `PointXY`, not `Point`), and converted to the `Point` representation, points are used mainly as keys and not constructed often, so the performance will improve due to smaller save files, the use of `EnumMap` and cheaper array indexing, including cheaper bounds checks.

Instances

 Enum Point Eq Point Ord Point Show Point Ix Point Binary Point Random Point

Conversion from cartesian coordinates to `Point`.

Print a point as a tuple of cartesian coordinates.

The top-left corner position of the level.

chessDist :: X -> Point -> Point -> IntSource

The distance between two points in the chessboard metric.

adjacent :: X -> Point -> Point -> BoolSource

Checks whether two points are adjacent on the map (horizontally, vertically or diagonally).

vicinity :: X -> Y -> Point -> [Point]Source

Returns the 8, or less, surrounding positions of a given position.

vicinityCardinal :: X -> Y -> Point -> [Point]Source

Returns the 4, or less, surrounding positions in cardinal directions from a given position.

inside :: X -> Point -> (X, Y, X, Y) -> BoolSource

Checks that a point belongs to an area.

Calculate the displacement vector from a position to another.

bla :: X -> Y -> Int -> Point -> Point -> Maybe [Point]Source

Bresenham's line algorithm generalized to arbitrary starting `eps` (`eps` value of 0 gives the standard BLA). Skips the source point and goes through the second point to the edge of the level. GIves `Nothing` if the points are equal.