summaryrefslogtreecommitdiff
path: root/src/systems/moving.rs
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-02-23 22:12:21 +0100
committertroido <troido@protonmail.com>2020-02-23 22:12:21 +0100
commitf422238d7aaae0ff1b2d560a71a99b0a881ad338 (patch)
treec335cb8eee47d34953f7d4cd96c195958d223202 /src/systems/moving.rs
parent613952f918b8d72a3e397dc46be309b2320c6ad0 (diff)
players can get damage from traps
Diffstat (limited to 'src/systems/moving.rs')
-rw-r--r--src/systems/moving.rs22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/systems/moving.rs b/src/systems/moving.rs
index ccd9455..daa1eb4 100644
--- a/src/systems/moving.rs
+++ b/src/systems/moving.rs
@@ -18,7 +18,8 @@ use crate::{
Blocking,
Position,
Floor,
- Moved
+ Moved,
+ Entered
},
controls::{
Control
@@ -40,19 +41,13 @@ impl <'a> System<'a> for Move {
ReadStorage<'a, Blocking>,
Write<'a, Ground>,
ReadStorage<'a, Floor>,
- WriteStorage<'a, Moved>
+ WriteStorage<'a, Moved>,
+ WriteStorage<'a, Entered>
);
- fn run(&mut self, (entities, controllers, mut positions, size, blocking, mut ground, floor, mut moved): Self::SystemData) {
- {
- let mut ents = Vec::new();
- for (ent, _moved) in (&*entities, &moved).join() {
- ents.push(ent);
- }
- for ent in ents {
- moved.remove(ent);
- }
- }
+ fn run(&mut self, (entities, controllers, mut positions, size, blocking, mut ground, floor, mut moved, mut entered): Self::SystemData) {
+ moved.clear();
+ entered.clear();
for (ent, controller, mut pos) in (&entities, &controllers, &mut positions.restrict_mut()).join(){
match &controller.0 {
Control::Move(direction) => {
@@ -74,6 +69,9 @@ impl <'a> System<'a> for Move {
ground.cells.get_mut(&pos_mut.pos).unwrap().remove(&ent);
pos_mut.pos = newpos;
ground.cells.entry(newpos).or_insert_with(HashSet::new).insert(ent);
+ for ent in ground.cells.get(&newpos).unwrap() {
+ let _ = entered.insert(*ent, Entered);
+ }
}
}
_ => {}