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

Safe HaskellNone
LanguageHaskell2010

Imj.Game.Hamazed

Contents

Synopsis

The game

In Hamazed, you are a BattleShip pilot surrounded by flying Numbers.

Your mission is to shoot exactly the Numbers whose sum will equate the current Level 's target number.

The higher the Level (1..12), the more Numbers are flying around (up-to 16). And the smaller the World gets.

Good luck !

Note that to adapt the keyboard layout, you can modify eventFromKey.

run :: IO () Source #

Runs the Hamazed game.

If your current terminal window is too small, the program will error and tell you what is the minimum window size to run the game.

The game doesn't run on Windows, because with GHC, IO operations cannot be interrupted on Windows.

Game loop

Hamazed is a synchronous, event-driven program. Its simplified main loop is:

getNextDeadline Source #

Arguments

:: GameState

Current state

-> SystemTime

The current time.

-> Maybe Deadline 

Returns the next Deadline to handle.

We prefer having time-accurate game motions for central items of the game (the BattleShip, the Numbers) than having time-accurate explosive Animations.

Hence, when multiple overdue deadlines are competing, the following priorities apply (higher number = higher priority):

\[ \newcommand\T{\Rule{0pt}{.5em}{.3em}} \begin{array}{|c|c|c|} \hline \textbf{ Priority } \T & \textbf{ Name } \T & \textbf{ Description } \\\hline \text{ 5 } & \text{ AnimateUI } \T & \text{ Inter-level animations } \\\hline \text{ 4 } & \text{ DisplayContinueMessage } \T & \textit{ Press a key to continue } \\\hline \text{ 3 } & \text{ MoveFlyingItems } \T & \text{ Move the BattleShip and Numbers } \\\hline \text{ 2 } & \textit{ Player event } \T & \text{ Handle a key-press } \\\hline \text{ 1 } & \text{ Animate } \T & \text{ Update animations (explosions and others)} \\\hline \end{array} \]

When no Deadline is overdue, we return the closest one in time, irrespective of its priority.

getEventForMaybeDeadline Source #

Arguments

:: Level

Current level

-> Maybe Deadline

May contain a Deadline

-> SystemTime

Current time

-> IO (Maybe Event) 

Returns a player event or the Event associated to the Deadline if the Deadline expired before the player could press a Key.

update Source #

Arguments

:: GameParameters

World creation parameters, used in case the Event is StartLevel.

-> GameState

The current state

-> Event

The Event that should be handled here.

-> IO GameState 

Updates the state. It needs IO just to generate random numbers in case Event is StartLevel

render :: (Render e, MonadReader e m, MonadIO m) => GameState -> m () Source #

Renders the game to the screen, using Imj.Graphics.Render.Delta to avoid screen tearing.

Deadlines

data Deadline Source #

A foreseen game or animation update.

data DeadlineType Source #

Constructors

MoveFlyingItems

Move Numbers and BattleShip according to their current speeds.

Animate

Update one or more Animations.

DisplayContinueMessage

Show the Hit a key to continue message

AnimateUI

Update the inter-level animation

Events

data Event Source #

Constructors

Action !ActionTarget !Direction

A player action on an ActionTarget in a Direction.

Timeout !Deadline

The Deadline that needs to be handled immediately.

StartLevel !Int

New level.

EndGame

End of game.

Interrupt !MetaAction

A game interruption.

Instances

Eq Event Source # 

Methods

(==) :: Event -> Event -> Bool #

(/=) :: Event -> Event -> Bool #

Show Event Source # 

Methods

showsPrec :: Int -> Event -> ShowS #

show :: Event -> String #

showList :: [Event] -> ShowS #

data ActionTarget Source #

Constructors

Ship

The player wants to accelerate the BattleShip

Laser

The player wants to shoot with the laser.

data MetaAction Source #

Constructors

Quit

The player decided to quit the game.

Configure

The player wants to configure the game (Not implemented yet)

Help

The player wants to read the help page (Not implemented yet)

GameState

GameState has two fields of type World : during Level transitions, we render the old World while using the new World 's dimensions to animate the UI accordingly (see Imj.Graphics.UI.Animation).

data GameState Source #

Constructors

GameState 

Fields

Environment

 

data Env Source #

The environment of Hamazed program

Instances

Render Env Source #

Forwards to the Render instance of DeltaEnv.

Methods

renderToScreen' :: MonadIO m => Env -> m () #

Draw Env Source #

Forwards to the Draw instance of DeltaEnv.

createEnv :: IO Env Source #

Constructor of Env

Keyboard layout

eventFromKey :: Key -> Maybe Event Source #

Maps a Key (pressed by the player) to an Event.

Reexport

data UIAnimation :: * #

Manages the progress and deadline of UIEvolutions.

Constructors

UIAnimation 

Fields