Safe Haskell | None |
---|---|
Language | Haskell2010 |
- getGameParameters :: (Render e, MonadReader e m, MonadIO m) => m GameParameters
- data GameParameters = GameParameters {}
- data Level = Level {
- _levelNumber :: !Int
- _levelTarget :: !Int
- _levelStatus :: !(Maybe LevelFinished)
- checkTargetAndAmmo :: Int -> Int -> Int -> SystemTime -> Maybe LevelFinished
- data World = World {
- _worldNumbers :: ![Number]
- _worldShip :: !BattleShip
- _worldSpace :: !Space
- _worldAnimations :: ![Animation]
- _worldEmbedded :: !InTerminal
- worldSizeFromLevel :: Int -> WorldShape -> Size
- mkWorld :: MonadIO m => InTerminal -> Size -> WallDistribution -> [Int] -> Int -> m World
- gameMotionPeriod :: DiffTime
- moveWorld :: KeyTime -> World -> World
- renderWorld :: (Draw e, MonadReader e m, MonadIO m) => World -> m ()
- laserEventAction :: Direction -> World -> ([Number], [Number], Maybe (LaserRay Actual), Int)
- mkInTerminal :: MonadIO m => Size -> m (Either String InTerminal)
- data InTerminal = InTerminal {
- _inTerminalSize :: !(Maybe (Window Int))
- _inTerminalUpperLeft :: !(Coords Pos)
- data Space
- data Material
- mkEmptySpace :: Size -> Space
- mkDeterministicallyFilledSpace :: Size -> Space
- mkRandomlyFilledSpace :: RandomParameters -> Size -> IO Space
- data RandomParameters = RandomParameters {}
- data Strategy = StrictlyOneComponent
- location :: Coords Pos -> Space -> Location
- scopedLocation :: Space -> Maybe (Window Int) -> Coords Pos -> Boundaries -> Coords Pos -> Location
- data Boundaries
- createRandomNonCollidingPosSpeed :: Space -> IO PosSpeed
- renderSpace :: (Draw e, MonadReader e m, MonadIO m) => Space -> Coords Pos -> m (Coords Pos)
- updateMovableItem :: Space -> PosSpeed -> PosSpeed
- data BattleShip = BattleShip {
- _shipPosSpeed :: !PosSpeed
- _shipAmmo :: !Int
- _shipSafeUntil :: !(Maybe SystemTime)
- _shipCollisions :: ![Number]
- accelerateShip :: Direction -> BattleShip -> BattleShip
- data Number = Number {
- _numberPosSpeed :: !PosSpeed
- _numberNum :: !Int
- mkWorldContainer :: World -> RectContainer
- module Imj.Graphics.UI.Animation
- data WallDistribution
- data WorldShape
- data LevelFinished = LevelFinished {
- _levelFinishedResult :: !GameStops
- _levelFinishedWhen :: !SystemTime
- _levelFinishedCurrentMessage :: !MessageState
- data GameStops
- module Imj.Graphics.Render
- data ColorString :: *
Parameters
When the game starts, the player can chose World
parameters:
WorldShape
: square or rectangularWorld
where the width is twice the heightWallDistribution
: Should theWorld
have walls, and what kind of walls.
getGameParameters :: (Render e, MonadReader e m, MonadIO m) => m GameParameters Source #
Displays the configuration UI showing the game creation options, and returns when the player has finished chosing the options.
data GameParameters Source #
Level
There are 12 levels in Hamazed, numbered from 1 to 12.
Level | |
|
Level termination
:: Int | Remaining ammo |
-> Int | The current sum of all shot |
-> Int | The |
-> SystemTime | The current time |
-> Maybe LevelFinished |
World
A World
brings together:
- game elements :
Space
,BattleShip
andNumber
s, - rendering elements:
Animation
s, - terminal-awareness :
InTerminal
World | |
|
Create the world
The World
size decreases with increasing Level
numbers.
worldSizeFromLevel
gives the Size
of the World
based on
the Level
number and the WorldShape
:
:: Int |
|
-> WorldShape | |
-> Size |
:: MonadIO m | |
=> InTerminal | Tells where to draw the |
-> Size | The dimensions |
-> WallDistribution | How the |
-> [Int] | The numbers for which we will create |
-> Int | Ammunition : how many laser shots are available. |
-> m World |
Update World
Every gameMotionPeriod
seconds, the positions of BattleShip
and Numbers
are updated according to their speeds:
Moves elements of game logic (Number
s, BattleShip
).
Note that Animation
s are not updated.
Render World
renderWorld :: (Draw e, MonadReader e m, MonadIO m) => World -> m () Source #
World utilities
laserEventAction
returns the effect a laser shot it has on the World
.
:: Direction | The direction of the laser shot |
-> World | |
-> ([Number], [Number], Maybe (LaserRay Actual), Int) |
|
Computes the effect of an laser shot on the World
.
InTerminal
InTerminal
allows to place the game in the center of the terminal.
:: MonadIO m | |
=> Size | Measures the dimensions of the inner content of the |
-> m (Either String InTerminal) |
Will compute the position of the World
so as to display it in the
center of the terminal window.
data InTerminal Source #
InTerminal | |
|
Space
Space
describes the environment in which Number
s and the BattleShip
live.
It can be composed of Air
, where BattleShip
and Number
s are free to move, and of
Wall
.
Simple creation
mkEmptySpace :: Size -> Space Source #
Creates a rectangular empty space of size specified in parameters.
mkDeterministicallyFilledSpace :: Size -> Space Source #
Creates a rectangular deterministic space of size specified in parameters.
Randomized creation
mkRandomlyFilledSpace
places Wall
s at random and discards resulting
Space
s which have more than one Air
connected component.
This way, the BattleShip
is guaranteed to be able to reach any part of
the Space
, and Number
s.
Generating a big Space
with a very small block size can
be computationnaly expensive because the probability to have a single Air
connected component drops very fast (probably at least exponentially)
towards zero with increasing sizes.
mkRandomlyFilledSpace :: RandomParameters -> Size -> IO Space Source #
Creates a rectangular random space of size specified in parameters, with a
one-element border. IO
is used for random numbers generation.
data RandomParameters Source #
Parameters for random walls creation.
RandomParameters | |
|
StrictlyOneComponent | There should be a single connected component of air. This way, the ship can reach any allowed location without having to go
through |
Collision detection
location
is the standard collision detection function that considers
that being outside the world means being in collision.
scopedLocation
prevides more options with the use of Boundaries
to
defines the collision detection scopes.
location :: Coords Pos -> Space -> Location Source #
Considers that outside Space
, everything is OutsideWorld
data Boundaries Source #
WorldFrame | Just the world. |
TerminalWindow | The terminal, not the world. |
Both | The terminal. |
Collision detection utilities
createRandomNonCollidingPosSpeed :: Space -> IO PosSpeed Source #
Creates a PosSpeed
such that its position is not colliding,
and moves to precollision and mirrors speed if a collision is detected for
the next step (see mirrorSpeedAndMoveToPrecollisionIfNeeded
).
Render
Movable items
A movable item's PosSpeed
is updated using updateMovableItem
at each MoveFlyingItems
event:
BattleShip
data BattleShip Source #
BattleShip | |
|
Accelerate BattleShip
The BattleShip
is controlled in (discrete) acceleration by the player
using the keyboard.
accelerateShip :: Direction -> BattleShip -> BattleShip Source #
Note that the position of the BattleShip
remains unchanged.
Number
Number
s can be shot by the BattleShip
to finish the Level
.
Number can collide with the BattleShip
, hence triggering colorfull
Animation
explosions.
Number
s never change speed, except when they rebound on Wall
s, of course.
Number | |
|
UI
UI elements around the World
are:
- a
RectContainer
created bymkWorldContainer
to visually delimit theWorld
ColorString
information, placed around theRectContainer
:
mkWorldContainer :: World -> RectContainer Source #
Helper function to create a RectContainer
containing a World
.
Inter-level animations
module Imj.Graphics.UI.Animation
Secondary types
data WallDistribution Source #
How should walls be created?
None | No |
Deterministic | A Rectangular |
Random !RandomParameters |
|
data WorldShape Source #
Square | Width = Height |
Rectangle2x1 | Width = 2 * Height |
data LevelFinished Source #
LevelFinished | |
|
Reexports
module Imj.Graphics.Render
data ColorString :: * #
Show ColorString | |
IsString ColorString | |
Monoid ColorString | |
DiscreteInterpolation ColorString | First interpolating characters, then color. |
DiscreteDistance ColorString | First interpolating characters, then color. |