Safe Haskell | None |
---|---|
Language | Haskell2010 |
- run :: IO ()
- getNextDeadline :: GameState -> SystemTime -> Maybe Deadline
- getEventForMaybeDeadline :: Level -> Maybe Deadline -> SystemTime -> IO (Maybe Event)
- update :: GameParameters -> GameState -> Event -> IO GameState
- render :: (Render e, MonadReader e m, MonadIO m) => GameState -> m ()
- data Deadline = Deadline {}
- data DeadlineType
- data Event
- data ActionTarget
- data MetaAction
- data GameState = GameState {}
- data Env
- createEnv :: IO Env
- eventFromKey :: Key -> Maybe Event
- module Imj.Game.Hamazed.World
- data UIAnimation :: * = UIAnimation {
- _uiAnimationEvs :: !UIEvolutions
- _uiAnimationDeadline :: !(Maybe KeyTime)
- _uiAnimationProgress :: !Iteration
The game
In Hamazed, you are a BattleShip
pilot surrounded by flying Number
s.
Your mission is to shoot exactly the Number
s whose sum will equate the
current Level
's target number.
The higher the Level
(1..12), the more Number
s 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
.
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:
- \(deadline\) = the next foreseen
Deadline
.
- \(deadline\) = the next foreseen
\(event\) =
- a key-press occuring before \(deadline\) expires
- or the \(deadline\) event
- Update
GameState
according to \(event\)
- Update
- Render (using Imj.Graphics.Render.Delta to avoid screen tearing).
:: 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 Number
s) than having time-accurate explosive Animation
s.
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.
:: GameParameters |
|
-> GameState | The current state |
-> Event | The |
-> 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
A foreseen game or animation update.
data DeadlineType Source #
MoveFlyingItems | Move |
Animate | Update one or more |
DisplayContinueMessage | Show the Hit a key to continue message |
AnimateUI | Update the inter-level animation |
Events
Action !ActionTarget !Direction | A player action on an |
Timeout !Deadline | The |
StartLevel !Int | New level. |
EndGame | End of game. |
Interrupt !MetaAction | A game interruption. |
data ActionTarget Source #
Ship | The player wants to accelerate the |
Laser | The player wants to shoot with the laser. |
data MetaAction Source #
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).
GameState | |
|
Environment
The environment of Hamazed program
Keyboard layout
Reexport
module Imj.Game.Hamazed.World
data UIAnimation :: * #
Manages the progress and deadline of UIEvolutions
.
UIAnimation | |
|