about summary refs log tree commit diff
path: root/src/Xanthous/Game
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2019-09-19T17·56-0400
committerGriffin Smith <root@gws.fyi>2019-09-19T17·56-0400
commit62a2e05ef222dd69263b819a400a83f8910816f9 (patch)
treeb81ee35bcc1f6f20290e6347e5b6ceff8a9fff12 /src/Xanthous/Game
parent15895c69fe8f1415f45fe33f7b3d564f4239496e (diff)
Add items and inventory
Add a new "Item" entity, which pulls from the previously-existent
ItemType raw, and add a "PickUp" command which takes the (currently
*only*) item off the ground and puts it into the inventory.
Diffstat (limited to 'src/Xanthous/Game')
-rw-r--r--src/Xanthous/Game/Draw.hs24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/Xanthous/Game/Draw.hs b/src/Xanthous/Game/Draw.hs
index bb6508acdff7..8deb20ff84cb 100644
--- a/src/Xanthous/Game/Draw.hs
+++ b/src/Xanthous/Game/Draw.hs
@@ -17,7 +17,7 @@ import Xanthous.Entities
 import Xanthous.Game
   ( GameState(..)
   , entities
-  , revealedEntities
+  , revealedPositions
   , characterPosition
   , MessageHistory(..)
   , messageHistory
@@ -37,28 +37,34 @@ drawMessages (MessageHistory (lastMessage :| _) True) = txt lastMessage
 --   (MessageHistory (lastMessage :| _) True) -> txt lastMessage
 
 drawEntities
-  :: EntityMap SomeEntity -- ^ visible entities
+  :: Set Position
+    -- ^ Positions the character has seen
+    -- FIXME: this will break down as soon as creatures can walk around on their
+    -- own, since we don't want to render things walking around when the
+    -- character can't see them
   -> EntityMap SomeEntity -- ^ all entities
   -> Widget Name
-drawEntities em allEnts
+drawEntities visiblePositions allEnts
   = vBox rows
   where
-    entityPositions = EntityMap.positions em
+    entityPositions = EntityMap.positions allEnts
     maxY = fromMaybe 0 $ maximumOf (folded . y) entityPositions
     maxX = fromMaybe 0 $ maximumOf (folded . x) entityPositions
     rows = mkRow <$> [0..maxY]
     mkRow rowY = hBox $ renderEntityAt . flip Position rowY <$> [0..maxX]
-    renderEntityAt pos =
-      let neighbors = EntityMap.neighbors pos allEnts
-      in maybe (str " ") (drawWithNeighbors neighbors)
-         $ em ^? atPosition pos . folded
+    renderEntityAt pos
+      | pos `member` visiblePositions
+      = let neighbors = EntityMap.neighbors pos allEnts
+        in maybe (str " ") (drawWithNeighbors neighbors)
+           $ allEnts ^? atPosition pos . folded
+      | otherwise = str " "
 
 drawMap :: GameState -> Widget Name
 drawMap game
   = viewport MapViewport Both
   . showCursor Character (game ^. characterPosition . loc)
   $ drawEntities
-    (game ^. revealedEntities)
+    (game ^. revealedPositions)
     (game ^. entities)
 
 drawGame :: GameState -> [Widget Name]