Replaced Direction type with vectors

This commit is contained in:
Ivy 2021-02-18 18:31:20 +01:00
parent b46f642728
commit 7e09931173
4 changed files with 14 additions and 25 deletions

View File

@ -18,8 +18,7 @@ executable roguelike
hs-source-dirs: src hs-source-dirs: src
main-is: Main.hs main-is: Main.hs
default-language: Haskell2010 default-language: Haskell2010
other-modules: Direction, other-modules: Dungeon,
Dungeon,
Player, Player,
Game, Game,
Rendering, Rendering,

View File

@ -1,25 +1,26 @@
{-# LANGUAGE NegativeLiterals #-}
module Action where module Action where
import Graphics.Vty.Input import Graphics.Vty.Input
import Control.Applicative import Control.Applicative
import Data.Maybe import Data.Maybe
import Linear.V2
import Direction data Action = Move (V2 Int)
data Action = Walk Direction
| ExitGame | ExitGame
| None | None
bindings :: [(Event, Action)] bindings :: [(Event, Action)]
bindings = bindings =
[ (EvKey (KChar 'k') [], Walk N) [ (EvKey (KChar 'k') [], Move $ V2 0 -1)
, (EvKey (KChar 'j') [], Walk S) , (EvKey (KChar 'j') [], Move $ V2 0 1)
, (EvKey (KChar 'h') [], Walk W) , (EvKey (KChar 'h') [], Move $ V2 -1 0)
, (EvKey (KChar 'l') [], Walk E) , (EvKey (KChar 'l') [], Move $ V2 1 0)
, (EvKey (KChar 'y') [], Walk NW) , (EvKey (KChar 'y') [], Move $ V2 -1 -1)
, (EvKey (KChar 'u') [], Walk NE) , (EvKey (KChar 'u') [], Move $ V2 1 -1)
, (EvKey (KChar 'b') [], Walk SW) , (EvKey (KChar 'b') [], Move $ V2 -1 1)
, (EvKey (KChar 'n') [], Walk SE) , (EvKey (KChar 'n') [], Move $ V2 1 1)
, (EvKey (KChar 'q') [], ExitGame) , (EvKey (KChar 'q') [], ExitGame)
] ]

View File

@ -1,3 +0,0 @@
module Direction where
data Direction = N | S | W | E | NW | NE | SW | SE

View File

@ -8,7 +8,6 @@ import Linear.V2
import Dungeon import Dungeon
import Player import Player
import Direction
import Action import Action
data Game = Game data Game = Game
@ -24,13 +23,6 @@ newGame = do
return $ Game dun (Player $ V2 0 0) return $ Game dun (Player $ V2 0 0)
runAction :: Action -> Game -> Maybe Game runAction :: Action -> Game -> Maybe Game
runAction (Walk N) game = Just $ game & player . pos +~ V2 0 -1 runAction (Move vec) game = Just $ game & player . pos +~ vec
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 None g = Just g runAction None g = Just g
runAction ExitGame _ = Nothing runAction ExitGame _ = Nothing