Now the player can't walk on solid cells
This commit is contained in:
parent
7e09931173
commit
5254c8429e
|
@ -1,13 +1,14 @@
|
||||||
module Dungeon where
|
module Dungeon where
|
||||||
|
|
||||||
import Data.Matrix hiding ((<|>))
|
import Data.Matrix hiding ((<|>))
|
||||||
|
import Linear.V2
|
||||||
import Data.Tuple
|
import Data.Tuple
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Control.Applicative ((<|>))
|
import Control.Applicative ((<|>))
|
||||||
|
|
||||||
data Cell = Solid
|
data Cell = Solid
|
||||||
| Empty
|
| Empty
|
||||||
deriving (Eq)
|
deriving (Eq)
|
||||||
|
|
||||||
instance Show Cell where
|
instance Show Cell where
|
||||||
show cell = [fromJust (lookup cell cellChars <|> Just '?')]
|
show cell = [fromJust (lookup cell cellChars <|> Just '?')]
|
||||||
|
@ -30,3 +31,6 @@ makeDungeonFromFile f = do
|
||||||
|
|
||||||
dungeonToLists :: Dungeon -> [[Cell]]
|
dungeonToLists :: Dungeon -> [[Cell]]
|
||||||
dungeonToLists (Dungeon m) = toLists m
|
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 :: IO Game
|
||||||
newGame = do
|
newGame = do
|
||||||
dun <- makeDungeonFromFile "maps/test.map"
|
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 :: 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 None g = Just g
|
||||||
runAction ExitGame _ = Nothing
|
runAction ExitGame _ = Nothing
|
||||||
|
|
Loading…
Reference in New Issue