diff --git a/src/Dungeon.hs b/src/Dungeon.hs index 2e650ea..6a4d21a 100644 --- a/src/Dungeon.hs +++ b/src/Dungeon.hs @@ -1,13 +1,14 @@ module Dungeon where import Data.Matrix hiding ((<|>)) +import Linear.V2 import Data.Tuple import Data.Maybe import Control.Applicative ((<|>)) data Cell = Solid - | Empty - deriving (Eq) + | Empty + deriving (Eq) instance Show Cell where show cell = [fromJust (lookup cell cellChars <|> Just '?')] @@ -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) diff --git a/src/Game.hs b/src/Game.hs index bff50ca..ba49b4a 100644 --- a/src/Game.hs +++ b/src/Game.hs @@ -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