From 05da490185e970b2cfdf6c61f69932fa373993f6 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sun, 29 Sep 2019 10:54:52 -0400 Subject: Gormlaks attack back When gormlaks see the character, they step towards them and attack dealing 1 damage when adjacent. Characters have hitpoints now, displayed at the bottom of the game screen, and when the game is over they die. --- src/Xanthous/Entities/Character.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/Xanthous/Entities') diff --git a/src/Xanthous/Entities/Character.hs b/src/Xanthous/Entities/Character.hs index 1c7d1bbe82a6..0bb5867ee5e1 100644 --- a/src/Xanthous/Entities/Character.hs +++ b/src/Xanthous/Entities/Character.hs @@ -4,8 +4,10 @@ module Xanthous.Entities.Character , characterName , inventory , characterDamage + , characterHitpoints , mkCharacter , pickUpItem + , isDead ) where -------------------------------------------------------------------------------- import Xanthous.Prelude @@ -24,6 +26,7 @@ data Character = Character { _inventory :: !(Vector Item) , _characterName :: !(Maybe Text) , _characterDamage :: !Word + , _characterHitpoints :: !Word } deriving stock (Show, Eq, Generic) deriving anyclass (CoArbitrary, Function) @@ -51,13 +54,20 @@ instance Entity Character where instance Arbitrary Character where arbitrary = genericArbitrary +initialHitpoints :: Word +initialHitpoints = 10 + mkCharacter :: Character mkCharacter = Character { _inventory = mempty , _characterName = Nothing , _characterDamage = 1 + , _characterHitpoints = initialHitpoints } +isDead :: Character -> Bool +isDead = (== 0) . view characterHitpoints + pickUpItem :: Item -> Character -> Character pickUpItem item = inventory %~ (item <|) -- cgit 1.4.1