Copyright | © 2017-2019 Francesco Ariis |
---|---|
License | GPLv3 (see LICENSE file) |
Maintainer | Francesco Ariis <fa-ml@ariis.it> |
Stability | provisional |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
Machinery and utilities for 2D terminal games.
Before continuing, please read this: to use ansi-terminal-game
,
you need to compile your programs with -threaded
; if you do not do
this the program will crash at start-up. Just add:
ghc-options: -threaded
in your .cabal
file and you will be fine!
Synopsis
- type MonadGameIO m = (MonadInput m, MonadTimer m, MonadDisplay m)
- type FPS = Integer
- runGame :: forall s m. MonadGameIO m => s -> (s -> Event -> s) -> (s -> Plane) -> (s -> Bool) -> FPS -> m s
- data Event
- data Plane
- type Coords = (Row, Column)
- type Row = Integer
- type Column = Integer
- type Width = Integer
- type Height = Integer
- stringPlane :: String -> Plane
- stringPlaneTrans :: Char -> String -> Plane
- blankPlane :: Width -> Height -> Plane
- addVitrum :: Char -> Plane -> Plane
- pastePlane :: Plane -> Plane -> Coords -> Plane
- planeSize :: Plane -> (Width, Height)
- paperPlane :: Plane -> String
- type Draw = Plane -> Plane
- (%) :: Coords -> Plane -> Draw
- (#) :: Plane -> Draw -> Plane
- (&) :: a -> (a -> b) -> b
- mergePlanes :: Plane -> [(Coords, Plane)] -> Plane
- cell :: Char -> Plane
- box :: Char -> Width -> Height -> Plane
- textBox :: String -> Width -> Height -> Plane
- bold :: Plane -> Plane
- invert :: Plane -> Plane
- type Animation = Timed Plane
- data Loop
- creaAni :: Loop -> [(Integer, Plane)] -> Animation
- tick :: Timed a -> Timed a
- reset :: Timed a -> Timed a
- getFrames :: Timed a -> [(Integer, a)]
- data Timed a
- data ExpBehaviour
- creaTimer :: a -> a -> Integer -> Timed a
- creaBoolTimer :: Integer -> Timed Bool
- fetchFrame :: Timed a -> a
- isExpired :: Timed a -> Bool
Game Loop
type MonadGameIO m = (MonadInput m, MonadTimer m, MonadDisplay m) Source #
:: MonadGameIO m | |
=> s | Initial state of the game. |
-> (s -> Event -> s) | Logic function. |
-> (s -> Plane) | Draw function. |
-> (s -> Bool) | "Should I quit?" function. |
-> FPS | Frames per second. |
-> m s |
Entry point for the game, should be called in main
. The two
most important functions are the one dealing with logic and the
blitting one. Check alone-in-a-room
(you can compiler it with
cabal new-build -f examples
) to see a simple game in action.
Plane
A two-dimensional surface (Row, Column) where to blit stuff.
stringPlane :: String -> Plane Source #
stringPlaneTrans :: Char -> String -> Plane Source #
Same as stringPlane
, but with transparent Char
.
paperPlane :: Plane -> String Source #
Draw
Animations
Number of times to repeat the animation.
AlwaysLoop | Loops forever, never expires. |
Times Integer ExpBehaviour | Repeats the cycle for a fixed number of times. |
Instances
Eq Loop | |
Show Loop | |
Generic Loop | |
type Rep Loop | |
Defined in Control.Timer.Tick type Rep Loop = D1 (MetaData "Loop" "Control.Timer.Tick" "timers-tick-0.4.0.0-4YT45JnkKST1JU1nhPkPXb" False) (C1 (MetaCons "AlwaysLoop" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "Times" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Integer) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 ExpBehaviour))) |
Timers
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
data ExpBehaviour #
Expire behaviour.
Instances
Eq ExpBehaviour | |
Defined in Control.Timer.Tick (==) :: ExpBehaviour -> ExpBehaviour -> Bool # (/=) :: ExpBehaviour -> ExpBehaviour -> Bool # | |
Show ExpBehaviour | |
Defined in Control.Timer.Tick showsPrec :: Int -> ExpBehaviour -> ShowS # show :: ExpBehaviour -> String # showList :: [ExpBehaviour] -> ShowS # | |
Generic ExpBehaviour | |
Defined in Control.Timer.Tick type Rep ExpBehaviour :: Type -> Type # from :: ExpBehaviour -> Rep ExpBehaviour x # to :: Rep ExpBehaviour x -> ExpBehaviour # | |
type Rep ExpBehaviour | |
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"!
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
).