Composing the Player
Rather than coding everything player related into a single module, the ECS approach is to describe a player in terms of what components they use. Looking at the Player module from the previous chapter, you can deduce some components that meet your needs:
-
A Player component indicating that the player is a Player. Components don’t have to contain any fields. An empty component is sometimes called a “tag”—it serves to flag that a property exists.
-
A Render component describing how the player appears on the screen.
-
A Position component indicating where the entity is on the map. The Point structure from bracket-lib is ideal for this; it contains an x and a y component, and it also provides several point-related math functions ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access