Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data PosSpeed = PosSpeed {
- _posSpeedPos :: !(Coords Pos)
- _posSpeedSpeed :: !(Coords Vel)
- mirrorSpeedAndMoveToPrecollisionIfNeeded :: (Coords Pos -> Location) -> PosSpeed -> (PosSpeed, CollisionStatus)
- data CollisionStatus
- firstCollision :: (Coords Pos -> Location) -> [Coords Pos] -> Maybe (Mirror, Coords Pos)
- data Location
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.
Represents a discrete position and a discrete speed.
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 #
:: (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 #
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 |
:: (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.