From 9e5f22458c509caf5ececc45950af09833675ac9 Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Wed, 14 Dec 2022 15:13:43 +0100 Subject: [PATCH] Added state #6, #7, #8 --- lib/RPGEngine.hs | 6 ++--- lib/data/Game.hs | 15 ++++++++----- lib/data/State.hs | 32 +++++++++++++++++++++++++++ lib/render/Render.hs | 47 ++++++++++++++++++++++++++++++++++++++++ lib/render/RenderGame.hs | 19 ---------------- rpg-engine.cabal | 4 ++-- 6 files changed, 93 insertions(+), 30 deletions(-) create mode 100644 lib/data/State.hs create mode 100644 lib/render/Render.hs delete mode 100644 lib/render/RenderGame.hs diff --git a/lib/RPGEngine.hs b/lib/RPGEngine.hs index 3c4812a..44047fb 100644 --- a/lib/RPGEngine.hs +++ b/lib/RPGEngine.hs @@ -6,10 +6,10 @@ module RPGEngine ) where import Game -import RenderGame +import Render import Graphics.Gloss ( Color(..) - , black + , white , play ) @@ -25,7 +25,7 @@ winOffsets = (0, 0) -- Game background color bgColor :: Color -bgColor = black +bgColor = white ---------------------------------------------------------------------- diff --git a/lib/data/Game.hs b/lib/data/Game.hs index 350b386..3a07903 100644 --- a/lib/data/Game.hs +++ b/lib/data/Game.hs @@ -2,21 +2,24 @@ module Game ( Game(..) -, initGame -- Initialize the game + +-- Initialize the game +, initGame ) where +import State + ----------------------------- Constants ------------------------------ +-- TODO Add more data Game = Game { - -- TODO Add more - playerName :: String + -- Current state of the game + state :: State } ---------------------------------------------------------------------- --- Initialize the game --- TODO Expand initGame :: Game initGame = Game { - playerName = "Tibo" + state = defaultState } diff --git a/lib/data/State.hs b/lib/data/State.hs new file mode 100644 index 0000000..1ae7a29 --- /dev/null +++ b/lib/data/State.hs @@ -0,0 +1,32 @@ +-- Describes the current state of the game, +-- e.g. Main menu, game, pause, win or lose +-- Allows to easily go to a next state and change rendering accordingly + +module State +( State(..) +-- Default state of the game, Menu +, defaultState + +-- Get the next state based on the current state +, nextState +) where + +----------------------------- Constants ------------------------------ + +-- Current state of the game. +data State = Menu + | Playing + | Pause + | Win + | Lose + +---------------------------------------------------------------------- + +defaultState :: State +defaultState = Menu + +nextState :: State -> State +nextState Menu = Playing +nextState Playing = Pause +nextState Pause = Playing +nextState _ = Menu \ No newline at end of file diff --git a/lib/render/Render.hs b/lib/render/Render.hs new file mode 100644 index 0000000..a94fed5 --- /dev/null +++ b/lib/render/Render.hs @@ -0,0 +1,47 @@ +-- Allows to render the played game + +module Render +( +-- Initialize a window to play in +initWindow + +-- Render the game +, render +) where + +import Game(Game(..)) +import State(State(..)) +import Graphics.Gloss + +---------------------------------------------------------------------- + +initWindow :: String -> (Int, Int) -> (Int, Int) -> Display +initWindow title dims offs = InWindow title dims offs + +render :: Game -> Picture +render g@Game{ state = Menu } = renderMenu g +render g@Game{ state = Playing } = renderPlaying g +render g@Game{ state = Pause } = renderPause g +render g@Game{ state = Win } = renderWin g +render g@Game{ state = Lose } = renderLose g + + +-- TODO +renderMenu :: Game -> Picture +renderMenu _ = text "Menu" + +-- TODO +renderPlaying :: Game -> Picture +renderPlaying _ = text "Playing" + +-- TODO +renderPause :: Game -> Picture +renderPause _ = text "Pause" + +-- TODO +renderWin :: Game -> Picture +renderWin _ = text "Win" + +-- TODO +renderLose :: Game -> Picture +renderLose _ = text "Lose" \ No newline at end of file diff --git a/lib/render/RenderGame.hs b/lib/render/RenderGame.hs deleted file mode 100644 index aac0ed2..0000000 --- a/lib/render/RenderGame.hs +++ /dev/null @@ -1,19 +0,0 @@ --- 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 b068317..754ec51 100644 --- a/rpg-engine.cabal +++ b/rpg-engine.cabal @@ -11,8 +11,8 @@ library gloss >= 1.11 && < 1.14, gloss-juicy >= 0.2.3 exposed-modules: RPGEngine, - Game, - RenderGame + Game, State, + Render executable rpg-engine main-is: Main.hs