diff options
Diffstat (limited to 'src/Xanthous/Entities')
-rw-r--r-- | src/Xanthous/Entities/Creature.hs | 32 | ||||
-rw-r--r-- | src/Xanthous/Entities/Raws/gormlak.yaml | 2 |
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 |