aboutsummaryrefslogtreecommitdiff
path: root/Demos
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2024-12-30 19:14:12 -0800
committer3gg <3gg@shellblade.net>2024-12-30 19:14:12 -0800
commitf1939232bec72fffede16a55119bc7c4fb3057cf (patch)
tree379a8268ff765023527bbf0a4e2088396dba5f84 /Demos
parent34cac097d15cdd7ef0a0de8b9024db9acfe8618d (diff)
Simplify Game monad.
Diffstat (limited to 'Demos')
-rw-r--r--Demos/Pong/Main.hs18
1 files changed, 9 insertions, 9 deletions
diff --git a/Demos/Pong/Main.hs b/Demos/Pong/Main.hs
index de8e6f2..df90020 100644
--- a/Demos/Pong/Main.hs
+++ b/Demos/Pong/Main.hs
@@ -41,16 +41,16 @@ initGame window = do
41 41
42endGame :: Game GameState () 42endGame :: Game GameState ()
43endGame = do 43endGame = do
44 game <- getGameState 44 game <- get
45 runSubGame' (deleteImmRenderer $ immRenderState game) (renderCoreState game) 45 runSubGame' (deleteImmRenderer $ immRenderState game) (renderCoreState game)
46 46
47 47
48step :: Elapsed -> Dt -> [InputEvent] -> Game GameState Bool 48step :: Elapsed -> Dt -> [InputEvent] -> Game GameState Bool
49step elapsed dt inputEvents = do 49step elapsed dt inputEvents = do
50 gs <- getGameState 50 gs <- get
51 events <- processInput (window gs) 51 events <- processInput (window gs)
52 --when (events /= []) $ gameIO . putStrLn $ show events 52 --when (events /= []) $ liftIO . putStrLn $ show events
53 modifyGameState $ \gs -> 53 modify $ \gs ->
54 gs 54 gs
55 { world = stepWorld (realToFrac elapsed) (realToFrac dt) events (world gs) 55 { world = stepWorld (realToFrac elapsed) (realToFrac dt) events (world gs)
56 } 56 }
@@ -67,18 +67,18 @@ exitRequested = elem (KeyDown KEY_ESC)
67 67
68render :: Game GameState () 68render :: Game GameState ()
69render = do 69render = do
70 gameState <- getGameState 70 gameState <- get
71 immRenderState' <- flip execSubGame (immRenderState gameState) $ do 71 immRenderState' <- flip execSubGame (immRenderState gameState) $ do
72 immStart 72 immStart
73 immSetViewProjectionMatrix (viewProjection gameState) 73 immSetViewProjectionMatrix (viewProjection gameState)
74 -- Clear the background to a different colour than the playable area to make 74 -- Clear the background to a different colour than the playable area to make
75 -- the latter distinguishable. 75 -- the latter distinguishable.
76 gameIO $ do 76 liftIO $ do
77 setClearColour (0.2, 0.2, 0.2, 0.0) 77 setClearColour (0.2, 0.2, 0.2, 0.0)
78 clearBuffers [ColourBuffer] 78 clearBuffers [ColourBuffer]
79 render' $ world gameState 79 render' $ world gameState
80 immEnd 80 immEnd
81 saveGameState $ gameState { immRenderState = immRenderState' } 81 put $ gameState { immRenderState = immRenderState' }
82 82
83render' :: [GameObject] -> Game ImmRenderState () 83render' :: [GameObject] -> Game ImmRenderState ()
84render' world = do 84render' world = do
@@ -122,7 +122,7 @@ resize (ResizeEvent w h) =
122 bottom = if r > 1 then 0 else -pad 122 bottom = if r > 1 then 0 else -pad
123 top = if r > 1 then 1 else 1 + pad 123 top = if r > 1 then 1 else 1 + pad
124 in do 124 in do
125 gameIO $ setViewport 0 0 w h 125 liftIO $ setViewport 0 0 w h
126 modifyGameState $ \state -> state { 126 modify $ \state -> state {
127 viewProjection = Matrix4.ortho left right bottom top (-1) 1 127 viewProjection = Matrix4.ortho left right bottom top (-1) 1
128 } 128 }