| Portability | non-portable |
|---|---|
| Stability | provisional |
| Maintainer | Fumiaki Kinoshita <fumiexcel@gmail.com> |
| Safe Haskell | None |
FreeGame
Contents
Description
- type Game = IterT Frame
- runGame :: WindowMode -> BoundingBox Double -> Game a -> IO (Maybe a)
- data WindowMode
- = Windowed
- | FullScreen
- data BoundingBox a = BoundingBox a a a a
- delay :: (Monad f, MonadFree f m) => m a -> m a
- tick :: (Monad f, MonadFree f m) => m ()
- foreverFrame :: (Monad f, Monad m, MonadTrans t, MonadFree f (t m)) => m a -> t m any
- untick :: (Functor f, MonadFree f m) => IterT (F f) a -> m (Either (IterT (F f) a) a)
- untickInfinite :: (Functor f, MonadFree f m) => IterT (F f) Void -> m (IterT (F f) Void)
- type Frame = F UI
- class (Picture2D m, Local m, Keyboard m, Mouse m, FromFinalizer m) => FreeGame m where
- draw :: forall f. (Applicative f, Monad f, Picture2D f, Local f) => f a => m a
- preloadBitmap :: Bitmap -> m ()
- bracket :: Frame a -> m a
- takeScreenshot :: m Bitmap
- setFPS :: Int -> m ()
- setTitle :: String -> m ()
- showCursor :: m ()
- hideCursor :: m ()
- clearColor :: Color -> m ()
- getFPS :: m Int
- type Vec2 = V2 Double
- class Functor p => Affine p where
- class Affine p => Local p
- globalize :: Local f => Vec2 -> f Vec2
- localize :: Local f => Vec2 -> f Vec2
- class Affine p => Picture2D p where
- data BlendMode
- data Bitmap
- readBitmap :: MonadIO m => FilePath -> m Bitmap
- cropBitmap :: Bitmap -> (Int, Int) -> (Int, Int) -> Bitmap
- loadBitmaps :: FilePath -> Q [Dec]
- loadBitmapsWith :: ExpQ -> FilePath -> Q [Dec]
- writeBitmap :: MonadIO m => FilePath -> Bitmap -> m ()
- data Font
- loadFont :: MonadIO m => FilePath -> m Font
- text :: (FromFinalizer m, Monad m, Picture2D m) => Font -> Double -> String -> m ()
- class Functor f => Keyboard f where
- keyStates_ :: f (Map Key ButtonState)
- data Key
- = KeyUnknown
- | KeySpace
- | KeyApostrophe
- | KeyComma
- | KeyMinus
- | KeyPeriod
- | KeySlash
- | Key0
- | Key1
- | Key2
- | Key3
- | Key4
- | Key5
- | Key6
- | Key7
- | Key8
- | Key9
- | KeySemicolon
- | KeyEqual
- | KeyA
- | KeyB
- | KeyC
- | KeyD
- | KeyE
- | KeyF
- | KeyG
- | KeyH
- | KeyI
- | KeyJ
- | KeyK
- | KeyL
- | KeyM
- | KeyN
- | KeyO
- | KeyP
- | KeyQ
- | KeyR
- | KeyS
- | KeyT
- | KeyU
- | KeyV
- | KeyW
- | KeyX
- | KeyY
- | KeyZ
- | KeyLeftBracket
- | KeyBackslash
- | KeyRightBracket
- | KeyGraveAccent
- | KeyWorld1
- | KeyWorld2
- | KeyEscape
- | KeyEnter
- | KeyTab
- | KeyBackspace
- | KeyInsert
- | KeyDelete
- | KeyRight
- | KeyLeft
- | KeyDown
- | KeyUp
- | KeyPageUp
- | KeyPageDown
- | KeyHome
- | KeyEnd
- | KeyCapsLock
- | KeyScrollLock
- | KeyNumLock
- | KeyPrintScreen
- | KeyPause
- | KeyF1
- | KeyF2
- | KeyF3
- | KeyF4
- | KeyF5
- | KeyF6
- | KeyF7
- | KeyF8
- | KeyF9
- | KeyF10
- | KeyF11
- | KeyF12
- | KeyF13
- | KeyF14
- | KeyF15
- | KeyF16
- | KeyF17
- | KeyF18
- | KeyF19
- | KeyF20
- | KeyF21
- | KeyF22
- | KeyF23
- | KeyF24
- | KeyF25
- | KeyPad0
- | KeyPad1
- | KeyPad2
- | KeyPad3
- | KeyPad4
- | KeyPad5
- | KeyPad6
- | KeyPad7
- | KeyPad8
- | KeyPad9
- | KeyPadDecimal
- | KeyPadDivide
- | KeyPadMultiply
- | KeyPadSubtract
- | KeyPadAdd
- | KeyPadEnter
- | KeyPadEqual
- | KeyLeftShift
- | KeyLeftControl
- | KeyLeftAlt
- | KeyLeftSuper
- | KeyRightShift
- | KeyRightControl
- | KeyRightAlt
- | KeyRightSuper
- | KeyMenu
- charToKey :: Char -> Key
- keyPress :: Keyboard f => Key -> f Bool
- keyUp :: Keyboard f => Key -> f Bool
- keyDown :: Keyboard f => Key -> f Bool
- class Functor f => Mouse f
- mousePosition :: (Applicative f, Mouse f, Local f) => f Vec2
- mouseButtonL :: Mouse f => f Bool
- mouseButtonR :: Mouse f => f Bool
- mouseButtonM :: Mouse f => f Bool
- mouseDownL :: Mouse f => f Bool
- mouseDownR :: Mouse f => f Bool
- mouseDownM :: Mouse f => f Bool
- mouseUpL :: Mouse f => f Bool
- mouseUpR :: Mouse f => f Bool
- mouseUpM :: Mouse f => f Bool
- class FromFinalizer m
- embedIO :: FromFinalizer m => IO a -> m a
- liftIO :: MonadIO m => forall a. IO a -> m a
- randomness :: (Random r, FromFinalizer m) => (r, r) -> m r
- unitV2 :: Floating a => a -> V2 a
- angleV2 :: RealFloat a => V2 a -> a
- degrees :: Floating a => a -> a
- radians :: Floating a => a -> a
- module Control.Monad
- module Control.Applicative
- module Control.Bool
- module Data.Color
- module Data.Color.Names
- module Linear
- fromBitmap :: Picture2D p => Bitmap -> p ()
- loadBitmapFromFile :: MonadIO m => FilePath -> m Bitmap
- colored :: Picture2D p => Color -> p a -> p a
- keyChar :: Keyboard f => Char -> f Bool
- keySpecial :: Keyboard f => Key -> f Bool
Game
runGame :: WindowMode -> BoundingBox Double -> Game a -> IO (Maybe a)Source
Game is a monad literally expressing games.
This monad is an instance of Picture2D so you can construct it using bitmap and can be transformed with translate, scale, rotate, color.
It is also an instance of Keyboard and Mouse. Note that mousePosition returns a relative position.
foo = foreverFrame $ do p <- mousePosition translate p $ color blue $ polygonOutline [V2 (-8) (-8), V2 8 (-8), V2 8 8, V2 (-8) 8]
When we run foo using runGame, a blue square follows the cursor.
And translate (V2 240 240) foo, rotate 45 foo, scale 1.5 foo also does in the same way.
The only way to embody a Game as a real stuff is to apply runGame.
For more examples, see https://github.com/fumieval/free-game/tree/master/examples.
data WindowMode Source
Constructors
| Windowed | |
| FullScreen |
data BoundingBox a Source
2D bounding box
Constructors
| BoundingBox a a a a |
Instances
| Functor BoundingBox | |
| Typeable1 BoundingBox | |
| Foldable BoundingBox | |
| Traversable BoundingBox | |
| Eq a => Eq (BoundingBox a) | |
| Ord a => Ord (BoundingBox a) | |
| Read a => Read (BoundingBox a) | |
| Show a => Show (BoundingBox a) |
foreverFrame :: (Monad f, Monad m, MonadTrans t, MonadFree f (t m)) => m a -> t m anySource
foreverFrame :: Frame a -> Game any
untick :: (Functor f, MonadFree f m) => IterT (F f) a -> m (Either (IterT (F f) a) a)Source
Extract the next frame of the action.
untickInfinite :: (Functor f, MonadFree f m) => IterT (F f) Void -> m (IterT (F f) Void)Source
An infinite version of untick.
Frame
class (Picture2D m, Local m, Keyboard m, Mouse m, FromFinalizer m) => FreeGame m whereSource
Methods
draw :: forall f. (Applicative f, Monad f, Picture2D f, Local f) => f a => m aSource
Draw an action that consist of Picture2D's methods.
preloadBitmap :: Bitmap -> m ()Source
bracket :: Frame a -> m aSource
Run a Frame, and release all the matter happened.
takeScreenshot :: m BitmapSource
Generate a Bitmap from the front buffer.
setTitle :: String -> m ()Source
showCursor :: m ()Source
hideCursor :: m ()Source
clearColor :: Color -> m ()Source
Instances
| FreeGame UI | |
| (FreeGame m, Monad m) => FreeGame (IdentityT m) | |
| (FreeGame m, Functor m) => FreeGame (F m) | |
| (FreeGame m, Functor m) => FreeGame (Free m) | |
| (FreeGame m, Monad m) => FreeGame (IterT m) | |
| (FreeGame m, Monad m) => FreeGame (ListT m) | |
| (FreeGame m, Monad m) => FreeGame (MaybeT m) | |
| (FreeGame m, Monad m, Error e) => FreeGame (ErrorT e m) | |
| (FreeGame m, Monad m) => FreeGame (ContT r m) | |
| (FreeGame m, Monad m) => FreeGame (StateT s m) | |
| (FreeGame m, Monad m) => FreeGame (StateT s m) | |
| (FreeGame m, Monad m, Monoid w) => FreeGame (WriterT w m) | |
| (FreeGame m, Monad m, Monoid w) => FreeGame (WriterT w m) | |
| (FreeGame m, Monad m, Monoid w) => FreeGame (RWST r w s m) | |
| (FreeGame m, Monad m, Monoid w) => FreeGame (RWST r w s m) |
Transformations
class Functor p => Affine p whereSource
Methods
rotateR :: Double -> p a -> p aSource
(radians)
rotateD :: Double -> p a -> p aSource
(degrees)
Instances
| Affine Location | |
| Affine UI | |
| (Affine m, Monad m) => Affine (IdentityT m) | |
| (Affine m, Functor m) => Affine (F m) | |
| (Affine m, Functor m) => Affine (Free m) | |
| (Affine m, Monad m) => Affine (IterT m) | |
| (Affine m, Monad m) => Affine (ListT m) | |
| (Affine m, Monad m) => Affine (MaybeT m) | |
| (Affine m, Monad m, Error e) => Affine (ErrorT e m) | |
| (Affine m, Monad m) => Affine (ContT r m) | |
| (Affine m, Monad m) => Affine (ReaderT r m) | |
| (Affine m, Monad m) => Affine (StateT s m) | |
| (Affine m, Monad m) => Affine (StateT s m) | |
| (Affine m, Monad m, Monoid w) => Affine (WriterT w m) | |
| (Affine m, Monad m, Monoid w) => Affine (WriterT w m) | |
| (Affine m, Monad m, Monoid w) => Affine (RWST r w s m) | |
| (Affine m, Monad m, Monoid w) => Affine (RWST r w s m) |
class Affine p => Local p Source
Instances
| Local UI | |
| (Local m, Monad m) => Local (IdentityT m) | |
| (Local m, Functor m) => Local (F m) | |
| (Local m, Functor m) => Local (Free m) | |
| (Local m, Monad m) => Local (IterT m) | |
| (Local m, Monad m) => Local (ListT m) | |
| (Local m, Monad m) => Local (MaybeT m) | |
| (Local m, Monad m, Error e) => Local (ErrorT e m) | |
| (Local m, Monad m) => Local (ContT r m) | |
| (Local m, Monad m) => Local (ReaderT s m) | |
| (Local m, Monad m) => Local (StateT s m) | |
| (Local m, Monad m) => Local (StateT s m) | |
| (Local m, Monad m, Monoid w) => Local (WriterT w m) | |
| (Local m, Monad m, Monoid w) => Local (WriterT w m) | |
| (Local m, Monad m, Monoid w) => Local (RWST r w s m) | |
| (Local m, Monad m, Monoid w) => Local (RWST r w s m) |
Pictures
class Affine p => Picture2D p whereSource
The class of types that can be regarded as a kind of picture.
Methods
bitmap :: Bitmap -> p ()Source
polygon :: [Vec2] -> p ()Source
polygonOutline :: [Vec2] -> p ()Source
circle :: Double -> p ()Source
circleOutline :: Double -> p ()Source
thickness :: Float -> p a -> p aSource
Instances
| Picture2D UI | |
| (Picture2D m, Monad m) => Picture2D (IdentityT m) | |
| (Picture2D m, Functor m) => Picture2D (F m) | |
| (Picture2D m, Functor m) => Picture2D (Free m) | |
| (Picture2D m, Monad m) => Picture2D (IterT m) | |
| (Picture2D m, Monad m) => Picture2D (ListT m) | |
| (Picture2D m, Monad m) => Picture2D (MaybeT m) | |
| (Picture2D m, Monad m, Error e) => Picture2D (ErrorT e m) | |
| (Picture2D m, Monad m) => Picture2D (ContT r m) | |
| (Picture2D m, Monad m) => Picture2D (ReaderT r m) | |
| (Picture2D m, Monad m) => Picture2D (StateT s m) | |
| (Picture2D m, Monad m) => Picture2D (StateT s m) | |
| (Picture2D m, Monad m, Monoid w) => Picture2D (WriterT w m) | |
| (Picture2D m, Monad m, Monoid w) => Picture2D (WriterT w m) | |
| (Picture2D m, Monad m, Monoid w) => Picture2D (RWST r w s m) | |
| (Picture2D m, Monad m, Monoid w) => Picture2D (RWST r w s m) |
readBitmap :: MonadIO m => FilePath -> m BitmapSource
Load an image file.
Arguments
| :: Bitmap | original bitmap |
| -> (Int, Int) | width and height |
| -> (Int, Int) | x and y |
| -> Bitmap | result |
Extract a Bitmap from the specified range.
loadBitmaps :: FilePath -> Q [Dec]Source
Load and define all pictures in the specified directory. In GHC >= 7.6, file paths to actually load will be respect to the directory of the executable. Otherwise it will be based on the current directory.
loadBitmapsWith :: ExpQ -> FilePath -> Q [Dec]Source
The type of the given ExpQ must be FilePath -> IO FilePath
Text
text :: (FromFinalizer m, Monad m, Picture2D m) => Font -> Double -> String -> m ()Source
Render a String.
Keyboard
class Functor f => Keyboard f whereSource
Methods
keyStates_ :: f (Map Key ButtonState)Source
Instances
| Keyboard UI | |
| (Keyboard m, Monad m) => Keyboard (IdentityT m) | |
| (Keyboard m, Functor m) => Keyboard (F m) | |
| (Keyboard m, Functor m) => Keyboard (Free m) | |
| (Keyboard m, Monad m) => Keyboard (IterT m) | |
| (Keyboard m, Monad m) => Keyboard (ListT m) | |
| (Keyboard m, Monad m) => Keyboard (MaybeT m) | |
| (Keyboard m, Monad m, Error e) => Keyboard (ErrorT e m) | |
| (Keyboard m, Monad m) => Keyboard (ContT r m) | |
| (Keyboard m, Monad m) => Keyboard (ReaderT s m) | |
| (Keyboard m, Monad m) => Keyboard (StateT s m) | |
| (Keyboard m, Monad m) => Keyboard (StateT s m) | |
| (Keyboard m, Monad m, Monoid w) => Keyboard (WriterT w m) | |
| (Keyboard m, Monad m, Monoid w) => Keyboard (WriterT w m) | |
| (Keyboard m, Monad m, Monoid w) => Keyboard (RWST r w s m) | |
| (Keyboard m, Monad m, Monoid w) => Keyboard (RWST r w s m) |
Constructors
Mouse
class Functor f => Mouse f Source
Instances
| Mouse UI | |
| (Mouse m, Monad m) => Mouse (IdentityT m) | |
| (Mouse m, Functor m) => Mouse (F m) | |
| (Mouse m, Functor m) => Mouse (Free m) | |
| (Mouse m, Monad m) => Mouse (IterT m) | |
| (Mouse m, Monad m) => Mouse (ListT m) | |
| (Mouse m, Monad m) => Mouse (MaybeT m) | |
| (Mouse m, Monad m, Error e) => Mouse (ErrorT e m) | |
| (Mouse m, Monad m) => Mouse (ContT r m) | |
| (Mouse m, Monad m) => Mouse (ReaderT r m) | |
| (Mouse m, Monad m) => Mouse (StateT s m) | |
| (Mouse m, Monad m) => Mouse (StateT s m) | |
| (Mouse m, Monad m, Monoid w) => Mouse (WriterT w m) | |
| (Mouse m, Monad m, Monoid w) => Mouse (WriterT w m) | |
| (Mouse m, Monad m, Monoid w) => Mouse (RWST r w s m) | |
| (Mouse m, Monad m, Monoid w) => Mouse (RWST r w s m) |
mousePosition :: (Applicative f, Mouse f, Local f) => f Vec2Source
Returns the relative coordinate of the cursor.
mouseButtonL :: Mouse f => f BoolSource
mouseButtonR :: Mouse f => f BoolSource
mouseButtonM :: Mouse f => f BoolSource
mouseDownL :: Mouse f => f BoolSource
mouseDownR :: Mouse f => f BoolSource
mouseDownM :: Mouse f => f BoolSource
IO
class FromFinalizer m Source
Instances
| FromFinalizer UI | |
| (FromFinalizer m, Monad m) => FromFinalizer (IdentityT m) | |
| (FromFinalizer m, Functor m) => FromFinalizer (F m) | |
| (FromFinalizer m, Functor m) => FromFinalizer (Free m) | |
| (FromFinalizer m, Monad m) => FromFinalizer (IterT m) | |
| (FromFinalizer m, Monad m) => FromFinalizer (ListT m) | |
| (FromFinalizer m, Monad m) => FromFinalizer (MaybeT m) | |
| FromFinalizer (FinalizerT IO) | |
| (FromFinalizer m, Monad m, Error e) => FromFinalizer (ErrorT e m) | |
| (FromFinalizer m, Monad m) => FromFinalizer (ContT r m) | |
| (FromFinalizer m, Monad m) => FromFinalizer (StateT s m) | |
| (FromFinalizer m, Monad m) => FromFinalizer (StateT s m) | |
| (FromFinalizer m, Monad m, Monoid w) => FromFinalizer (WriterT w m) | |
| (FromFinalizer m, Monad m, Monoid w) => FromFinalizer (WriterT w m) | |
| (FromFinalizer m, Monad m, Monoid w) => FromFinalizer (RWST r w s m) | |
| (FromFinalizer m, Monad m, Monoid w) => FromFinalizer (RWST r w s m) |
embedIO :: FromFinalizer m => IO a -> m aSource
randomness :: (Random r, FromFinalizer m) => (r, r) -> m rSource
Get a given range of value.
Utility functions
Reexports
module Control.Monad
module Control.Applicative
module Control.Bool
module Data.Color
module Data.Color.Names
module Linear
Deprecated
fromBitmap :: Picture2D p => Bitmap -> p ()Source
Deprecated: Use bitmap instead
loadBitmapFromFile :: MonadIO m => FilePath -> m BitmapSource
Deprecated: use readBitmap instead
keySpecial :: Keyboard f => Key -> f BoolSource
Deprecated: use keyPress instead