June 2021
Beginner
344 pages
8h 9m
English
Adding hit points to entities requires a new component type. This is a common theme in ECS design patterns—whenever you want to represent something new about entities, you add a component type. Open src/components.rs and add another component type to the file:
| | #[derive(Clone, Copy, Debug, PartialEq)] |
| | pub struct Health { |
| | pub current: i32, |
| | pub max: i32 |
| | } |
This component stores both the current and max (maximum) hit points of an entity. It’s important to store the maximum hit points because health bars are scaled to show how much health an entity is missing. When an entity is healed, you can use the maximum hit points to ensure it’s not healed above its maximum. ...
Read now
Unlock full access