Fix dependency loop
This commit is contained in:
parent
b7278d6afc
commit
f529fc5237
25 changed files with 251 additions and 199 deletions
|
@ -1,28 +1,17 @@
|
|||
module RPGEngine.Input.Playing
|
||||
module RPGEngine.Input.Playing
|
||||
( handleInputPlaying
|
||||
, checkPlaying
|
||||
, spawnPlayer
|
||||
) where
|
||||
|
||||
import RPGEngine.Input.Core
|
||||
( composeInputHandlers, handleKey, InputHandler )
|
||||
import RPGEngine.Input.Core (InputHandler, handleKey, composeInputHandlers)
|
||||
|
||||
import RPGEngine.Data
|
||||
( Player(Player, position),
|
||||
Direction(West, North, East, South),
|
||||
Physical(Entrance),
|
||||
Y,
|
||||
X,
|
||||
Level(Level, layout),
|
||||
State(..),
|
||||
StateBase(StateBase, renderer, inputHandler),
|
||||
Game(..) )
|
||||
import RPGEngine.Data.Level ( findFirstOf, directionOffsets )
|
||||
import RPGEngine.Data.Game ( isLegalMove )
|
||||
import RPGEngine.Input.Paused ( handleInputPaused )
|
||||
import RPGEngine.Render.Paused ( renderPaused )
|
||||
import RPGEngine.Data (Game (..), Layout(..), Level(..), Physical(..), Player(..), State(..), X, Y, Direction (..))
|
||||
import RPGEngine.Data.Game (isLegalMove, isPlayerDead, isPlayerAtExit)
|
||||
import RPGEngine.Data.Level (directionOffsets, findFirstOf)
|
||||
import Data.Maybe (fromJust, isNothing)
|
||||
import Graphics.Gloss.Interface.IO.Game (Key(..))
|
||||
import Graphics.Gloss.Interface.IO.Interact (SpecialKey(..))
|
||||
import Data.Maybe (isNothing, fromJust)
|
||||
|
||||
------------------------------ Exported ------------------------------
|
||||
|
||||
|
@ -43,6 +32,8 @@ handleInputPlaying = composeInputHandlers [
|
|||
handleKey (Char 'a') $ movePlayer West
|
||||
]
|
||||
|
||||
----------------------------------------------------------------------
|
||||
|
||||
-- Set the initial position of the player in a given level.
|
||||
spawnPlayer :: Level -> Player -> Player
|
||||
spawnPlayer l@Level{ layout = lay } p@Player{ position = prevPos } = p{ position = newPos }
|
||||
|
@ -50,15 +41,30 @@ spawnPlayer l@Level{ layout = lay } p@Player{ position = prevPos } = p{ position
|
|||
newPos | isNothing try = prevPos
|
||||
| otherwise = fromJust try
|
||||
|
||||
----------------------------------------------------------------------
|
||||
checkPlaying :: Game -> Game
|
||||
checkPlaying g@Game{ state = s@Playing{ restart = restart }} = newGame
|
||||
where newGame | isPlayerDead g = loseGame
|
||||
| isPlayerAtExit g = g{ state = goToNextLevel s }
|
||||
| otherwise = g
|
||||
loseGame = g{ state = restart }
|
||||
checkPlaying g = g
|
||||
|
||||
pauseGame :: Game -> Game
|
||||
pauseGame g@Game{ state = playing@Playing{} } = pausedGame
|
||||
where pausedGame = g{ state = pausedState }
|
||||
pausedState = Paused{ base = newBase, continue = playing }
|
||||
newBase = StateBase { renderer = renderPaused, inputHandler = handleInputPaused }
|
||||
where pausedGame = g{ state = Paused playing }
|
||||
pauseGame g = g
|
||||
|
||||
-- Go to next level if there is a next level, otherwise, initialize win state.
|
||||
goToNextLevel :: State -> State
|
||||
goToNextLevel s@Playing{ levels = levels, level = current, count = count, player = player } = nextState
|
||||
where -- Either the next level or winState
|
||||
nextState | (count + 1) < length levels = nextLevelState
|
||||
| otherwise = Win
|
||||
nextLevelState = s{ level = nextLevel, count = count + 1, player = movedPlayer }
|
||||
nextLevel = levels !! (count + 1)
|
||||
movedPlayer = spawnPlayer nextLevel player
|
||||
goToNextLevel s = s
|
||||
|
||||
-- Move a player in a direction if possible.
|
||||
movePlayer :: Direction -> Game -> Game
|
||||
movePlayer dir g@Game{ state = s@Playing{ player = p@Player{ position = (x, y) }}} = newGame
|
||||
|
@ -70,12 +76,6 @@ movePlayer dir g@Game{ state = s@Playing{ player = p@Player{ position = (x, y) }
|
|||
(xD, yD) = directionOffsets dir
|
||||
movePlayer _ g = g
|
||||
|
||||
-- TODO
|
||||
goToNextLevel :: Game -> Game
|
||||
goToNextLevel = undefined
|
||||
|
||||
----------------------------------------------------------------------
|
||||
|
||||
-- Map all Physicals onto coordinates
|
||||
putCoords :: Level -> [(X, Y, Physical)]
|
||||
putCoords l@Level{ layout = lay } = concatMap (\(a, bs) -> map (\(b, c) -> (b, a, c)) bs) numberedList
|
||||
|
|
Reference in a new issue