packages feed

FunGEn 0.4.1 → 0.4.2

raw patch · 7 files changed

+117/−43 lines, 7 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Graphics.UI.Fungen: funBinding :: [InputBinding t s u v] -> Game t s u v -> IO (KeyBinder, StillDownHandler)
- Graphics.UI.GLUT.Input: initGLUTInput :: IO (KeyBinder, StillDownHandler)
+ Graphics.UI.Fungen: funInitInput :: [InputBinding t s u v] -> Game t s u v -> IO (KeyBinder, StillDownHandler)
+ Graphics.UI.GLUT.Input: glutInitInput :: IO (KeyBinder, StillDownHandler)

Files

FunGEn.cabal view
@@ -1,5 +1,5 @@ name:               FunGEn
-version:            0.4.1
+version:            0.4.2
 copyright:          (C) 2002 Andre Furtado <awbf@cin.ufpe.br>
 license:            BSD3
 license-file:       LICENSE
@@ -8,7 +8,7 @@ homepage:           http://joyful.com/fungen
 category:           Game
 synopsis:           FUNctional Game ENgine
-description:        Multi-platform 2D game engine built on top of OpenGL & GLUT
+description:        A lightweight, cross-platform, OpenGL/GLUT-based game engine
 stability:          alpha
 cabal-version:      >= 1.6
 build-type:         Simple
Graphics/UI/Fungen/Init.hs view
@@ -49,7 +49,7 @@         windowSize     $= Size     (fromIntegral sx) (fromIntegral sy)
         basicInit sx sy
         game <- createGame userMap objectGroups winConfig gState gAttrib picList
-        (bindKey, stillDown) <- funBinding i game
+        (bindKey, stillDown) <- funInitInput i game
         displayCallback $= (display game gameCicle)
         setRefresh r stillDown
         mainLoop
@@ -67,7 +67,7 @@         matrixMode $= Modelview 0
         loadIdentity
 
--- | Exit the program successfully.
+-- | Exit the program successfully (from within a game action).
 funExit :: IOGame t s u v ()
 funExit = liftIOtoIOGame' exitWith ExitSuccess
 
Graphics/UI/Fungen/Input.hs view
@@ -17,12 +17,12 @@ module Graphics.UI.Fungen.Input (
         InputBinding, InputHandler,
         KeyEvent(..), Key(..), SpecialKey(..), MouseButton(..), Modifiers(..), Position(..),
-        funBinding
+        funInitInput
 ) where
 
 import Graphics.UI.Fungen.Game
 import Graphics.UI.GLUT
-import Graphics.UI.GLUT.Input (KeyEvent(..), KeyBinder, StillDownHandler, initGLUTInput)
+import Graphics.UI.GLUT.Input (KeyEvent(..), KeyBinder, StillDownHandler, glutInitInput)
 
 -- | A FunGEn input handler is like an IOGame (game action) that takes
 -- two extra arguments: the current keyboard modifiers state, and the
@@ -33,11 +33,15 @@ -- | A mapping from an input event to an input handler.
 type InputBinding t s u v = (Key, KeyEvent, InputHandler t s u v)
 
-funBinding :: [InputBinding t s u v] -> Game t s u v -> IO (KeyBinder, StillDownHandler)
-funBinding inputs g = do
-        (bindKey, stillDown) <- initGLUTInput
-        mapM (userBinding g bindKey) inputs 
-        return (bindKey, stillDown)
-
-userBinding :: Game t s u v -> KeyBinder -> InputBinding t s u v -> IO ()
-userBinding g bindKey (key, keyEvent, inputHandler) = bindKey key keyEvent (Just (\mods pos -> runIOGameM (inputHandler mods pos) g))+-- | Initialise the input system, which keeps a list of input event to
+-- action bindings and executes the the proper actions automatically.
+-- Returns a function for adding bindings (GLUT's - should return the
+-- FunGEn-aware one instead ?), and another which should be called
+-- periodically (eg from refresh) to trigger still-down actions.
+funInitInput :: [InputBinding t s u v] -> Game t s u v -> IO (KeyBinder, StillDownHandler)
+funInitInput bindings game = do
+  (glutBindKey, glutStillDown) <- glutInitInput
+  let funBindKey (key, keyEvent, inputHandler) =
+        glutBindKey key keyEvent (Just (\mods pos -> runIOGameM (inputHandler mods pos) game))
+  mapM funBindKey bindings
+  return (glutBindKey, glutStillDown)
Graphics/UI/GLUT/Input.hs view
@@ -10,7 +10,7 @@ -}
 
 module Graphics.UI.GLUT.Input (
-   Key(..), KeyEvent(..), KeyBinder, InputHandler, StillDownHandler, initGLUTInput
+   Key(..), KeyEvent(..), KeyBinder, InputHandler, StillDownHandler, glutInitInput
 ) where
 
 import Data.IORef(IORef, newIORef, readIORef, modifyIORef)
