Composing Entities

Hands-on Rust — by Herbert Wolverson (52 / 120)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Understanding Terminology | TOC | Installing and Using Legion 👉

Entities are composed of combined components that describe them. Whenever you add a component type (and systems that use it), you’re offering that functionality to any entity. You can use it for everything, or you may restrict it to a small number of special creatures — but every time you add a component, you are giving yourself options. You can now add that functionality to anything you like. Some combinations may not make sense, but with a little thought, you can quickly add realism and fun to your game.

One advantage of using component composition is that it becomes easier to translate from an English description of a monster to a set of components. You might write that a goblin is “a small, green, angry humanoid. They roam the dungeon, preying upon unsuspecting adventurers. They prefer to attack from a distance, and are cowardly and quite weak.” Reading a description like this gives you some valuable clues as to what components your goblin may require:

  • It’s a small humanoid requiring the same Render components as other humanoids.
  • It has a Position on the map.
  • It’s angry, so you need an AI component denoting that it attacks on sight.
  • It prefers ranged attacks, so your AI components should indicate that.
  • It is cowardly, so maybe that needs a component…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.