diff options
author | Griffin Smith <root@gws.fyi> | 2019-09-28T19·02-0400 |
---|---|---|
committer | Griffin Smith <root@gws.fyi> | 2019-09-28T19·03-0400 |
commit | ec39dc0a5bed58e0b0b48eeac98e0fd0ceaa65db (patch) | |
tree | 65a53bd79b15020572524db0a6e65ec549b5ab24 /src/Xanthous/Game | |
parent | abea2dcfac0e094bf4ce0d378763af7816b04501 (diff) |
Tweak gormlak movement slightly
- Don't let gormlaks run into things like walls or each other - Add a small element of randomness to gormlaks' motion - Increase gormlaks' vision by a large amount
Diffstat (limited to 'src/Xanthous/Game')
-rw-r--r-- | src/Xanthous/Game/Lenses.hs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/Xanthous/Game/Lenses.hs b/src/Xanthous/Game/Lenses.hs index 91ff5c137d1a..e077e339cd87 100644 --- a/src/Xanthous/Game/Lenses.hs +++ b/src/Xanthous/Game/Lenses.hs @@ -6,17 +6,25 @@ module Xanthous.Game.Lenses , characterPosition , updateCharacterVision , getInitialState + + -- * Collisions + , Collision(..) + , collisionAt ) where -------------------------------------------------------------------------------- import Xanthous.Prelude -------------------------------------------------------------------------------- import System.Random +import Control.Monad.State -------------------------------------------------------------------------------- import Xanthous.Game.State import Xanthous.Data import qualified Xanthous.Data.EntityMap as EntityMap import Xanthous.Data.EntityMap.Graphics (visiblePositions) import Xanthous.Entities.Character (Character, mkCharacter) +import Xanthous.Entities.Environment (Door, open) +import Xanthous.Entities.Item (Item) +import Xanthous.Entities.Creature (Creature) -------------------------------------------------------------------------------- getInitialState :: IO GameState @@ -31,6 +39,9 @@ getInitialState = do _messageHistory = NoMessageHistory _revealedPositions = mempty _promptState = NoPrompt + _debugState = DebugState + { _allRevealed = False + } pure GameState {..} @@ -70,3 +81,20 @@ updateCharacterVision game = let charPos = game ^. characterPosition visible = visiblePositions charPos visionRadius $ game ^. entities in game & revealedPositions <>~ visible + +data Collision + = Stop + | Combat + deriving stock (Show, Eq, Ord, Generic) + deriving anyclass (NFData) + +collisionAt :: MonadState GameState m => Position -> m (Maybe Collision) +collisionAt pos = do + ents <- use $ entities . EntityMap.atPosition pos + pure $ + if | null ents -> Nothing + | any (entityIs @Creature) ents -> pure Combat + | all (entityIs @Item) ents -> Nothing + | doors@(_ : _) <- ents ^.. folded . _SomeEntity @Door + , all (view open) doors -> Nothing + | otherwise -> pure Stop |