Track entity collision in the Entity class
Rather than having a single function in the Game.Lenses module for determining what collision type if any an entity has, track it in the Entity typeclass itself. This is both more extensible and a better separation of concerns and gets rid of one of the two needs for a circular import. Yay! As part of this, I realized nothing was being done to prevent doors from being placed on tiles that already had walls (since now that was properly causing a collision!) so I've fixed that as well.
This commit is contained in:
parent
1b88921bc3
commit
84f32efad4
9 changed files with 37 additions and 35 deletions
|
|
@ -91,6 +91,8 @@ instance Entity Door where
|
|||
description door | door ^. open = "an open door"
|
||||
| otherwise = "a closed door"
|
||||
entityChar _ = "d"
|
||||
entityCollision door | door ^. open = Nothing
|
||||
| otherwise = Just Stop
|
||||
|
||||
-- | A closed, unlocked door
|
||||
unlockedDoor :: Door
|
||||
|
|
@ -113,8 +115,10 @@ newtype GroundMessage = GroundMessage Text
|
|||
deriving Draw
|
||||
via DrawStyledCharacter ('Just 'Yellow) 'Nothing "≈"
|
||||
GroundMessage
|
||||
deriving Entity
|
||||
via DeriveEntity 'False "a message on the ground. Press r. to read it."
|
||||
"≈"
|
||||
GroundMessage
|
||||
instance Brain GroundMessage where step = brainVia Brainless
|
||||
|
||||
instance Entity GroundMessage where
|
||||
blocksVision = const False
|
||||
description = const "a message on the ground. Press r. to read it."
|
||||
entityChar = const "≈"
|
||||
entityCollision = const Nothing
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue