Add particle effects for item usage

This commit is contained in:
Timothy Warren 2021-11-17 13:50:55 -05:00
parent 1dd5db42f7
commit 5bd85f5d86

View File

@ -1,5 +1,7 @@
use crate::components::*;
use crate::particle_system::ParticleBuilder;
use crate::{game_log::GameLog, Map};
use rltk::RGB;
use specs::prelude::*;
pub struct ItemCollectionSystem {}
@ -63,6 +65,8 @@ impl<'a> System<'a> for ItemUseSystem {
ReadStorage<'a, Equippable>,
WriteStorage<'a, Equipped>,
WriteStorage<'a, InBackpack>,
WriteExpect<'a, ParticleBuilder>,
ReadStorage<'a, Position>,
);
#[allow(clippy::cognitive_complexity)]
@ -84,6 +88,8 @@ impl<'a> System<'a> for ItemUseSystem {
equippable,
mut equipped,
mut backpack,
mut particle_builder,
positions,
) = data;
for (entity, useitem) in (&entities, &wants_use).join() {
@ -117,6 +123,15 @@ impl<'a> System<'a> for ItemUseSystem {
for mob in map.tile_content[idx].iter() {
targets.push(*mob);
}
particle_builder.request(
tile_idx.x,
tile_idx.y,
RGB::named(rltk::ORANGE),
RGB::named(rltk::BLACK),
rltk::to_cp437('░'),
200.0,
);
}
}
}
@ -189,6 +204,18 @@ impl<'a> System<'a> for ItemUseSystem {
}
used_item = true;
// Visually show healing
if let Some(pos) = positions.get(*target) {
particle_builder.request(
pos.x,
pos.y,
RGB::named(rltk::GREEN),
RGB::named(rltk::BLACK),
rltk::to_cp437('♥'),
200.0,
);
}
}
}
}
@ -210,6 +237,17 @@ impl<'a> System<'a> for ItemUseSystem {
"You use {} on {}, inflicting {} hp.",
item_name.name, mob_name.name, damage.damage
));
if let Some(pos) = positions.get(*mob) {
particle_builder.request(
pos.x,
pos.y,
RGB::named(rltk::RED),
RGB::named(rltk::BLACK),
rltk::to_cp437('‼'),
200.0,
);
}
}
used_item = true;
@ -236,6 +274,17 @@ impl<'a> System<'a> for ItemUseSystem {
"You use {} on {}, confusing them.",
item_name.name, mob_name.name
));
if let Some(pos) = positions.get(*mob) {
particle_builder.request(
pos.x,
pos.y,
RGB::named(rltk::MAGENTA),
RGB::named(rltk::BLACK),
rltk::to_cp437('?'),
200.0,
);
}
}
}
}