diff --git a/lib/RPGEngine.hs b/lib/RPGEngine.hs new file mode 100644 index 0000000..3c4812a --- /dev/null +++ b/lib/RPGEngine.hs @@ -0,0 +1,39 @@ +-- Allows to play a game using RPGEngine. +-- Includes all logic and rendering. + +module RPGEngine +( playRPGEngine +) where + +import Game +import RenderGame +import Graphics.Gloss ( + Color(..) + , black + , play + ) + +----------------------------- Constants ------------------------------ + +-- Dimensions for main window +winDimensions :: (Int, Int) +winDimensions = (1280, 720) + +-- Offsets for main window +winOffsets :: (Int, Int) +winOffsets = (0, 0) + +-- Game background color +bgColor :: Color +bgColor = black + +---------------------------------------------------------------------- + +-- This is the gameloop. +-- It can receive input and update itself. It is rendered by a renderer. +playRPGEngine :: String -> Int -> IO() +playRPGEngine title fps = do + play window bgColor fps initGame render handleInputs step + where window = initWindow title winDimensions winOffsets + step _ g = g -- TODO Do something with step? + handleInputs _ g = g -- TODO Implement inputHanlders diff --git a/lib/VoorbeeldModule.hs b/lib/VoorbeeldModule.hs deleted file mode 100644 index 63dfdf3..0000000 --- a/lib/VoorbeeldModule.hs +++ /dev/null @@ -1,10 +0,0 @@ -module VoorbeeldModule - ( hoi -- oplijsting van de publieke functies - als je deze lijst en de haakjes weglaat, wordt alles publiek - , hallo - ) where - -hoi :: String -hoi = "Hoi" - -hallo :: String -hallo = "Hallo" diff --git a/lib/data/Game.hs b/lib/data/Game.hs new file mode 100644 index 0000000..350b386 --- /dev/null +++ b/lib/data/Game.hs @@ -0,0 +1,22 @@ +-- Representation of all the game's data + +module Game +( Game(..) +, initGame -- Initialize the game +) where + +----------------------------- Constants ------------------------------ + +data Game = Game { + -- TODO Add more + playerName :: String +} + +---------------------------------------------------------------------- + +-- Initialize the game +-- TODO Expand +initGame :: Game +initGame = Game { + playerName = "Tibo" +} diff --git a/lib/render/RenderGame.hs b/lib/render/RenderGame.hs new file mode 100644 index 0000000..aac0ed2 --- /dev/null +++ b/lib/render/RenderGame.hs @@ -0,0 +1,19 @@ +-- Allows to render the played game + +module RenderGame +( initWindow -- Initialize a window to play in +, render -- Rener the game +) where + +import Game +import Graphics.Gloss + +---------------------------------------------------------------------- + +-- Render the game +render :: Game -> Picture +render _ = Blank + +-- Initialize a window to play in +initWindow :: String -> (Int, Int) -> (Int, Int) -> Display +initWindow title dims offs = InWindow title dims offs diff --git a/rpg-engine.cabal b/rpg-engine.cabal index 7d6f4ad..b068317 100644 --- a/rpg-engine.cabal +++ b/rpg-engine.cabal @@ -1,13 +1,18 @@ name: rpg-engine version: 1.0.0 -author: Author name here +author: Tibo De Peuter cabal-version: 1.12 build-type: Simple library - hs-source-dirs: lib - build-depends: base >= 4.7 && <5 - exposed-modules: VoorbeeldModule + hs-source-dirs: lib, lib/control, lib/data, lib/render + build-depends: + base >= 4.7 && <5, + gloss >= 1.11 && < 1.14, gloss-juicy >= 0.2.3 + exposed-modules: + RPGEngine, + Game, + RenderGame executable rpg-engine main-is: Main.hs @@ -17,7 +22,7 @@ executable rpg-engine test-suite rpg-engine-test type: exitcode-stdio-1.0 - main-is: VoorbeeldTest.hs + main-is: RPG-Engine-Test.hs hs-source-dirs: test default-language: Haskell2010 build-depends: base >=4.7 && <5, hspec <= 2.10.6, rpg-engine diff --git a/src/Main.hs b/src/Main.hs index 55d35ac..bb69131 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -1,4 +1,16 @@ -import VoorbeeldModule (hoi) +import RPGEngine + +----------------------------- Constants ------------------------------ + +-- Title of the game +title :: String +title = "RPG Engine" + +-- Framerate of the game +fps :: Int +fps = 60 + +---------------------------------------------------------------------- main :: IO () -main = putStrLn hoi +main = playRPGEngine title fps diff --git a/stack.yaml b/stack.yaml index 2c311ed..2539f5a 100644 --- a/stack.yaml +++ b/stack.yaml @@ -35,12 +35,13 @@ packages: # These entries can reference officially published versions as well as # forks / in-progress versions pinned to a git hash. For example: # -# extra-deps: +extra-deps: # - acme-missiles-0.3 # - git: https://github.com/commercialhaskell/stack.git # commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a # # extra-deps: [] +- gloss-juicy-0.2.3@sha256:0c3bca95237cbf91f8b3b1936a0661f1e0457acd80502276d54d6c5210f88b25,1618 # Override default flag values for local packages and extra-deps # flags: {} diff --git a/test/RPG-Engine-Test.hs b/test/RPG-Engine-Test.hs new file mode 100644 index 0000000..e69de29 diff --git a/test/VoorbeeldTest.hs b/test/VoorbeeldTest.hs deleted file mode 100644 index 2b94edb..0000000 --- a/test/VoorbeeldTest.hs +++ /dev/null @@ -1,11 +0,0 @@ -import Test.Hspec - -import VoorbeeldModule (hoi, hallo) - -main :: IO () -main = hspec $ do - it "Returns correct string for hoi" $ do - hoi `shouldBe` "Hoi" - - it "Returns correct string for hallo" $ do - hallo `shouldBe` "Hallo" diff --git a/verslag.pdf b/verslag.pdf new file mode 100644 index 0000000..e69de29