diff options
| author | troido <troido@protonmail.com> | 2020-02-07 20:28:01 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-02-07 20:28:01 +0100 |
| commit | fa81f03509aa1300613c62e3a7b32db1183cd5c8 (patch) | |
| tree | 0258c669ea0a81b8e98a4b5fc14cc5139d49bedc /src/systems/moving.rs | |
| parent | 8be2749edf97b200281a2c67f97ed8835f5c6d88 (diff) | |
added floors
Diffstat (limited to 'src/systems/moving.rs')
| -rw-r--r-- | src/systems/moving.rs | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/systems/moving.rs b/src/systems/moving.rs index 2ea0650..28c3d3f 100644 --- a/src/systems/moving.rs +++ b/src/systems/moving.rs @@ -12,7 +12,8 @@ use super::super::pos::Pos; use super::super::components::{ Controller, Blocking, - Position + Position, + Floor }; use super::super::controls::{ @@ -21,27 +22,39 @@ use super::super::controls::{ use super::super::resources::{ Size, - Floor + Ground }; pub struct Move; impl <'a> System<'a> for Move { - 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) { + type SystemData = ( + ReadStorage<'a, Controller>, + WriteStorage<'a, Position>, + Read<'a, Size>, + ReadStorage<'a, Blocking>, + Read<'a, Ground>, + ReadStorage<'a, Floor>, + ); + + fn run(&mut self, (controllers, mut positions, size, blocking, ground, floor): Self::SystemData) { for (controller, mut pos) in (&controllers, &mut positions.restrict_mut()).join(){ match &controller.0 { Control::Move(direction) => { 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()) { + let mut on_floor = false; + for ent in ground.cells.get(&newpos).unwrap_or(&Vec::new()) { if blocking.get(*ent).is_some(){ blocked = true; break; } + if floor.get(*ent).is_some(){ + on_floor = true; + } } - if !blocked { + if !blocked && on_floor { let mut pos_mut = pos.get_mut_unchecked(); pos_mut.prev = Some(pos_mut.pos); pos_mut.pos = newpos.clone(); |
