ansi-terminal-game-0.1.0.0: sdl-like functions for terminal applications, based on ansi-terminal

Safe HaskellNone
LanguageHaskell2010

Terminal.Game

Contents

Synopsis

Game loop

gameLoop Source #

Arguments

:: String

title

-> s

initial state todo [release] [study] no full IO for s, but a jailed IO (provided by a datatype), both for I and for O

-> (s -> Maybe Char -> IO s)

logic function

-> (s -> Plane)

draw function

-> (s -> Bool)

quit? function

-> Integer

framerate (in fps)

-> IO () 

Entry point for the game.

Plane

data Plane Source #

Instances

Eq Plane Source # 

Methods

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

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

Show Plane Source # 

Methods

showsPrec :: Int -> Plane -> ShowS #

show :: Plane -> String #

showList :: [Plane] -> ShowS #

Generic Plane Source # 

Associated Types

type Rep Plane :: * -> * #

Methods

from :: Plane -> Rep Plane x #

to :: Rep Plane x -> Plane #

type Rep Plane Source # 
type Rep Plane = D1 * (MetaData "Plane" "Terminal.Game.Plane" "ansi-terminal-game-0.1.0.0-DiuNSeDJ0cDGlv2SELrpJo" True) (C1 * (MetaCons "Plane" PrefixI True) (S1 * (MetaSel (Just Symbol "fromPlane") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 * (Array Coords Cell))))

type Coords = (Row, Column) Source #

Draw

(%) :: Coords -> Plane -> Draw Source #

(&) :: a -> (a -> b) -> b infixl 1 #

& is a reverse application operator. This provides notational convenience. Its precedence is one higher than that of the forward application operator $, which allows & to be nested in $.

Since: 4.8.0.0

Animations

data Loop :: * #

Number of times to repeat the animation.

Constructors

AlwaysLoop

Loops forever, never expires.

Times Integer ExpBehaviour

Repeats the cycle for a fixed number of times.

Instances

Eq Loop 

Methods

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

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

Show Loop 

Methods

showsPrec :: Int -> Loop -> ShowS #

show :: Loop -> String #

showList :: [Loop] -> ShowS #

Generic Loop 

Associated Types

type Rep Loop :: * -> * #

Methods

from :: Loop -> Rep Loop x #

to :: Rep Loop x -> Loop #

type Rep Loop 
type Rep Loop = D1 * (MetaData "Loop" "Control.Timer.Tick" "timers-tick-0.4.0.0-HWOzz1XwfZYGa3EzWkuPYo" False) ((:+:) * (C1 * (MetaCons "AlwaysLoop" PrefixI False) (U1 *)) (C1 * (MetaCons "Times" PrefixI False) ((:*:) * (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 * Integer)) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 * ExpBehaviour)))))

tick :: Timed a -> Timed a #

Ticks the timer (one step).

reset :: Timed a -> Timed a #

Resets the timer to its original state.

getFrames :: Timed a -> [(Integer, a)] #

Return a list of all frames plus their duration.

Timers

data Timed a :: * -> * #

A timed resource is a timer which, at any given moment, points to a specific item (like an animation).

Example:

timer = creaTimedRes (Times 1 Elapse) [(2, "a "), (1, "b "), (2, "c ")]
test t | isExpired t = putStrLn "Fine."
       | otherwise   = do putStr (fetchFrame t)
                          test (tick t)

   -- λ> test timer
   -- a a b c c Fine.

Instances

Functor Timed

Mapping on frames.

Methods

fmap :: (a -> b) -> Timed a -> Timed b #

(<$) :: a -> Timed b -> Timed a #

Eq a => Eq (Timed a) 

Methods

(==) :: Timed a -> Timed a -> Bool #

(/=) :: Timed a -> Timed a -> Bool #

Show a => Show (Timed a) 

Methods

showsPrec :: Int -> Timed a -> ShowS #

show :: Timed a -> String #

showList :: [Timed a] -> ShowS #

Generic (Timed a) 

Associated Types

type Rep (Timed a) :: * -> * #

Methods

from :: Timed a -> Rep (Timed a) x #

to :: Rep (Timed a) x -> Timed a #

type Rep (Timed a) 

data ExpBehaviour :: * #

Expire behaviour.

Constructors

Reach

Expires upon reaching last frame.

Elapse

Expires when last frame is over.

Instances

Eq ExpBehaviour 
Show ExpBehaviour 
Generic ExpBehaviour 

Associated Types

type Rep ExpBehaviour :: * -> * #

type Rep ExpBehaviour 
type Rep ExpBehaviour = D1 * (MetaData "ExpBehaviour" "Control.Timer.Tick" "timers-tick-0.4.0.0-HWOzz1XwfZYGa3EzWkuPYo" False) ((:+:) * (C1 * (MetaCons "Reach" PrefixI False) (U1 *)) (C1 * (MetaCons "Elapse" PrefixI False) (U1 *)))

creaTimer :: a -> a -> Integer -> Timed a #

A simple off/on timer expiring in fixed number of ticks.

Example:

timer = creaTimer Nothing (Just "Over!") 4
test t | isExpired t = print (fetchFrame t)
       | otherwise   = do print (fetchFrame t)
                          test (tick t)

   -- λ> test timer
   -- Nothing
   -- Nothing
   -- Nothing
   -- Nothing
   -- Just "Over"!

creaBoolTimer :: Integer -> Timed Bool #

Shorthand for: creaTimer False True i.

fetchFrame :: Timed a -> a #

Fetches the current resource of the timer.

isExpired :: Timed a -> Bool #

Checks wheter the timer is expired (an expired timer will not respond to tick).

Utils