

play display bg fps world draw handler ( perform steppers ) where perform _time world = world perform ( stepper : steppers ) time world = perform steppers time ( stepper time world ) - Global variable to keep track of the time since we started playing (there can only always be one game anyway). play :: Display - ^Display mode -> Color - ^Background color -> Int - ^Number of simulation steps to take for each second of real time -> world - ^The initial world state -> ( world -> Picture ) - ^A function to convert the world to a picture -> ( Event -> world -> world ) - ^A function to handle individual input events -> - ^Set of functions invoked once per iteration - first argument is the period of time (in seconds) needing to be advanced -> IO () play display bg fps world draw handler steppers = G. Pictures _ps ) = error ": Pictures not implemented yet" - Extended play function - |Play a game. Scale xf yf p ) = let ( origin, ( w, h ) ) = boundingBox p in ( origin, ( w * xf, h * yf ) ) boundingBox ( G. Rotate _ang _p ) = error ": Rotate not implemented yet" boundingBox ( G. Translate dx dy p ) = let ( ( x, y ), size ) = boundingBox p in ( ( x + dx, y + dy ), size ) boundingBox ( G. Color _ p ) = boundingBox p boundingBox ( G. Bitmap w h _ _ ) = ( ( 0, 0 ), ( fromIntegral w, fromIntegral h ) ) boundingBox ( G. Text _ ) = error ": Text not implemented yet" boundingBox ( G. ThickArc _ _ _ _ ) = error ": ThickArc not implemented yet" boundingBox ( G. Arc _ _ _ ) = error ": Arc not implemented yet" boundingBox ( G. ThickCircle t r ) = ( ( 0, 0 ), ( 2 * r + t, 2 * r + t ) ) boundingBox ( G.

Circle r ) = ( ( 0, 0 ), ( 2 * r, 2 * r ) ) boundingBox ( G. Line _ ) = error ": Line not implemented yet" boundingBox ( G. Polygon _ ) = error ": Polygon not implemented yet" boundingBox ( G. FIXME: Current implementation is incomplete! - boundingBox :: Picture -> Rect boundingBox G. jpg :: FilePath -> Picture jpg fname = maybe ( text "JPEG ERROR" ) id ( unsafePerformIO $ loadJuicyJPG fname ) - Query pictures - |Determine the bounding box of a picture. NB: Define loaded pictures on the toplevel to avoid reloading.

png :: FilePath -> Picture png fname = maybe ( text "PNG ERROR" ) id ( unsafePerformIO $ loadJuicyPNG fname ) - |Turn a JPEG file into a picture. bmp :: FilePath -> Picture bmp fname = unsafePerformIO $ loadBMP fname - |Turn a PNG file into a picture.

Game as G - Geometry - type Size = ( Float, Float ) - ^width & height type Rect = ( Point, Size ) - ^origin & extent, where the origin is at the centre - On-the-fly image loading - |Turn a bitmap file into a picture. Picture ( Picture ) - keep 'Picture' abstract import Graphics. Unsafe ( unsafePerformIO ) - packages import Graphics. Game, - * Geometry Size, Rect, - * Load sprites into pictures bmp, png, jpg, - * Query pictures boundingBox, - * More convenient game play play, playInScene, - * Game scenes Animation, animation, noAnimation, animationPicture, Scene, picture, picturing, animating, translating, rotating, scaling, scenes, drawScene, ) where - standard libraries import Data. Game ( - * Reexport some basic Gloss datatypes module Graphics.
Let xf and yf be adjacent floating point numbers license#
Graphics/Gloss/Game.hs - | - Module : Main - Copyright : Manuel M T Chakravarty - License : BSD3 - Maintainer : Manuel M T Chakravarty - Portability : haskell2011 module Graphics.
