Composing the Player

Learn how to compose a player and add it to the game world.

We'll cover the following

Rather than coding everything player-related into a single module, the ECS approach describes a player in terms of what components they use. The Player module from the previous lessons reveals some components that meet our needs:

  • A Player component indicates that the player is a Player. Components needn’t contain any fields. An empty component is sometimes called a tag; it serves to flag that property exists.

  • A Render component describing how the adventurer appears on the screen.

  • A Position component indicates where they are on the map. The Point structure from bracket-lib is ideal for this; it contains an x and y component, and it also provides several point-related math functions that will prove useful.

We’ll create a new file, src/ This creates a new module named components. We’ll use components throughout our game, so it makes sense to add it to our prelude in

Get hands-on with 1200+ tech skills courses.