diff --git a/roguelike.cabal b/roguelike.cabal index 9261ac6..fa81a73 100644 --- a/roguelike.cabal +++ b/roguelike.cabal @@ -18,8 +18,7 @@ executable roguelike hs-source-dirs: src main-is: Main.hs default-language: Haskell2010 - other-modules: Direction, - Dungeon, + other-modules: Dungeon, Player, Game, Rendering, diff --git a/src/Action.hs b/src/Action.hs index 6c97f95..de088cc 100644 --- a/src/Action.hs +++ b/src/Action.hs @@ -1,25 +1,26 @@ +{-# LANGUAGE NegativeLiterals #-} + module Action where import Graphics.Vty.Input import Control.Applicative import Data.Maybe +import Linear.V2 -import Direction - -data Action = Walk Direction +data Action = Move (V2 Int) | ExitGame | None bindings :: [(Event, Action)] bindings = - [ (EvKey (KChar 'k') [], Walk N) - , (EvKey (KChar 'j') [], Walk S) - , (EvKey (KChar 'h') [], Walk W) - , (EvKey (KChar 'l') [], Walk E) - , (EvKey (KChar 'y') [], Walk NW) - , (EvKey (KChar 'u') [], Walk NE) - , (EvKey (KChar 'b') [], Walk SW) - , (EvKey (KChar 'n') [], Walk SE) + [ (EvKey (KChar 'k') [], Move $ V2 0 -1) + , (EvKey (KChar 'j') [], Move $ V2 0 1) + , (EvKey (KChar 'h') [], Move $ V2 -1 0) + , (EvKey (KChar 'l') [], Move $ V2 1 0) + , (EvKey (KChar 'y') [], Move $ V2 -1 -1) + , (EvKey (KChar 'u') [], Move $ V2 1 -1) + , (EvKey (KChar 'b') [], Move $ V2 -1 1) + , (EvKey (KChar 'n') [], Move $ V2 1 1) , (EvKey (KChar 'q') [], ExitGame) ] diff --git a/src/Direction.hs b/src/Direction.hs deleted file mode 100644 index 7445eee..0000000 --- a/src/Direction.hs +++ /dev/null @@ -1,3 +0,0 @@ -module Direction where - -data Direction = N | S | W | E | NW | NE | SW | SE diff --git a/src/Game.hs b/src/Game.hs index 50b1510..bff50ca 100644 --- a/src/Game.hs +++ b/src/Game.hs @@ -8,7 +8,6 @@ import Linear.V2 import Dungeon import Player -import Direction import Action data Game = Game @@ -24,13 +23,6 @@ newGame = do return $ Game dun (Player $ V2 0 0) runAction :: Action -> Game -> Maybe Game -runAction (Walk N) game = Just $ game & player . pos +~ V2 0 -1 -runAction (Walk S) game = Just $ game & player . pos +~ V2 0 1 -runAction (Walk W) game = Just $ game & player . pos +~ V2 -1 0 -runAction (Walk E) game = Just $ game & player . pos +~ V2 1 0 -runAction (Walk NW) game = Just $ game & player . pos +~ V2 -1 -1 -runAction (Walk NE) game = Just $ game & player . pos +~ V2 1 -1 -runAction (Walk SW) game = Just $ game & player . pos +~ V2 -1 1 -runAction (Walk SE) game = Just $ game & player . pos +~ V2 1 1 +runAction (Move vec) game = Just $ game & player . pos +~ vec runAction None g = Just g runAction ExitGame _ = Nothing