imj-base-0.1.0.2: Game engine with geometry, easing, animated text, delta rendering.

Safe HaskellNone
LanguageHaskell2010

Imj.Physics.Discrete

Contents

Synopsis

Discrete position and speed

In a terminal, it is only possible to represent objects at discrete locations, hence, movable objects have discrete speeds and positions.

data PosSpeed Source #

Represents a discrete position and a discrete speed.

Constructors

PosSpeed 

Handling collisions

To give a better realism in the game, if the location before a collision is not touching a wall, then the position after the collision will be forced to touch a wall. Note that forcing the position only happens if the absolute speed of one coordinate is >= 2.

mirrorSpeedAndMoveToPrecollisionIfNeeded Source #

Arguments

:: (Coords Pos -> Location)

Interaction function.

-> PosSpeed

Input position and speed.

-> (PosSpeed, CollisionStatus)

The speed was potentially mirrored

On collision, mirrors speed and moves to the pre-collision position.

data CollisionStatus Source #

Constructors

NoCollision

no collision on the trajectory, position is unchanged

PreCollision

a collision exists on the trajectory, position was changed to be just before the collision and speed was mirrored

firstCollision Source #

Arguments

:: (Coords Pos -> Location)

The collision function.

-> [Coords Pos]

The trajectory (the first position is expected to be collision-free).

-> Maybe (Mirror, Coords Pos)

On collision, the kind of speed mirroring that should be applied and the position just before the collision.

Handles the first collision on a trajectory, assuming that the first position has no collision.

data Location Source #

Describes if a collision exists.

Constructors

InsideWorld

No collision.

OutsideWorld

A collision exists.