From 73a52e531d940858f0ac334d8b2ccda479ea7b5e Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Mon, 2 Sep 2019 14:45:36 -0400 Subject: 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) --- src/Xanthous/Entities/Creature.hs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/Xanthous/Entities/Creature.hs (limited to 'src/Xanthous/Entities/Creature.hs') 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 -- cgit 1.4.1