@@ -81,12 +81,12 @@ -- action bindings and executes the the proper actions automatically.
 -- Returns a function for adding bindings, and another which should be
 -- called periodically (eg from refresh) to trigger still-down actions.
-initGLUTInput :: IO (KeyBinder, StillDownHandler)
-initGLUTInput = do
-   -- Using "setKeyRepeat KeyRepeatOff" would be a little bit more
-   -- efficient, but has two disadvantages: It is not yet implemented
-   -- for M$ and it changes the global state of X11.
-   globalKeyRepeat $= GlobalKeyRepeatOff
+glutInitInput :: IO (KeyBinder, StillDownHandler)
+glutInitInput = do
+  -- globalKeyRepeat would be a little bit more efficient, but it has
+  -- two disadvantages: it is not yet implemented for MS windows and
+  -- it changes the global state of X11.
+   perWindowKeyRepeat $= PerWindowKeyRepeatOff
    bindingTable <- newBindingTable
    pressedKeys  <- newKeyTable
    let keyPress k mods pos = do
README.md view
@@ -13,31 +13,82 @@  # <span class="a">Fun<span class="b">ctional</span> G<span class="b">ame</span> En<span class="b">gine</span></span> -FunGEn (Functional Game Engine) is a cross-platform, BSD-licensed,-OpenGL-based 2D game engine written in Haskell. It is intended to help-game programmers make games in a faster and more automated way. FunGEn-supports:+FunGEn (Functional Game Engine) is a BSD-licensed, cross-platform,+OpenGL/GLUT-based, imperative game engine/framework written in+Haskell.  With very few dependencies and two example games, it's one+of the easiest ways to get started with game development in Haskell. -- Initialization, updating, removing, rendering and grouping routines for game objects;-- Definition of a game background (or map), including texture-based maps and tile maps;-- Reading and intepretation of the player's keyboard input;-- Collision detection;-- Time-based functions and pre-defined game actions;-- Loading and displaying of 24-bit bitmap files;-- Debugging and game performance evaluation facilities;-- Sound support (actually for windows platforms only... :-[ );-- Hope to expand this list soon :-]+<img src="pong.png" title="An example pong game" style="float:right; margin:1em;"> -Home:               [http://joyful.com/fungen](http://joyful.com/fungen)  -Docs:               [Original docs](old-site/index.html), moved here from the [old site](http://www.cin.ufpe.br/~haskell/fungen). <!-- Another version of the [pong tutorial](TUTORIAL.html). --> A [video of the worms demo](http://www.youtube.com/watch?v=XRG9H0oC2Fw).  -Hackage & API docs: [http://hackage.haskell.org/package/FunGEn](http://hackage.haskell.org/package/FunGEn)  -Latest code:        [http://hub.darcs.net/simon/fungen](http://hub.darcs.net/simon/fungen)  -Discussion & help:  [#haskell-game](irc://irc.freenode.net/#haskell-game) or [haskell-cafe](http://www.haskell.org/haskellwiki/Mailing_lists)  +FunGEn, created by Andre Furtado, is intended to help game programmers+make games in a faster and more automated way. It supports: +* Initialization, updating, removing, rendering and grouping+  routines for game objects;+* Definition of a game background (or map), including texture-based+  maps and tile maps;+* Reading and intepretation of the player's keyboard and mouse input+* Collision detection;+* Time-based functions and pre-defined game actions;+* Loading and displaying of 24-bit bitmap files;+* Some debugging and game performance evaluation facilities;+* Sound support (maybe ? windows only)++**Home:**                  <http://joyful.com/fungen>+ \+**Hackage:**  <http://hackage.haskell.org/package/FunGEn>+ \+**Docs:**+ [0.4 API docs](http://hackage.haskell.org/packages/archive/FunGEn/0.4.1/doc/html/Graphics-UI-Fungen.html),+ [0.1 intro docs](old-site/index.html)+ <!-- Another version of the [pong tutorial](TUTORIAL.html), -->+ <!-- the [old site](http://www.cin.ufpe.br/~haskell/fungen), -->+ \+**Code:**           <http://hub.darcs.net/simon/fungen>+ \+**Discussion & help:**+ [#haskell-game](irc://irc.freenode.net/#haskell-game) IRC channel,+ [haskell-cafe](http://www.haskell.org/haskellwiki/Mailing_lists) mail list+ \++ ## Getting started -    cabal install FunGEn+<img src="worms.png" title="An example snake game" style="float:right; margin:1em;"> +Install from hackage: ++```+$ cabal update+$ cabal install FunGEn+```++Or, install source and+[run](http://hub.darcs.net/simon/fungen/examples/helloworld.hs)+[the](http://hub.darcs.net/simon/fungen/examples/pong/pong.hs)+[examples](http://hub.darcs.net/simon/fungen/examples/worms/worms.hs):++```+$ darcs get http://hub.darcs.net/simon/fungen+$ cd fungen+$ cabal install+$ (cd examples; ghc helloworld; ./helloworld)+$ (cd examples/pong; ghc pong; ./pong)+$ (cd examples/worms; ghc worms; ./worms)+```++Contribute patches:++- log in to hub.darcs.net and fork <http://hub.darcs.net/simon/fungen>+- push patches to your branch+- give me a "pull request" on #haskell-game++I ([Simon Michael](http://joyful.com)) maintain FunGEn+sporadically. If you'd like to take it and run with it, or+co-maintain, let's chat! I'm sm on the #haskell-game IRC channel.++---+ ## FAQ  **What is a game engine?**@@ -69,8 +120,15 @@ language) when programming in Haskell. You can find more info on HOpenGL in my HOpenGL Tutorial site, or in its official site. +---+ ## Release notes +### 0.4.2 (2013/08/07)++* add q as quit key to examples+* fix buggy input when holding down keys on windows+ ### 0.4.1 (2013/08/06)  * reorganised and exposed more haddocks@@ -78,6 +136,7 @@ ### 0.4 (2013/08/05)  * a new hakyll-based website, incorporating the old site+* tested with GHC 7.6 * input handlers now receive mouse position and modifier state   (inspired by Pradeep Kumar).  See fungentest.hs for examples. * more haddocks@@ -130,6 +189,8 @@   mechanisms following the CGL concepts. This really demands some time,   but the authors expect a new version to be released soon. +---+ ## Contributing  Andre's 2002 todo list:@@ -152,7 +213,11 @@ Would you like to suggest a feature? Feel free to do it. Would you like to implement a feature? Please do it! Keep in touch. +---+ ## Credits++Andre's 2002 credits:  FunGEn was created by Andre Furtado, Computation Science graduation student at the Informatics Center (CIn) of the Federal University of
examples/pong/pong.hs view
@@ -30,8 +30,10 @@             bar    = objectGroup "barGroup"  [createBar]
             ball   = objectGroup "ballGroup" [createBall]
             initScore = Score 0
-            input = [(SpecialKey KeyRight, StillDown, moveBarToRight)
+            input = [
+                     (SpecialKey KeyRight, StillDown, moveBarToRight)
                     ,(SpecialKey KeyLeft,  StillDown, moveBarToLeft)
+                    ,(Char 'q',            Press,     \_ _ -> funExit)
                     ]
         funInit winConfig gameMap [bar,ball] () initScore input gameCycle (Timer 30) bmpList
 
examples/worms/worms.hs view
@@ -86,10 +86,13 @@                       (objectGroup "food"     [createFood]),
                       (objectGroup "tail"      createTail )]
 
-            input = [(SpecialKey KeyLeft,  Press, turnLeft ),
+            input = [
+                     (SpecialKey KeyLeft,  Press, turnLeft ),
                      (SpecialKey KeyRight, Press, turnRight),
                      (SpecialKey KeyUp,    Press, turnUp   ),
-                     (SpecialKey KeyDown,  Press, turnDown )]
+                     (SpecialKey KeyDown,  Press, turnDown )
+                    ,(Char 'q',            Press, \_ _ -> funExit)
+                    ]
         
         funInit winConfig gameMap groups (LevelStart 1) gameAttribute input gameCycle (Timer 150) bmpList