Tracking Game Level
Explore how to track the player's current dungeon level in a Rust game. Learn to update the Player component, handle level transitions, clear and generate new map entities, and spawn appropriate game events. This lesson equips you to manage game progression and enhance player engagement.
Transitioning between levels is a great start, but it’s helpful to know what level the player is on. We need this information to determine if we should spawn the Amulet of Yala or an exit. We’ll use the current dungeon level later to present the player with their progress through the dungeon, providing a sense of progress. The current level will also be used in the next chapter to spawn increasingly difficult monsters and better loot as the adventurer progresses.
Let’s start by adding the current dungeon level to the Player component. The adventurer is the only entity advancing through the dungeon, so the Player component is a good place to store the current map level. Add a map_level field to the Player component in components.rs:
We have to include every field when we create a structure. Update the spawn_player in spawner.rs to start the adventurer on level zero:
With the current level safely stored in the Player component, we’re ready to add transitions between levels when the adventurer reaches an exit.
Level transition state
Finishing the level is a major event, similar to a victory or defeat. Such an event requires that the main game loop do something drastic, outside of the ECS systems. Add a new condition ...