diff options
author | Griffin Smith <root@gws.fyi> | 2020-01-03T17·04-0500 |
---|---|---|
committer | Griffin Smith <root@gws.fyi> | 2020-01-03T17·04-0500 |
commit | 5c5aa14a3dcb5c172eaf8d2236b41020c8e92051 (patch) | |
tree | 2cb247aa5dae22203ca72c88718f8438f7c11379 /src/Xanthous/Game/Lenses.hs | |
parent | 14997bc1a3501cb3b759dc6dff7a2604deb6648b (diff) |
Don't render moving entities that aren't visible
When the character walks away from or around the corner from entities that move such that they're no longer visible, stop rendering them. Still render static entities like walls, doors, and items though. This prevents entities walking into a "revealed position" after the character's left being visible despite not being in a line of sight any more.
Diffstat (limited to 'src/Xanthous/Game/Lenses.hs')
-rw-r--r-- | src/Xanthous/Game/Lenses.hs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/Xanthous/Game/Lenses.hs b/src/Xanthous/Game/Lenses.hs index 853f758385b1..4a080f85f017 100644 --- a/src/Xanthous/Game/Lenses.hs +++ b/src/Xanthous/Game/Lenses.hs @@ -5,6 +5,7 @@ module Xanthous.Game.Lenses , character , characterPosition , updateCharacterVision + , characterVisiblePositions , getInitialState , initialStateFromSeed @@ -84,12 +85,16 @@ characterPosition = positionedCharacter . position visionRadius :: Word visionRadius = 12 -- TODO make this dynamic --- | Update the revealed entities at the character's position based on their vision +-- | Update the revealed entities at the character's position based on their +-- vision updateCharacterVision :: GameState -> GameState -updateCharacterVision game = +updateCharacterVision game + = game & revealedPositions <>~ characterVisiblePositions game + +characterVisiblePositions :: GameState -> Set Position +characterVisiblePositions game = let charPos = game ^. characterPosition - visible = visiblePositions charPos visionRadius $ game ^. entities - in game & revealedPositions <>~ visible + in visiblePositions charPos visionRadius $ game ^. entities data Collision = Stop |