packages feed

pine 0.1.0.1 → 0.1.0.2

raw patch · 5 files changed

+40/−28 lines, 5 files

Files

README.md view
@@ -1,7 +1,7 @@ # pine  ![logo](https://github.com/Grinshpon/pine/blob/master/src/Media/logo.png)-Functional Reactive Game Framework in Haskell+Functional 2D Game Framework in Haskell  Inspired by [CodeWorld](https://github.com/google/codeworld) and [Elm](https://elm-lang.org/) @@ -9,4 +9,13 @@  <br> -Currently a Work In Progress, but technically functional. Documentation is currently nonexistant and that is something I'm working on, as well as everything else+Currently a Work In Progress, but technically functional. Documentation is currently minimal and that is something I'm working on, as well as everything else++### TODO:++- [x] Textures+- [ ] Events+- [ ] Sounds+- [ ] Text+- [ ] Improved/cleaner backend+- [ ] Optional higher level api with premade game state and entities
pine.cabal view
@@ -4,12 +4,12 @@ -- -- see: https://github.com/sol/hpack ----- hash: 5c8ce70e58c9a2cc571577e2515cb558a15dc0c3aa9d5728c5f24331217746c9+-- hash: c6906bc45dcc27ae37ed3ac5ae2e0ab85f7cbd22e891ba597dca6603e515ea25  name:           pine-version:        0.1.0.1-synopsis:       Functional Reactive 2D Game Framework-description:    Please see the README on GitHub at <https://github.com/githubuser/pine#readme>+version:        0.1.0.2+synopsis:       Functional 2D Game Framework+description:    Please see the README on GitHub at <https://github.com/grinshpon/pine#readme> category:       Game homepage:       https://github.com/grinshpon/pine#readme bug-reports:    https://github.com/grinshpon/pine/issues
src/Pine.hs view
@@ -7,7 +7,7 @@   , Stateful(..)   , Image(..)   , newImage-  , Canvas+  , Scene   , fromImage   , Event(..)   ) where
src/Pine/Internal/Renderer.hs view
@@ -45,34 +45,35 @@      go :: (Stateful s, Drawable s) => Word32 -> TChan () -> TextureCache -> s -> Maybe SDL.Event -> IO ()     go time updateQueue cache state mevent = do-      time' <- SDL.ticks-      let dt = fromIntegral (time' - time) :: Double       atomically $ readTChan updateQueue -- not ideal, events could get backed up-      cache' <- drawCanvas cache $ draw state+      time' <- SDL.ticks+      let dt = (fromIntegral (time' - time) :: Double) / 1000+      --print $ 1/dt+      cache' <- drawScene cache $ draw state       case mevent of         Nothing -> SDL.pollEvent >>= go time' updateQueue cache' (update (DeltaTime dt) state)         Just ev -> case SDL.eventPayload ev of           SDL.WindowClosedEvent _ -> pure ()-          _ -> SDL.pollEvent >>= go time' updateQueue cache' (update (SDLEvent ev) state)+          _ -> SDL.pollEvent >>= go time' updateQueue cache' (update (SDLEvent ev) $ update (DeltaTime dt) state)      fpsTimer :: TChan () -> Word32 -> IO SDL.RetriggerTimer     fpsTimer updateQueue _ = do       atomically $ writeTChan updateQueue ()       pure $ SDL.Reschedule 16 -    drawCanvas :: TextureCache -> Canvas -> IO TextureCache-    drawCanvas cache canvas = do+    drawScene :: TextureCache -> Scene -> IO TextureCache+    drawScene cache canvas = do       SDL.clear renderer-      cache' <- drawCanvas' cache canvas+      cache' <- drawScene' cache canvas       SDL.present renderer       pure cache' -    drawCanvas' :: TextureCache -> Canvas -> IO TextureCache-    drawCanvas' cache canvas = do+    drawScene' :: TextureCache -> Scene -> IO TextureCache+    drawScene' cache canvas = do       case canvas of         SingleImage img -> drawImages cache [img]         Images imgs -> drawImages cache imgs-        EmptyCanvas -> pure cache+        EmptyScene -> pure cache      drawImages :: TextureCache -> [Image] -> IO TextureCache     drawImages cache [] = pure cache
src/Pine/Internal/Types.hs view
@@ -9,9 +9,9 @@ data Event = DeltaTime Double | SDLEvent SDL.Event deriving (Eq, Show)  --- | Drawable class contains the draw function, which takes a type and converts it into a `Canvas`+-- | Drawable class contains the draw function, which takes a type and converts it into a `Scene` class Drawable d where-  draw :: d -> Canvas --Foldable f => d -> f Image+  draw :: d -> Scene  -- | Stateful class contains initial and update functions. Any objects in your game, including the overrall world, will update according to events that occur class Stateful s where@@ -29,21 +29,23 @@ newImage = Image  --- | A Canvas can be empty, a single `Image`, or a group of `Image`s. (WIP: Later text and other stuff will be added)-data Canvas = EmptyCanvas | SingleImage Image | Images [Image] deriving (Eq, Show)+data Media = MImage Image | MAudio | MText deriving (Eq, Show) -- WIP (TODO: replace instances of Image in Scene with Media -instance Semigroup Canvas where+-- | A Scene can be empty, a single `Image`, or a group of `Image`s. (WIP: Later text and other stuff will be added)+data Scene = EmptyScene | SingleImage Image | Images [Image] deriving (Eq, Show)++instance Semigroup Scene where   (<>) (SingleImage img1) (SingleImage img2) = Images [img1,img2]   (<>) (Images imgs1) (Images imgs2) = Images $ imgs1 <> imgs2   (<>) (SingleImage img) (Images imgs) = Images $ img:imgs   (<>) (Images imgs) (SingleImage img) = Images $ imgs <> [img]-  (<>) EmptyCanvas c = c-  (<>) c EmptyCanvas = c+  (<>) EmptyScene c = c+  (<>) c EmptyScene = c -instance Monoid Canvas where-  mempty = EmptyCanvas+instance Monoid Scene where+  mempty = EmptyScene   mappend = (<>) --- | Convert a single `Image` into a `Canvas`-fromImage :: Image -> Canvas+-- | Convert a single `Image` into a `Scene`+fromImage :: Image -> Scene fromImage = SingleImage