Complete chapter 2.8

This commit is contained in:
Timothy Warren 2021-11-04 09:54:38 -04:00
parent e4be3b6855
commit fee78663de
3 changed files with 7 additions and 1 deletions

View File

@ -13,6 +13,7 @@ pub struct Renderable {
pub glyph: rltk::FontCharType,
pub fg: RGB,
pub bg: RGB,
pub render_order: i32,
}
#[derive(Component, Debug)]

View File

@ -157,7 +157,9 @@ impl GameState for State {
let renderables = self.ecs.read_storage::<Renderable>();
let map = self.ecs.fetch::<Map>();
for (pos, render) in (&positions, &renderables).join() {
let mut data = (&positions, &renderables).join().collect::<Vec<_>>();
data.sort_by(|&a, &b| b.1.render_order.cmp(&a.1.render_order));
for (pos, render) in data.iter() {
let idx = map.xy_idx(pos.x, pos.y);
if map.visible_tiles[idx] {

View File

@ -19,6 +19,7 @@ pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity {
glyph: rltk::to_cp437('@'),
fg: RGB::named(rltk::YELLOW),
bg: RGB::named(rltk::BLACK),
render_order: 0,
})
.with(Player {})
.with(Viewshed {
@ -68,6 +69,7 @@ fn monster<S: ToString>(ecs: &mut World, x: i32, y: i32, glyph: rltk::FontCharTy
glyph,
fg: RGB::named(rltk::RED),
bg: RGB::named(rltk::BLACK),
render_order: 1,
})
.with(Viewshed {
visible_tiles: Vec::new(),
@ -152,6 +154,7 @@ fn health_potion(ecs: &mut World, x: i32, y: i32) {
glyph: rltk::to_cp437('¡'),
fg: RGB::named(rltk::MAGENTA),
bg: RGB::named(rltk::BLACK),
render_order: 2,
})
.with(Name {
name: "Health Potion".to_string(),