Now the player can't walk on solid cells
This commit is contained in:
parent
7e09931173
commit
5254c8429e
|
@ -1,6 +1,7 @@
|
|||
module Dungeon where
|
||||
|
||||
import Data.Matrix hiding ((<|>))
|
||||
import Linear.V2
|
||||
import Data.Tuple
|
||||
import Data.Maybe
|
||||
import Control.Applicative ((<|>))
|
||||
|
@ -30,3 +31,6 @@ makeDungeonFromFile f = do
|
|||
|
||||
dungeonToLists :: Dungeon -> [[Cell]]
|
||||
dungeonToLists (Dungeon m) = toLists m
|
||||
|
||||
getCell :: V2 Int -> Dungeon -> Cell
|
||||
getCell (V2 x y) (Dungeon m) = fromMaybe Solid (safeGet (y+1) (x+1) m)
|
||||
|
|
|
@ -20,9 +20,13 @@ makeLenses ''Game
|
|||
newGame :: IO Game
|
||||
newGame = do
|
||||
dun <- makeDungeonFromFile "maps/test.map"
|
||||
return $ Game dun (Player $ V2 0 0)
|
||||
return $ Game dun (Player $ V2 1 1)
|
||||
|
||||
runAction :: Action -> Game -> Maybe Game
|
||||
runAction (Move vec) game = Just $ game & player . pos +~ vec
|
||||
runAction (Move vec) game =
|
||||
if ableToMove then Just $ game & player . pos .~ newPos
|
||||
else Just game
|
||||
where ableToMove = getCell newPos (game ^. dungeon) == Empty
|
||||
newPos = (game ^. player . pos) + vec
|
||||
runAction None g = Just g
|
||||
runAction ExitGame _ = Nothing
|
||||
|
|
Loading…
Reference in New Issue