about summary refs log tree commit diff
path: root/src/Xanthous/Entities/Creature.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Xanthous/Entities/Creature.hs')
-rw-r--r--src/Xanthous/Entities/Creature.hs32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/Xanthous/Entities/Creature.hs b/src/Xanthous/Entities/Creature.hs
new file mode 100644
index 0000000000..983772090e
--- /dev/null
+++ b/src/Xanthous/Entities/Creature.hs
@@ -0,0 +1,32 @@
+{-# LANGUAGE RecordWildCards #-}
+{-# LANGUAGE TemplateHaskell #-}
+-- |
+
+module Xanthous.Entities.Creature where
+
+import Data.Word
+
+import Xanthous.Prelude
+import Xanthous.Entities.RawTypes hiding (Creature)
+import Xanthous.Entities (Draw(..))
+
+data Creature = Creature
+  { _creatureType :: CreatureType
+  , _hitpoints :: Word16
+  }
+  deriving stock (Eq, Show, Generic)
+makeLenses ''Creature
+
+instance Draw Creature where
+  draw = draw .view (creatureType . char)
+
+newWithType :: CreatureType -> Creature
+newWithType _creatureType =
+  let _hitpoints = _creatureType ^. maxHitpoints
+  in Creature {..}
+
+damage :: Word16 -> Creature -> Creature
+damage amount = hitpoints %~ \hp ->
+  if hp <= amount
+  then 0
+  else hp - amount