Managing Inventory
Learn how to manage inventory for the player.
We'll cover the following
Items don’t always sit passively on the map, hoping someone will walk onto them. Unless we’re making a PacMan-style game, it also doesn’t make sense to have items activated when the player walks into them. Instead, let’s allow players to pick up items and carry them in their inventory until they’re needed. This adds strategy to the game, letting players decide when they want to use their precious items.
Items are entities, and they exist on the map because they have a Point
component indicating their location. The entity rendering system query requires a Point
to draw an item or display its tooltip. We can take advantage of the render system’s query structure by removing the Point
component from an item when it’s picked up. The item no longer has a location on the map.
Picking an item up requires removing the Point
component and adding a Carried
component, with the stored Entity
pointing at the entity carrying the item.
Add a new component in component.rs
, representing that another entity is holding an item:
Get hands-on with 1200+ tech skills courses.