#18 & massive structure overhaul

This commit is contained in:
Tibo De Peuter 2022-12-19 22:54:42 +01:00
parent 83659e69b4
commit 3b0de65de1
16 changed files with 397 additions and 221 deletions

View file

@ -0,0 +1,25 @@
-- Representation of all the game's data
module RPGEngine.Internals.Data.Game
( Game(..),
initGame
) where
import RPGEngine.Internals.Data.State
----------------------------- Constants ------------------------------
-- TODO Add more
data Game = Game {
-- Current state of the game
state :: State
}
----------------------------------------------------------------------
-- Initialize the game
initGame :: Game
initGame = Game {
state = defaultState
}

View file

@ -0,0 +1,77 @@
-- Represents an item in the game.
module RPGEngine.Internals.Data.Internals
( Action(..)
, Condition(..)
, Object(..)
, EntityId
, ItemId
) where
----------------------------- Constants ------------------------------
type EntityId = String
type ItemId = String
data Object =
Item { -- All fields are required
-- Easy way to identify items
id :: ItemId,
-- Horizontal coördinate in the level
x :: Int,
-- Vertical coördinate in the level
y :: Int,
name :: String,
-- Short description of the object
description :: String,
-- Counts how often the object can be used by the player. Either
-- infinite or a natural number
useTimes :: Maybe Int,
-- List of conditional actions when the player is standing on this object
actions :: [([Condition], Action)],
-- Interpretation depends on action with this object.
value :: Maybe Int
}
| Entity {
-- Required fields
-- Easy way to identify items
id :: EntityId,
-- Horizontal coördinate in the level
x :: Int,
-- Vertical coördinate in the level
y :: Int,
name :: String,
-- Short description of the object
description :: String,
-- List of conditional actions when the player is standing on this object
actions :: [([Condition], Action)],
-- Optional fields
-- The direction of the item. e.g. a door has a direction.
direction :: Maybe Direction,
-- Some entities have health points.
hp :: Maybe Int,
-- Interpretation depends on action with this object.
value :: Maybe Int
}
data Direction = North
| East
| South
| West
deriving (Show)
data Action = Leave
| RetrieveItem ItemId
| UseItem ItemId
| DecreaseHp EntityId ItemId
| IncreasePlayerHp ItemId
| Nothing
deriving (Show, Eq)
data Condition = InventoryFull
| InventoryContains ItemId
| Not Condition
| AlwaysFalse
deriving (Show, Eq)
----------------------------------------------------------------------

View file

@ -0,0 +1,15 @@
-- Represents a player in the game. This player can move around, pick
-- up items and interact with the world.
module RPGEngine.Internals.Data.Player
( Player(..)
) where
import RPGEngine.Internals.Data.Internals
----------------------------- Constants ------------------------------
data Player = Player {
hp :: Int,
inventory :: [Object]
}

View file

@ -0,0 +1,34 @@
-- 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 RPGEngine.Internals.Data.State
( State(..)
, defaultState
, nextState
) where
----------------------------- Constants ------------------------------
-- Current state of the game.
data State = Menu
| Playing
| Pause
| Win
| Lose
-- Default state of the game, Menu
defaultState :: State
defaultState = Menu
----------------------------------------------------------------------
-- Get the next state based on the current state
nextState :: State -> State
nextState Menu = Playing
nextState Playing = Pause
nextState Pause = Playing
nextState _ = Menu
----------------------------------------------------------------------