Complete chapter 2.8
This commit is contained in:
parent
e4be3b6855
commit
fee78663de
@ -13,6 +13,7 @@ pub struct Renderable {
|
|||||||
pub glyph: rltk::FontCharType,
|
pub glyph: rltk::FontCharType,
|
||||||
pub fg: RGB,
|
pub fg: RGB,
|
||||||
pub bg: RGB,
|
pub bg: RGB,
|
||||||
|
pub render_order: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component, Debug)]
|
#[derive(Component, Debug)]
|
||||||
|
@ -157,7 +157,9 @@ impl GameState for State {
|
|||||||
let renderables = self.ecs.read_storage::<Renderable>();
|
let renderables = self.ecs.read_storage::<Renderable>();
|
||||||
let map = self.ecs.fetch::<Map>();
|
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);
|
let idx = map.xy_idx(pos.x, pos.y);
|
||||||
|
|
||||||
if map.visible_tiles[idx] {
|
if map.visible_tiles[idx] {
|
||||||
|
@ -19,6 +19,7 @@ pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity {
|
|||||||
glyph: rltk::to_cp437('@'),
|
glyph: rltk::to_cp437('@'),
|
||||||
fg: RGB::named(rltk::YELLOW),
|
fg: RGB::named(rltk::YELLOW),
|
||||||
bg: RGB::named(rltk::BLACK),
|
bg: RGB::named(rltk::BLACK),
|
||||||
|
render_order: 0,
|
||||||
})
|
})
|
||||||
.with(Player {})
|
.with(Player {})
|
||||||
.with(Viewshed {
|
.with(Viewshed {
|
||||||
@ -68,6 +69,7 @@ fn monster<S: ToString>(ecs: &mut World, x: i32, y: i32, glyph: rltk::FontCharTy
|
|||||||
glyph,
|
glyph,
|
||||||
fg: RGB::named(rltk::RED),
|
fg: RGB::named(rltk::RED),
|
||||||
bg: RGB::named(rltk::BLACK),
|
bg: RGB::named(rltk::BLACK),
|
||||||
|
render_order: 1,
|
||||||
})
|
})
|
||||||
.with(Viewshed {
|
.with(Viewshed {
|
||||||
visible_tiles: Vec::new(),
|
visible_tiles: Vec::new(),
|
||||||
@ -152,6 +154,7 @@ fn health_potion(ecs: &mut World, x: i32, y: i32) {
|
|||||||
glyph: rltk::to_cp437('¡'),
|
glyph: rltk::to_cp437('¡'),
|
||||||
fg: RGB::named(rltk::MAGENTA),
|
fg: RGB::named(rltk::MAGENTA),
|
||||||
bg: RGB::named(rltk::BLACK),
|
bg: RGB::named(rltk::BLACK),
|
||||||
|
render_order: 2,
|
||||||
})
|
})
|
||||||
.with(Name {
|
.with(Name {
|
||||||
name: "Health Potion".to_string(),
|
name: "Health Potion".to_string(),
|
||||||
|
Loading…
Reference in New Issue
Block a user