diff options
Diffstat (limited to 'src/systems/moving.rs')
| -rw-r--r-- | src/systems/moving.rs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/systems/moving.rs b/src/systems/moving.rs index 38588d5..2ea0650 100644 --- a/src/systems/moving.rs +++ b/src/systems/moving.rs @@ -11,7 +11,8 @@ use super::super::pos::Pos; use super::super::components::{ Controller, - Blocking + Blocking, + Position }; use super::super::controls::{ @@ -27,12 +28,12 @@ use super::super::resources::{ pub struct Move; impl <'a> System<'a> for Move { - type SystemData = (ReadStorage<'a, Controller>, WriteStorage<'a, Pos>, Read<'a, Size>, ReadStorage<'a, Blocking>, Read<'a, Floor>); - fn run(&mut self, (controller, mut pos, size, blocking, floor): Self::SystemData) { - for (controller, pos) in (&controller, &mut pos).join(){ + type SystemData = (ReadStorage<'a, Controller>, WriteStorage<'a, Position>, Read<'a, Size>, ReadStorage<'a, Blocking>, Read<'a, Floor>); + fn run(&mut self, (controllers, mut positions, size, blocking, floor): Self::SystemData) { + for (controller, mut pos) in (&controllers, &mut positions.restrict_mut()).join(){ match &controller.0 { Control::Move(direction) => { - let newpos = (*pos + direction.to_position()).clamp(Pos::new(0, 0), Pos::new(size.width - 1, size.height - 1)); + let newpos = (pos.get_unchecked().pos + direction.to_position()).clamp(Pos::new(0, 0), Pos::new(size.width - 1, size.height - 1)); let mut blocked = false; for ent in floor.cells.get(&newpos).unwrap_or(&Vec::new()) { if blocking.get(*ent).is_some(){ @@ -41,7 +42,9 @@ impl <'a> System<'a> for Move { } } if !blocked { - pos.clone_from(&newpos); + let mut pos_mut = pos.get_mut_unchecked(); + pos_mut.prev = Some(pos_mut.pos); + pos_mut.pos = newpos.clone(); } } _ => {} |
