dev #16
6 changed files with 93 additions and 30 deletions
|
@ -6,10 +6,10 @@ module RPGEngine
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Game
|
import Game
|
||||||
import RenderGame
|
import Render
|
||||||
import Graphics.Gloss (
|
import Graphics.Gloss (
|
||||||
Color(..)
|
Color(..)
|
||||||
, black
|
, white
|
||||||
, play
|
, play
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ winOffsets = (0, 0)
|
||||||
|
|
||||||
-- Game background color
|
-- Game background color
|
||||||
bgColor :: Color
|
bgColor :: Color
|
||||||
bgColor = black
|
bgColor = white
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -2,21 +2,24 @@
|
||||||
|
|
||||||
module Game
|
module Game
|
||||||
( Game(..)
|
( Game(..)
|
||||||
, initGame -- Initialize the game
|
|
||||||
|
-- Initialize the game
|
||||||
|
, initGame
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import State
|
||||||
|
|
||||||
----------------------------- Constants ------------------------------
|
----------------------------- Constants ------------------------------
|
||||||
|
|
||||||
data Game = Game {
|
|
||||||
-- TODO Add more
|
-- TODO Add more
|
||||||
playerName :: String
|
data Game = Game {
|
||||||
|
-- Current state of the game
|
||||||
|
state :: State
|
||||||
}
|
}
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
-- Initialize the game
|
|
||||||
-- TODO Expand
|
|
||||||
initGame :: Game
|
initGame :: Game
|
||||||
initGame = Game {
|
initGame = Game {
|
||||||
playerName = "Tibo"
|
state = defaultState
|
||||||
}
|
}
|
||||||
|
|
32
lib/data/State.hs
Normal file
32
lib/data/State.hs
Normal file
|
@ -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
|
47
lib/render/Render.hs
Normal file
47
lib/render/Render.hs
Normal file
|
@ -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"
|
|
@ -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
|
|
|
@ -11,8 +11,8 @@ library
|
||||||
gloss >= 1.11 && < 1.14, gloss-juicy >= 0.2.3
|
gloss >= 1.11 && < 1.14, gloss-juicy >= 0.2.3
|
||||||
exposed-modules:
|
exposed-modules:
|
||||||
RPGEngine,
|
RPGEngine,
|
||||||
Game,
|
Game, State,
|
||||||
RenderGame
|
Render
|
||||||
|
|
||||||
executable rpg-engine
|
executable rpg-engine
|
||||||
main-is: Main.hs
|
main-is: Main.hs
|
||||||
|
|
Reference in a new issue