| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Imj.Game.Hamazed.World
Contents
- 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 rectangularWorldwhere the width is twice the heightWallDistribution: Should theWorldhave 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 #
Constructors
| GameParameters | |
Level
There are 12 levels in Hamazed, numbered from 1 to 12.
Constructors
| Level | |
Fields
| |
Level termination
Arguments
| :: 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,BattleShipandNumbers, - rendering elements:
Animations, - terminal-awareness :
InTerminal
Constructors
| World | |
Fields
| |
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:
Arguments
| :: Int |
|
| -> WorldShape | |
| -> Size |
Arguments
| :: 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 (Numbers, BattleShip).
Note that Animations 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.
Arguments
| :: 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.
Arguments
| :: 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 #
Constructors
| InTerminal | |
Fields
| |
Instances
Space
Space describes the environment in which Numbers and the BattleShip
live.
It can be composed of Air, where BattleShip and Numbers 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 Walls at random and discards resulting
Spaces 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 Numbers.
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.
Constructors
| RandomParameters | |
Fields
| |
Constructors
| 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 #
Constructors
| WorldFrame | Just the world. |
| TerminalWindow | The terminal, not the world. |
| Both | The terminal. |
Instances
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 #
Constructors
| BattleShip | |
Fields
| |
Instances
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
Numbers can be shot by the BattleShip to finish the Level.
Number can collide with the BattleShip, hence triggering colorfull
Animation explosions.
Numbers never change speed, except when they rebound on Walls, of course.
Constructors
| Number | |
Fields
| |
UI
UI elements around the World are:
- a
RectContainercreated bymkWorldContainerto visually delimit theWorld ColorStringinformation, 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?
Constructors
| None | No |
| Deterministic | A Rectangular |
| Random !RandomParameters |
|
data WorldShape Source #
Constructors
| Square | Width = Height |
| Rectangle2x1 | Width = 2 * Height |
data LevelFinished Source #
Constructors
| LevelFinished | |
Fields
| |
Reexports
module Imj.Graphics.Render
data ColorString :: * #
Instances
| Show ColorString | |
| IsString ColorString | |
| Monoid ColorString | |
| DiscreteInterpolation ColorString | First interpolating characters, then color. |
| DiscreteDistance ColorString | First interpolating characters, then color. |