top | item 25933910

(no title)

thepratt | 5 years ago

If we step into the haskell land of monads having explicit functionality kept in individual monads with their own instances would be one way to segment this type of stuff. Something vaguely written as below would let you run actions where anyone can move or is an enemy, and default implementations can be provided as well.

    data Demon = { ... }

    data Action
      = Dead
      | KnockedBack
      | Polymorphed

    class Character a where
      health :: Int

    class (Character a) => Movement a where
      speed :: Int

    class (Character a) => Enemy a where
      kill :: a -> Action
      damage :: a -> Action

    instance Character Demon where
      health = 30

    instance Movement Demon where
      speed = 5

    instance Enemy Demon where
      kill _ = _
      damage _ = _

https://soupi.github.io/rfc/pfgames/ is a talk going through an experience building a game in a pure fp way with Haskell and how they modelled certain aspects of game dev. Most of the code examples are when you press down in the slides.

discuss

order

No comments yet.