fight monsters, collect artifacts

This commit is contained in:
2023-12-17 16:14:17 +01:00
parent 643f3b76f9
commit 8b21e179c2
5 changed files with 105 additions and 52 deletions

View File

@@ -45,8 +45,8 @@ impl Level {
discovered: [[false; LEVEL_HEIGHT]; LEVEL_WIDTH],
monsters: Vec::with_capacity(10),
artifacts: Vec::with_capacity(10),
start: (0,0),
end: (0,0),
start: (0, 0),
end: (0, 0),
}
}
pub fn get_element(&mut self, x: i16, y: i16) -> (Option<StructureElement>, Option<&mut Monster>, Option<&mut Box<(dyn Artifact + 'static)>>) {
@@ -172,6 +172,21 @@ impl Level {
}
}
}
pub fn update(&mut self) {
for (index, a) in &mut self.artifacts.iter().enumerate() {
if a.was_collected() {
self.artifacts.remove(index);
break;
}
}
for (index, m) in &mut self.monsters.iter().enumerate() {
if m.is_dead() {
self.monsters.remove(index);
break;
}
}
}
}
#[test]