about summary refs log tree commit diff
path: root/src/Xanthous/Entities
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
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')
-rw-r--r--src/Xanthous/Entities/Creature.hs32
-rw-r--r--src/Xanthous/Entities/Raws/gormlak.yaml2
2 files changed, 33 insertions, 1 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
diff --git a/src/Xanthous/Entities/Raws/gormlak.yaml b/src/Xanthous/Entities/Raws/gormlak.yaml
index fc3215f2f451..2441e7e7822e 100644
--- a/src/Xanthous/Entities/Raws/gormlak.yaml
+++ b/src/Xanthous/Entities/Raws/gormlak.yaml
@@ -6,7 +6,7 @@ Creature:
   char:
     char: g
     style:
-      color: red
+      foreground: red
   maxHitpoints: 5
   speed: 120
   friendly: false