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.
This commit is contained in:
parent
ec39dc0a5b
commit
05da490185
11 changed files with 163 additions and 22 deletions
|
|
@ -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 <|)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue