imj-game-hamazed-0.1.0.2: A game with flying numbers and 8-bit color animations.

Safe HaskellNone
LanguageHaskell2010

Imj.Game.Hamazed.World

Contents

Synopsis

Parameters

When the game starts, the player can chose World parameters:

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.

Level

There are 12 levels in Hamazed, numbered from 1 to 12.

data Level Source #

Constructors

Level 

Fields

Level termination

Target number
Each level has a different target number which represents the sum of shot Numbers that should be reached to finish the Level.

A Level is finished once the sum of shot Numbers amounts to the target number.

checkTargetAndAmmo Source #

Arguments

:: Int

Remaining ammo

-> Int

The current sum of all shot Numbers

-> Int

The Level 's target number.

-> SystemTime

The current time

-> Maybe LevelFinished 

World

A World brings together:

data World Source #

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:

Once we have the Size of the World, we can create it using mkWorld:

mkWorld Source #

Arguments

:: MonadIO m 
=> InTerminal

Tells where to draw the World from

-> Size

The dimensions

-> WallDistribution

How the Walls should be constructed

-> [Int]

The numbers for which we will create Numbers.

-> 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:

moveWorld Source #

Arguments

:: KeyTime

The current time

-> World 
-> World 

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.

laserEventAction Source #

Arguments

:: Direction

The direction of the laser shot

-> World 
-> ([Number], [Number], Maybe (LaserRay Actual), Int)

Numbers still alive, Numbers destroyed, maybe an actual laser ray, Ammo left.

Computes the effect of an laser shot on the World.

InTerminal

InTerminal allows to place the game in the center of the terminal.

mkInTerminal Source #

Arguments

:: MonadIO m 
=> Size

Measures the dimensions of the inner content of the World, excluding the outer frame.

-> 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

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.

data Material Source #

Constructors

Air

In it, ship and numbers can move.

Wall

Ship and numbers rebound on Walls.

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

  • _randomWallsBlockSize :: !Int

    The size of a square wall block.

    Note that the smaller the block size, the harder it will be for the algorithm to find a random world with a single component of air.

  • _randomWallsStrategy :: !Strategy

    Space characteristics (only one connected component is available for the moment)

data Strategy Source #

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 Walls.

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

scopedLocation Source #

Arguments

:: Space 
-> Maybe (Window Int)

The terminal size

-> Coords Pos

The world upper left coordinates w.r.t terminal frame.

-> Boundaries

The scope

-> Coords Pos

The coordinates to test

-> Location 

data Boundaries Source #

Constructors

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

renderSpace Source #

Arguments

:: (Draw e, MonadReader e m, MonadIO m) 
=> Space 
-> Coords Pos

World upper left coordinates w.r.t terminal frame.

-> m (Coords Pos) 

Movable items

A movable item's PosSpeed is updated using updateMovableItem at each MoveFlyingItems event:

updateMovableItem Source #

Arguments

:: Space

The surrounding Space will be taken into account for collisions.

-> PosSpeed

The current position and speed of the moving item.

-> PosSpeed

The updated position and speed.

Updates PosSpeed of a movable item, according to Space.

BattleShip

data BattleShip Source #

Constructors

BattleShip 

Fields

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.

data Number Source #

Constructors

Number 

Fields

Instances

UI

UI elements around the World are:

mkWorldContainer :: World -> RectContainer Source #

Helper function to create a RectContainer containing a World.

Inter-level animations

Secondary types

data WallDistribution Source #

How should walls be created?

Constructors

None

No Walls.

Deterministic

A Rectangular Wall in the middle of the level.

Random !RandomParameters

Walls are created with an algorithm involving random numbers.

data WorldShape Source #

Constructors

Square

Width = Height

Rectangle2x1

Width = 2 * Height

data GameStops Source #

Constructors

Lost Text

Text is the reason why the Level was lost.

Won 

Reexports