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.
This commit is contained in:
Griffin Smith 2020-01-03 12:04:08 -05:00
parent 14997bc1a3
commit 5c5aa14a3d
5 changed files with 49 additions and 26 deletions

View file

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