Full potion system bby
This commit is contained in:
parent
433d5c00f3
commit
379df46c34
@ -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 {}
|
||||
@ -5,6 +5,7 @@ use super::{
|
||||
WantsToPickupItem,WantsToDropItem
|
||||
};
|
||||
|
||||
|
||||
pub struct ItemCollectionSystem {}
|
||||
|
||||
impl<'a> System<'a> for ItemCollectionSystem {
|
||||
|
||||
16
src/main.rs
16
src/main.rs
@ -75,12 +75,20 @@ impl GameState for State {
|
||||
let positions = self.ecs.read_storage::<Position>();
|
||||
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] {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -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<S: ToString>(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(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user