June 2021
Beginner
344 pages
8h 9m
English
Monsters have a lot in common with the player. They have a position and render information. They aren’t keyboard controlled and they shouldn’t have a Player tag. Instead, monsters need an Enemy tag component. Open components.rs, and add an Enemy tag:
| | #[derive(Clone, Copy, Debug, PartialEq)] |
| | pub struct Enemy; |
An empty structure is all that’s required for a tag class. You still need a way to spawn monsters. Open spawner.rs, and add a spawn_monster function. It’s very similar to the player spawning code:
| | pub fn spawn_monster( |
| | ecs: &mut World, |
| | rng: &mut RandomNumberGenerator, |
| | pos : Point |
| | ) { |
Read now
Unlock full access