From b46f642728a96fb88981440706b07c5f90df877a Mon Sep 17 00:00:00 2001 From: Ivy Date: Thu, 18 Feb 2021 18:25:13 +0100 Subject: [PATCH] Now player uses V2 for position --- roguelike.cabal | 3 ++- src/Game.hs | 21 +++++++++++---------- src/Player.hs | 3 ++- src/Rendering.hs | 5 +++-- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/roguelike.cabal b/roguelike.cabal index 018b758..9261ac6 100644 --- a/roguelike.cabal +++ b/roguelike.cabal @@ -29,4 +29,5 @@ executable roguelike matrix, unordered-containers, microlens-th, - microlens + microlens, + linear diff --git a/src/Game.hs b/src/Game.hs index cc0529d..50b1510 100644 --- a/src/Game.hs +++ b/src/Game.hs @@ -1,9 +1,10 @@ -{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE TemplateHaskell, NegativeLiterals #-} module Game where import Lens.Micro.TH import Lens.Micro +import Linear.V2 import Dungeon import Player @@ -20,16 +21,16 @@ makeLenses ''Game newGame :: IO Game newGame = do dun <- makeDungeonFromFile "maps/test.map" - return $ Game dun (Player (0,0)) + return $ Game dun (Player $ V2 0 0) runAction :: Action -> Game -> Maybe Game -runAction (Walk N) game = Just $ game & player . pos . _2 -~ 1 -runAction (Walk S) game = Just $ game & player . pos . _2 +~ 1 -runAction (Walk W) game = Just $ game & player . pos . _1 -~ 1 -runAction (Walk E) game = Just $ game & player . pos . _1 +~ 1 -runAction (Walk NW) game = Just $ game & player . pos . both -~ 1 -runAction (Walk NE) game = Just $ game & player . pos %~ (\(x,y) -> (x+1, y-1)) -runAction (Walk SW) game = Just $ game & player . pos %~ (\(x,y) -> (x-1, y+1)) -runAction (Walk SE) game = Just $ game & player . pos . both +~ 1 +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 None g = Just g runAction ExitGame _ = Nothing diff --git a/src/Player.hs b/src/Player.hs index 4d6728e..616c978 100644 --- a/src/Player.hs +++ b/src/Player.hs @@ -3,9 +3,10 @@ module Player where import Lens.Micro.TH (makeLenses) +import Linear.V2 data Player = Player - { _pos :: (Int, Int) + { _pos :: V2 Int } makeLenses ''Player diff --git a/src/Rendering.hs b/src/Rendering.hs index 48e91f3..39bf664 100644 --- a/src/Rendering.hs +++ b/src/Rendering.hs @@ -2,6 +2,7 @@ module Rendering where import Lens.Micro import Graphics.Vty +import Linear.V2 import Dungeon import Game @@ -18,5 +19,5 @@ dungeonToImg = vertCat . map (string defAttr . concatMap show) . dungeonToLists playerToImg :: Player -> Image playerToImg p = translateX px . translateY py $ char defAttr '@' - where px = p ^. pos . _1 - py = p ^. pos . _2 + where px = p ^. pos . _x + py = p ^. pos . _y