Fix dependency loop
This commit is contained in:
parent
b7278d6afc
commit
f529fc5237
25 changed files with 251 additions and 199 deletions
|
@ -1,11 +1,8 @@
|
|||
module RPGEngine.Data.Default
|
||||
-- Everything is exported
|
||||
where
|
||||
import RPGEngine.Data (Entity (..), Game (..), Item (..), Layout, Player (..), Level (..), StateBase (..), State (..), Physical (..), Direction (..))
|
||||
import RPGEngine.Data (Entity (..), Game (..), Item (..), Layout, Player (..), Level (..), State (..), Physical (..), Direction (..))
|
||||
import RPGEngine.Input.Core (ListSelector(..))
|
||||
import RPGEngine.Render.LevelSelection (renderLevelSelection)
|
||||
import RPGEngine.Input.Playing (spawnPlayer)
|
||||
import RPGEngine.Render.Menu (renderMenu)
|
||||
|
||||
------------------------------ Defaults ------------------------------
|
||||
|
||||
|
@ -36,9 +33,9 @@ defaultItem = Item {
|
|||
|
||||
defaultLayout :: Layout
|
||||
defaultLayout = [
|
||||
[Blocked, Blocked, Blocked],
|
||||
[Blocked, Entrance, Blocked],
|
||||
[Blocked, Blocked, Blocked]
|
||||
[Blocked, Blocked, Blocked, Blocked, Blocked],
|
||||
[Blocked, Entrance, Walkable, Exit, Blocked],
|
||||
[Blocked, Blocked, Blocked, Blocked, Blocked]
|
||||
]
|
||||
|
||||
defaultLevel :: Level
|
||||
|
@ -52,8 +49,14 @@ defaultLevel = Level {
|
|||
(1, 1, Entrance),
|
||||
(1, 2, Blocked),
|
||||
(2, 0, Blocked),
|
||||
(2, 1, Blocked),
|
||||
(2, 2, Blocked)
|
||||
(2, 1, Walkable),
|
||||
(2, 2, Blocked),
|
||||
(3, 0, Blocked),
|
||||
(3, 1, Exit),
|
||||
(3, 2, Blocked),
|
||||
(4, 0, Blocked),
|
||||
(4, 1, Blocked),
|
||||
(4, 2, Blocked)
|
||||
],
|
||||
items = [],
|
||||
entities = []
|
||||
|
@ -64,4 +67,10 @@ defaultPlayer = Player {
|
|||
playerHp = Prelude.Nothing, -- Compares to infinity
|
||||
inventory = [],
|
||||
position = (0, 0)
|
||||
}
|
||||
|
||||
defaultSelector :: ListSelector
|
||||
defaultSelector = ListSelector {
|
||||
selection = 0,
|
||||
selected = False
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
module RPGEngine.Data.Game
|
||||
( isLegalMove
|
||||
, isPlayerAtExit
|
||||
, isPlayerDead
|
||||
) where
|
||||
|
||||
import RPGEngine.Data
|
||||
|
@ -14,9 +16,21 @@ import RPGEngine.Data.Level (findAt, directionOffsets)
|
|||
|
||||
-- Check if a move is legal by checking what is located at the new position.
|
||||
isLegalMove :: Direction -> Game -> Bool
|
||||
isLegalMove dir g@Game{ state = Playing { level = lvl, player = p@Player{ position = (x, y) }}} = legality
|
||||
isLegalMove dir g@Game{ state = Playing{ level = lvl, player = p@Player{ position = (x, y) }}} = legality
|
||||
where legality = physical `elem` [Walkable, Entrance, Exit]
|
||||
physical = findAt newPos lvl
|
||||
newPos = (x + xD, y + yD)
|
||||
(xD, yD) = directionOffsets dir
|
||||
isLegalMove _ _ = False
|
||||
isLegalMove _ _ = False
|
||||
|
||||
-- Check if a player is standing on an exit
|
||||
isPlayerAtExit :: Game -> Bool
|
||||
isPlayerAtExit g@Game{ state = Playing{ player = player, level = level }} = atExit
|
||||
where playerPos = position player
|
||||
atPos = findAt playerPos level
|
||||
atExit = atPos == Exit
|
||||
isPlayerAtExit _ = False
|
||||
|
||||
-- Check if the players health is <= 0, which means the player is dead.
|
||||
isPlayerDead :: Game -> Bool
|
||||
isPlayerDead _ = False
|
|
@ -5,7 +5,7 @@ where
|
|||
import GHC.IO (unsafePerformIO)
|
||||
import System.Directory (getDirectoryContents)
|
||||
import RPGEngine.Input.Core (ListSelector(..))
|
||||
import RPGEngine.Data (Level (..), Physical (..), Direction (..), Entity (..), Game (..), Item (..), Player (..), StateBase (..), State (..), X, Y, Layout)
|
||||
import RPGEngine.Data (Level (..), Physical (..), Direction (..), Entity (..), Game (..), Item (..), Player (..), State (..), X, Y, Layout)
|
||||
import RPGEngine.Config (levelFolder)
|
||||
|
||||
------------------------------ Exported ------------------------------
|
||||
|
|
Reference in a new issue