Activate the next level
This commit is contained in:
parent
f4e718ad7f
commit
5c6f7c76ab
51
src/main.rs
51
src/main.rs
@ -139,7 +139,56 @@ impl State {
|
||||
}
|
||||
}
|
||||
|
||||
fn advance_level(&mut self) {}
|
||||
fn advance_level(&mut self) {
|
||||
let player_entity = *<Entity>::query()
|
||||
.filter(component::<Player>())
|
||||
.iter(&self.ecs)
|
||||
.next()
|
||||
.unwrap();
|
||||
|
||||
use std::collections::HashSet;
|
||||
let mut entities_to_keep = HashSet::new();
|
||||
entities_to_keep.insert(player_entity);
|
||||
|
||||
<(Entity, &Carried)>::query()
|
||||
.iter(&self.ecs)
|
||||
.filter(|(_e, carry)| carry.0 == player_entity)
|
||||
.map(|(e, _carry)| *e)
|
||||
.for_each(|e| {
|
||||
entities_to_keep.insert(e);
|
||||
});
|
||||
|
||||
let mut cb = CommandBuffer::new(&self.ecs);
|
||||
for e in Entity::query().iter(&self.ecs) {
|
||||
if !entities_to_keep.contains(e) {
|
||||
cb.remove(*e);
|
||||
}
|
||||
}
|
||||
cb.flush(&mut self.ecs);
|
||||
|
||||
<&mut FieldOfView>::query()
|
||||
.iter_mut(&mut self.ecs)
|
||||
.for_each(|fov| fov.is_dirty = true);
|
||||
|
||||
let mut rng = RandomNumberGenerator::new();
|
||||
let mut map_builder = MapBuilder::new(&mut rng);
|
||||
let mut map_level = 0;
|
||||
<(&mut Player, &mut Point)>::query()
|
||||
.iter_mut(&mut self.ecs)
|
||||
.for_each(|(player, pos)| {
|
||||
player.map_level += 1;
|
||||
map_level = player.map_level;
|
||||
pos.x = map_builder.player_start.x;
|
||||
pos.y = map_builder.player_start.y;
|
||||
});
|
||||
|
||||
if map_level == 2 {
|
||||
spawn_amulet_of_yala(&mut self.ecs, map_builder.amulet_start);
|
||||
} else {
|
||||
let exit_idx = map_builder.map.point2d_to_index(map_builder.amulet_start);
|
||||
map_builder.map.tiles[exit_idx] = TileType::Exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GameState for State {
|
||||
|
Loading…
x
Reference in New Issue
Block a user