FreeGame

Description

Synopsis

# Game

runGame :: WindowMode -> BoundingBox2 -> Game a -> IO (Maybe a) Source

`Game` is a kind of procedure but you can also use it like a value. free-game's design is based on free structures, however, you don't have to mind it -- Just apply `runGame`, and enjoy.

For more examples, see https://github.com/fumieval/free-game/tree/master/examples.

reGame :: (FreeGame m, Monad m) => Game a -> m a Source

Generalize `Game` to any monad based on `FreeGame`.

data WindowMode Source

Constructors

 Windowed Resizable FullScreen

Instances

 Eq WindowMode Ord WindowMode Read WindowMode Show WindowMode

data Box f a :: (* -> *) -> * -> *

The type of bounding box for arbitrary vector `f`. The functions for this type assume that `f` is a "zipping" `Applicative`.

Constructors

 Box (f a) (f a)

Instances

 Monad f => Monad (Box f) Functor f => Functor (Box f) Applicative f => Applicative (Box f) Foldable f => Foldable (Box f) Traversable f => Traversable (Box f) Eq (f a) => Eq (Box f a) Ord (f a) => Ord (Box f a) Read (f a) => Read (Box f a) Show (f a) => Show (Box f a)

isInside :: (Applicative f, Foldable f, Ord a) => f a -> Box f a -> Bool

check whether the point is in the box.

delay :: (Monad f, MonadFree f m) => m a -> m a

In particular, for the iterative monad `Iter`, this makes the computation require one more step, without changing its final result.

`runIter (delay ma) == Right ma`

Delimit the computation to yield a frame.

`foreverFrame :: Frame a -> Game any`

untick :: (Monad m, FreeGame m) => IterT Frame a -> m (Either (IterT Frame a) a) Source

Extract the next frame of the action.

untickInfinite :: (Monad m, FreeGame m) => IterT Frame Void -> m (IterT Frame Void) Source

An infinite version of `untick`.

# Frame

type Frame = F UI Source

reFrame :: (FreeGame m, Monad m) => Frame a -> m a Source

Generalize `Frame` to any monad based on `FreeGame`.

class (Picture2D m, Local m, Keyboard m, Mouse m, FromFinalizer m) => FreeGame m where Source

Methods

draw :: (forall f. (Applicative f, Monad f, Picture2D f, Local f) => f a) -> m a Source

Draw an action that consist of `Picture2D'`s methods.

preloadBitmap :: Bitmap -> m () Source

Load a `Bitmap` to avoid the cost of the first invocation of `bitmap`.

bracket :: Frame a -> m a Source

Run a `Frame`, and release all the matter happened.

forkFrame :: Frame () -> m () Source

Run a `Frame` action concurrently. Do not use this function to draw pictures.

Generate a `Bitmap` from the front buffer.

setFPS :: Double -> m () Source

Set the goal FPS.

setTitle :: String -> m () Source

showCursor :: m () Source

hideCursor :: m () Source

clearColor :: Color -> m () Source

getFPS :: m Int Source

Get the actual FPS value.

setBoundingBox :: BoundingBox2 -> m () Source

Instances

# Transformations

class Functor p => Affine p where Source

Minimal complete definition

Methods

rotateR :: Double -> p a -> p a infixr 5 Source

rotateD :: Double -> p a -> p a infixr 5 Source

(degrees)

scale :: Vec2 -> p a -> p a infixr 5 Source

translate :: Vec2 -> p a -> p a infixr 5 Source

Instances

class Affine p => Local p Source

Minimal complete definition

getLocation

Instances

# Pictures

class Affine p => Picture2D p where Source

The class of types that can be regarded as a kind of picture.

Methods

bitmap :: Bitmap -> p () Source

Construct a `Picture2D` from a `Bitmap`.

bitmapOnce :: Bitmap -> p () Source

Same as `bitmap`, but it does not create a cache.

line :: [Vec2] -> p () Source

polygon :: [Vec2] -> p () Source

polygonOutline :: [Vec2] -> p () Source

circle :: Double -> p () Source

circleOutline :: Double -> p () Source

thickness :: Float -> p a -> p a infixr 5 Source

color :: Color -> p a -> p a infixr 5 Source

blendMode :: BlendMode -> p a -> p a infixr 5 Source

Instances

data BlendMode Source

Constructors

Instances

 Enum BlendMode Eq BlendMode Ord BlendMode Read BlendMode Show BlendMode Typeable * BlendMode

bitmapSize :: Bitmap -> (Int, Int) Source

Get the size of the `Bitmap`.

Arguments

 :: Bitmap original bitmap -> (Int, Int) width and height -> (Int, Int) x and y -> Bitmap result

Extract a `Bitmap` from the specified range.

Load and define all pictures in the specified directory. On base >= 4.6, file paths to actually load will be respect to the directory of the executable. Otherwise it will be based on the current directory.

The type of the given `ExpQ` must be `FilePath -> IO FilePath` FIXME: This may cause name duplication if there are multiple non-alphanumeric file names.

writeBitmap :: MonadIO m => FilePath -> Bitmap -> m () Source

Save `Bitmap` into a file.

# Text

data Font Source

Font object

text :: (FromFinalizer m, Monad m, Picture2D m) => Font -> Double -> String -> m () Source

Render a `String`.

# Keyboard

class Functor f => Keyboard f where Source

Methods

Instances

# Mouse

class Functor f => Mouse f where Source

Minimal complete definition

Methods

Instances

mousePosition :: (Applicative f, Mouse f, Local f) => f Vec2 Source

Returns the relative coordinate of the cursor.

# IO

class FromFinalizer m Source

Minimal complete definition

fromFinalizer

Instances

embedIO :: FromFinalizer m => IO a -> m a Source

`liftIO`　variety for `FromFinalizer`.

liftIO :: MonadIO m => forall a. IO a -> m a

Lift a computation from the `IO` monad.

randomness :: (Random r, FromFinalizer m) => (r, r) -> m r Source

Get a given range of value.

# Utility functions

unitV2 :: Floating a => a -> V2 a Source

An unit vector with the specified angle.

angleV2 :: RealFloat a => V2 a -> a Source

An angle of the given vector.

degrees :: Floating a => a -> a Source

radians :: Floating a => a -> a Source