about summary refs log tree commit diff
path: root/src/Xanthous/Entities/Creature.hs
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2019-09-02T18·45-0400
committerGriffin Smith <root@gws.fyi>2019-09-02T18·45-0400
commit73a52e531d940858f0ac334d8b2ccda479ea7b5e (patch)
treefc7a953ddcb69691e2f734fa69f4585aff553e17 /src/Xanthous/Entities/Creature.hs
parent4d270712aecf1b61249086718852b96968de2bd8 (diff)
Put a test gormlak on the screen
Implement a concrete "Creature" entity, and place one on the screen at
the game startup for testing.

This revealed a bug with drawing when getting the maximum entity
position, but that appears to be fixed now (yay)
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 000000000000..983772090ee2
--- /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