about summary refs log tree commit diff
path: root/src/Xanthous/Game
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2019-10-13T16·37-0400
committerGriffin Smith <root@gws.fyi>2019-10-13T16·37-0400
commit8a4220df830adb6f1616ca02dd06902474fd25df (patch)
treeb78e5eea207e77ca82759bf05a26a77ae3729c09 /src/Xanthous/Game
parent8d36fb4af2f938d96c8d6c22ccc575d0a98d0d38 (diff)
Implement speed and ticks
Gormlaks now move 1/8th the speed of the character, which means we can
run away from them - yay!

Unfortunately this also introduces a bug where they'll eventually get
stuck and not do anything, so I'll be tackling that next.
Diffstat (limited to 'src/Xanthous/Game')
-rw-r--r--src/Xanthous/Game/Draw.hs2
-rw-r--r--src/Xanthous/Game/State.hs15
2 files changed, 9 insertions, 8 deletions
diff --git a/src/Xanthous/Game/Draw.hs b/src/Xanthous/Game/Draw.hs
index 9f247d383325..24c177513ed1 100644
--- a/src/Xanthous/Game/Draw.hs
+++ b/src/Xanthous/Game/Draw.hs
@@ -9,7 +9,7 @@ import           Brick.Widgets.Border
 import           Brick.Widgets.Border.Style
 import           Brick.Widgets.Edit
 --------------------------------------------------------------------------------
-import           Xanthous.Data (Position(Position), x, y, loc)
+import           Xanthous.Data (Position'(..), type Position, x, y, loc)
 import           Xanthous.Data.EntityMap (EntityMap, atPosition)
 import qualified Xanthous.Data.EntityMap as EntityMap
 import           Xanthous.Entities
diff --git a/src/Xanthous/Game/State.hs b/src/Xanthous/Game/State.hs
index 302d20e1efdc..c437f640c091 100644
--- a/src/Xanthous/Game/State.hs
+++ b/src/Xanthous/Game/State.hs
@@ -57,7 +57,8 @@ import           Control.Monad.Random.Class
 import           Brick (EventM, Widget)
 --------------------------------------------------------------------------------
 import           Xanthous.Data.EntityMap (EntityMap, EntityID)
-import           Xanthous.Data (Positioned(..), Position(..), Neighbors)
+import           Xanthous.Data
+                 (Positioned(..), type Position, Neighbors, Ticks(..))
 import           Xanthous.Orphans ()
 import           Xanthous.Game.Prompt
 import           Xanthous.Resource
@@ -149,12 +150,12 @@ instance Draw a => Draw (Positioned a) where
 --------------------------------------------------------------------------------
 
 class Brain a where
-  step :: Positioned a -> AppM (Positioned a)
+  step :: Ticks -> Positioned a -> AppM (Positioned a)
 
 newtype Brainless a = Brainless a
 
 instance Brain (Brainless a) where
-  step = pure
+  step = const pure
 
 -- | Workaround for the inability to use DerivingVia on Brain due to the lack of
 -- higher-order roles (specifically AppT not having its last type argument have
@@ -162,8 +163,8 @@ instance Brain (Brainless a) where
 brainVia
   :: forall brain entity. (Coercible entity brain, Brain brain)
   => (entity -> brain) -- ^ constructor, ignored
-  -> (Positioned entity -> AppM (Positioned entity))
-brainVia _ = fmap coerce . step . coerce @_ @(Positioned brain)
+  -> (Ticks -> Positioned entity -> AppM (Positioned entity))
+brainVia _ ticks = fmap coerce . step ticks . coerce @_ @(Positioned brain)
 
 --------------------------------------------------------------------------------
 
@@ -186,8 +187,8 @@ instance Draw SomeEntity where
   drawWithNeighbors ns (SomeEntity ent) = drawWithNeighbors ns ent
 
 instance Brain SomeEntity where
-  step (Positioned pos (SomeEntity ent)) =
-    fmap SomeEntity <$> step (Positioned pos ent)
+  step ticks (Positioned pos (SomeEntity ent)) =
+    fmap SomeEntity <$> step ticks (Positioned pos ent)
 
 instance Entity SomeEntity where
   blocksVision (SomeEntity ent) = blocksVision ent