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
main-is: Main.hs
default-language: Haskell2010
other-modules: Direction,
Dungeon,
other-modules: Dungeon,
Player,
Game,
Rendering,

View File

@ -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)
]

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 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