diff --git a/src/components.rs b/src/components.rs index bcc7db9..10ec230 100644 --- a/src/components.rs +++ b/src/components.rs @@ -13,6 +13,7 @@ pub struct Renderable { pub glyph: rltk::FontCharType, pub fg: RGB, pub bg: RGB, + pub render_order : i32, } #[derive(Component, Debug)] @@ -104,3 +105,6 @@ pub struct WantsToDrinkPotion { pub struct WantsToDropItem { pub item : Entity } + +#[derive(Component, Debug)] +pub struct Consumable {} \ No newline at end of file diff --git a/src/inventory_system.rs b/src/inventory_system.rs index beab1f0..2ada99f 100644 --- a/src/inventory_system.rs +++ b/src/inventory_system.rs @@ -5,6 +5,7 @@ use super::{ WantsToPickupItem,WantsToDropItem }; + pub struct ItemCollectionSystem {} impl<'a> System<'a> for ItemCollectionSystem { diff --git a/src/main.rs b/src/main.rs index ea3f980..5e6a2d4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -75,12 +75,20 @@ impl GameState for State { let positions = self.ecs.read_storage::(); let renderables = self.ecs.read_storage::(); let map = self.ecs.fetch::(); - for (pos, render) in (&positions, &renderables).join() { + + let mut data = (&positions, &renderables).join().collect::>(); + 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] { - ctx.set(pos.x, pos.y, render.fg, render.bg, render.glyph) - } + if map.visible_tiles[idx] { ctx.set(pos.x, pos.y, render.fg, render.bg, render.glyph) } } + // for (pos, render) in (&positions, &renderables).join() { + // let idx = map.xy_idx(pos.x, pos.y); + // if map.visible_tiles[idx] { + // ctx.set(pos.x, pos.y, render.fg, render.bg, render.glyph) + // } + // } gui::draw_ui(&self.ecs, ctx); } diff --git a/src/spawner.rs b/src/spawner.rs index 931ac54..c94092a 100644 --- a/src/spawner.rs +++ b/src/spawner.rs @@ -21,6 +21,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 { @@ -66,6 +67,7 @@ fn monster(ecs: &mut World, x: i32, y: i32, glyph: rltk::FontCharTy glyph: glyph, fg: RGB::named(rltk::RED), bg: RGB::named(rltk::BLACK), + render_order: 1 }) .with(Viewshed { visible_tiles: Vec::new(), @@ -142,6 +144,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(),