about summary refs log tree commit diff
path: root/src/Xanthous/Entities/Creature.hs
blob: 5af24a8cd3eb98da3447d2adb3960a16831c3778 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{-# 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(..), Entity(..))

data Creature = Creature
  { _creatureType :: CreatureType
  , _hitpoints :: Word16
  }
  deriving stock (Eq, Show, Generic)
makeLenses ''Creature

instance Entity Creature where
  blocksVision _ = False

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