2021-02-18 17:25:13 +00:00
|
|
|
{-# LANGUAGE TemplateHaskell, NegativeLiterals #-}
|
2021-02-13 00:06:26 +00:00
|
|
|
|
2021-02-11 22:40:00 +00:00
|
|
|
module Game where
|
|
|
|
|
2021-02-13 00:06:26 +00:00
|
|
|
import Lens.Micro.TH
|
|
|
|
import Lens.Micro
|
2021-02-18 17:25:13 +00:00
|
|
|
import Linear.V2
|
2021-02-13 00:06:26 +00:00
|
|
|
|
2021-02-11 22:40:00 +00:00
|
|
|
import Dungeon
|
|
|
|
import Player
|
|
|
|
import Action
|
|
|
|
|
|
|
|
data Game = Game
|
2021-02-13 00:06:26 +00:00
|
|
|
{ _dungeon :: Dungeon
|
|
|
|
, _player :: Player
|
2021-02-11 22:40:00 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 00:06:26 +00:00
|
|
|
makeLenses ''Game
|
|
|
|
|
2021-02-15 19:57:45 +00:00
|
|
|
newGame :: IO Game
|
|
|
|
newGame = do
|
2021-02-19 18:52:43 +00:00
|
|
|
dun <- makeDungeonFromFile "maps/test.json"
|
2021-02-19 23:31:09 +00:00
|
|
|
return $ Game dun (Player $ V2 1 23)
|
2021-02-11 22:40:00 +00:00
|
|
|
|
|
|
|
runAction :: Action -> Game -> Maybe Game
|
2021-02-18 22:11:24 +00:00
|
|
|
runAction (Move vec) game = Just $ if ableToMove
|
|
|
|
then game & player . pos .~ newPos
|
|
|
|
else game
|
2021-02-18 19:00:36 +00:00
|
|
|
where ableToMove = getCell newPos (game ^. dungeon) == Empty
|
|
|
|
newPos = (game ^. player . pos) + vec
|
2021-02-11 22:40:00 +00:00
|
|
|
runAction None g = Just g
|
|
|
|
runAction ExitGame _ = Nothing
|