about summary refs log tree commit diff
path: root/src/Xanthous/Game/State.hs
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2020-01-03T23·28-0500
committerGriffin Smith <root@gws.fyi>2020-01-03T23·28-0500
commit84f32efad4ff6d358fdeb985b3b4ac408e753b78 (patch)
treed22d15bbbd88d9dd253f13dd9bf64205022686b4 /src/Xanthous/Game/State.hs
parent1b88921bc36e5da1ade5c52827d057dc2be65bc5 (diff)
Track entity collision in the Entity class
Rather than having a single function in the Game.Lenses module for
determining what collision type if any an entity has, track it in the
Entity typeclass itself. This is both more extensible and a better
separation of concerns and gets rid of one of the two needs for a
circular import. Yay!

As part of this, I realized nothing was being done to prevent doors from
being placed on tiles that already had walls (since now that was
properly causing a collision!) so I've fixed that as well.
Diffstat (limited to 'src/Xanthous/Game/State.hs')
-rw-r--r--src/Xanthous/Game/State.hs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Xanthous/Game/State.hs b/src/Xanthous/Game/State.hs
index 853d0b6922d1..171f381e6b74 100644
--- a/src/Xanthous/Game/State.hs
+++ b/src/Xanthous/Game/State.hs
@@ -34,6 +34,7 @@ module Xanthous.Game.State
   , Brain(..)
   , Brainless(..)
   , brainVia
+  , Collision(..)
   , Entity(..)
   , SomeEntity(..)
   , downcastEntity
@@ -306,6 +307,13 @@ brainVia _ ticks = fmap coerce . step ticks . coerce @_ @(Positioned brain)
 
 --------------------------------------------------------------------------------
 
+
+data Collision
+  = Stop   -- ^ Can't move through this
+  | Combat -- ^ Moving into this equates to hitting it with a stick
+  deriving stock (Show, Eq, Ord, Generic)
+  deriving anyclass (NFData)
+
 class ( Show a, Eq a, Ord a, NFData a
       , ToJSON a, FromJSON a
       , Draw a, Brain a
@@ -313,6 +321,8 @@ class ( Show a, Eq a, Ord a, NFData a
   blocksVision :: a -> Bool
   description :: a -> Text
   entityChar :: a -> EntityChar
+  entityCollision :: a -> Maybe Collision
+  entityCollision = const $ Just Stop
 
 data SomeEntity where
   SomeEntity :: forall a. (Entity a, Typeable a) => a -> SomeEntity