Ready for takeoff
This commit is contained in:
parent
b36a7a4b95
commit
b622b93932
10 changed files with 106 additions and 29 deletions
39
lib/RPGEngine.hs
Normal file
39
lib/RPGEngine.hs
Normal file
|
@ -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
|
|
@ -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"
|
22
lib/data/Game.hs
Normal file
22
lib/data/Game.hs
Normal file
|
@ -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"
|
||||
}
|
19
lib/render/RenderGame.hs
Normal file
19
lib/render/RenderGame.hs
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
16
src/Main.hs
16
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
|
||||
|
|
|
@ -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: {}
|
||||
|
|
0
test/RPG-Engine-Test.hs
Normal file
0
test/RPG-Engine-Test.hs
Normal file
|
@ -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"
|
0
verslag.pdf
Normal file
0
verslag.pdf
Normal file
Reference in a new issue