From 58417742849c0f55ad64bdbd4d88278a6a3e54aa Mon Sep 17 00:00:00 2001 From: nek0 Date: Mon, 20 Feb 2017 20:21:06 +0100 Subject: [PATCH] changes in the engine --- haskelloids.cabal | 2 +- src/InGame.hs | 33 ++++++++++++++++++++++++--------- src/Main.hs | 5 ++--- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/haskelloids.cabal b/haskelloids.cabal index c8f0f34..9ce4d1e 100644 --- a/haskelloids.cabal +++ b/haskelloids.cabal @@ -66,7 +66,7 @@ executable haskelloids , affection , gegl , babl - , sdl2 + , sdl2 >= 2.1.3.1 , containers , random diff --git a/src/InGame.hs b/src/InGame.hs index 80559fa..81d8e2f 100644 --- a/src/InGame.hs +++ b/src/InGame.hs @@ -18,18 +18,22 @@ import Commons loadGame :: Affection UserData () loadGame = do + liftIO $ traceIO "loading game" ud <- getAffection _ <- liftIO $ gegl_node_connect_to (nodeGraph ud M.! KeyShipTranslate) "output" (nodeGraph ud M.! KeyShipOver) "aux" + liftIO $ traceIO "nodes connected" hs <- liftIO $ catMaybes <$> foldM (\acc _ -> do coords <- liftIO excludeShip insertHaskelloid acc Nothing coords ) [] ([0..9] :: [Int]) + liftIO $ traceIO "inserted haskelloids" liftIO $ gegl_node_link_many $ map hFlange hs liftIO $ gegl_node_link (last $ map hFlange hs) (nodeGraph ud M.! KeyHNop) + liftIO $ traceIO "nodes linked" putAffection ud { haskelloids = hs , wonlost = False @@ -46,6 +50,11 @@ loadGame = do , pixelSize = 3 , state = InGame } + liftIO $ traceIO "game loaded" + present + (GeglRectangle 0 0 800 600) + (buffer ud) + True excludeShip :: IO (Double, Double) excludeShip = do @@ -104,19 +113,25 @@ updateGame sec = do drawGame :: Affection UserData () drawGame = do + -- ud <- getAffection + -- liftIO $ gegl_node_process $ nodeGraph ud M.! KeySink + -- present + -- (GeglRectangle (floor $ fst $ sPos $ ship ud) (floor $ snd $ sPos $ ship ud) 50 50) + -- (buffer ud) + -- False + -- mapM_ (\h -> do + -- let s = 100 `div` hDiv h + -- present + -- (GeglRectangle (floor $ fst $ hPos h) (floor $ snd $ hPos h) s s) + -- (buffer ud) + -- False + -- ) (haskelloids ud) ud <- getAffection liftIO $ gegl_node_process $ nodeGraph ud M.! KeySink present - (GeglRectangle (floor $ fst $ sPos $ ship ud) (floor $ snd $ sPos $ ship ud) 50 50) + (GeglRectangle 0 0 800 600) (buffer ud) - False - mapM_ (\h -> do - let s = 100 `div` hDiv h - present - (GeglRectangle (floor $ fst $ hPos h) (floor $ snd $ hPos h) s s) - (buffer ud) - False - ) (haskelloids ud) + True handleGameEvent :: Double -> SDL.Event -> Affection UserData () handleGameEvent sec e = do diff --git a/src/Main.hs b/src/Main.hs index 4545a72..deb67b6 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -44,11 +44,10 @@ pre = do -- (buffer ud) -- True -update :: Double -> Affection UserData () -update sec = do +update :: Double -> [SDL.Event] -> Affection UserData () +update sec evs = do wd <- getAffection smUpdate (state wd) sec - evs <- SDL.pollEvents mapM_ (smEvent (state wd) sec) evs draw :: Affection UserData ()