diff options
author | Griffin Smith <root@gws.fyi> | 2019-10-16T16·10-0400 |
---|---|---|
committer | Griffin Smith <root@gws.fyi> | 2019-10-16T16·10-0400 |
commit | 87fedcb6c9bc251a5a23a632ccf985b674b84bc7 (patch) | |
tree | 739fab972e9ae8af9849f3e8f65dad0f5bf13c7d /src/Xanthous/Game/State.hs | |
parent | 4882350f5d7e54a6ae5c8760f2510273dae19c60 (diff) |
Add draw priority
Rather than blindly taking one entity from the list when we have multiple entities on the same tile, add a `drawPriority` method to the Draw typeclass which allows individual entities to request to be drawn on top - this avoids the "noodles floating over your head" bug we saw before.
Diffstat (limited to 'src/Xanthous/Game/State.hs')
-rw-r--r-- | src/Xanthous/Game/State.hs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/Xanthous/Game/State.hs b/src/Xanthous/Game/State.hs index c437f640c091..e3df5c60def2 100644 --- a/src/Xanthous/Game/State.hs +++ b/src/Xanthous/Game/State.hs @@ -58,7 +58,6 @@ import Brick (EventM, Widget) -------------------------------------------------------------------------------- import Xanthous.Data.EntityMap (EntityMap, EntityID) import Xanthous.Data - (Positioned(..), type Position, Neighbors, Ticks(..)) import Xanthous.Orphans () import Xanthous.Game.Prompt import Xanthous.Resource @@ -143,6 +142,10 @@ class Draw a where draw :: a -> Widget n draw = drawWithNeighbors $ pure mempty + -- | higher priority gets drawn on top + drawPriority :: a -> Word + drawPriority = const minBound + instance Draw a => Draw (Positioned a) where drawWithNeighbors ns (Positioned _ a) = drawWithNeighbors ns a draw (Positioned _ a) = draw a @@ -185,6 +188,7 @@ instance Eq SomeEntity where instance Draw SomeEntity where drawWithNeighbors ns (SomeEntity ent) = drawWithNeighbors ns ent + drawPriority (SomeEntity ent) = drawPriority ent instance Brain SomeEntity where step ticks (Positioned pos (SomeEntity ent)) = |