Finding the Amulet of Yala
Hands-on Rust — by Herbert Wolverson (73 / 120)
👈 Implementing a Game Over Screen | TOC | Wrap-Up 👉
You win the game when you collect the Amulet of Yala. Yala is an acronym for “yet another lost amulet,” a gentle poke at Nethack’s — and its many derivatives — plot.
Spawning the Amulet
You’ll use two new tag components to denote the amulet:
WinningAndLosing/winning/src/components.rs
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Item;
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct AmuletOfYala;
The Item component denotes that an entity is an item. It doesn’t move or have health, but it should still appear on the map. You’ll add further support for items in Chapter 13, Inventory and Power-Ups. The AmuletOfYala tag indicates that the tagged item is the item that wins the game.
The amulet also shares components with other entities. It needs a name, a rendered graphic, and a map position. Open spawner.rs and add a function to create the amulet:
WinningAndLosing/winning/src/spawner.rs
pub fn spawn_amulet_of_yala(ecs : &mut World, pos : Point) {
ecs.push(
(Item, AmuletOfYala,
pos,
Render{
color: ColorPair::new(WHITE, BLACK),
glyph : to_cp437('|')
},
…