diff options
| author | Jeanne-Kamikaze <jeannekamikaze@gmail.com> | 2013-12-23 01:17:43 +0100 |
|---|---|---|
| committer | Jeanne-Kamikaze <jeannekamikaze@gmail.com> | 2013-12-23 01:17:43 +0100 |
| commit | 85da1895b865cf68300c9a2299a113cee0aa1cbd (patch) | |
| tree | 05f5cbc123a4fe7a7ab8d89b9b60995f31cef80a /demos | |
| parent | 3718dc298578317a96cce1f12c49c06f1a8e5f0a (diff) | |
Window module now tracks elapsed time
Diffstat (limited to 'demos')
| -rw-r--r-- | demos/pong/Main.hs | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/demos/pong/Main.hs b/demos/pong/Main.hs index e9a6dc1..d0664b7 100644 --- a/demos/pong/Main.hs +++ b/demos/pong/Main.hs | |||
| @@ -14,7 +14,6 @@ import Graphics.Rendering.OpenGL.GL (($=)) | |||
| 14 | 14 | ||
| 15 | data GameState = GameState | 15 | data GameState = GameState |
| 16 | { wnd :: Window | 16 | { wnd :: Window |
| 17 | , elapsed :: Double | ||
| 18 | , world :: [GameObject] | 17 | , world :: [GameObject] |
| 19 | } | 18 | } |
| 20 | 19 | ||
| @@ -27,17 +26,16 @@ initGame wnd = do | |||
| 27 | GL.clearColor $= GL.Color4 0.7 0.5 0.7 1.0 | 26 | GL.clearColor $= GL.Color4 0.7 0.5 0.7 1.0 |
| 28 | GL.matrixMode $= GL.Modelview 0 | 27 | GL.matrixMode $= GL.Modelview 0 |
| 29 | GL.loadIdentity | 28 | GL.loadIdentity |
| 30 | return $ GameState wnd 0 newWorld | 29 | return $ GameState wnd newWorld |
| 31 | 30 | ||
| 32 | step :: Dt -> Game GameState Bool | 31 | step :: Elapsed -> Dt -> Game GameState Bool |
| 33 | step dt = do | 32 | step elapsed dt = do |
| 34 | gs <- getGameState | 33 | gs <- getGameState |
| 35 | evts <- events (wnd gs) | 34 | evts <- events (wnd gs) |
| 36 | gameIO . process $ evts | 35 | gameIO . process $ evts |
| 37 | let evts' = translate evts | 36 | let evts' = translate evts |
| 38 | modifyGameState $ \ gs -> gs | 37 | modifyGameState $ \ gs -> gs |
| 39 | { world = stepWorld (elapsed gs) dt evts' (world gs) | 38 | { world = stepWorld elapsed dt evts' (world gs) } |
| 40 | , elapsed = elapsed gs + realToFrac dt } | ||
| 41 | getGameState >>= \gs -> gameIO . render $ world gs | 39 | getGameState >>= \gs -> gameIO . render $ world gs |
| 42 | return (not $ exitRequested evts) | 40 | return (not $ exitRequested evts) |
| 43 | 41 | ||
| @@ -78,4 +76,4 @@ translate' _ = Nothing | |||
| 78 | exitRequested = any (==(KeyDown KEY_ESC)) | 76 | exitRequested = any (==(KeyDown KEY_ESC)) |
| 79 | 77 | ||
| 80 | f2d :: Float -> GL.GLdouble | 78 | f2d :: Float -> GL.GLdouble |
| 81 | f2d = realToFrac \ No newline at end of file | 79 | f2d = realToFrac |
