|
@@ -40,6 +40,10 @@ impl Map {
|
|
|
});
|
|
|
Map { tiles }
|
|
|
}
|
|
|
+
|
|
|
+ fn passable(&self, (x, y): (usize, usize)) -> bool {
|
|
|
+ Some(&TileType::Floor) == self.tiles.get(x, y)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#[derive(Component)]
|
|
@@ -96,11 +100,16 @@ system_impl! {
|
|
|
|
|
|
system! {
|
|
|
Move (
|
|
|
+ resource map: Map,
|
|
|
mut motion: Motion,
|
|
|
mut pos: Pos,
|
|
|
) {
|
|
|
- pos.x = (pos.x as i8 + motion.right) as usize;
|
|
|
- pos.y = (pos.y as i8 + motion.down) as usize;
|
|
|
+ let tgt_x = (pos.x as i8 + motion.right) as usize;
|
|
|
+ let tgt_y = (pos.y as i8 + motion.down) as usize;
|
|
|
+ if map.passable((tgt_x, tgt_y)) {
|
|
|
+ pos.x = tgt_x;
|
|
|
+ pos.y = tgt_y;
|
|
|
+ }
|
|
|
} finally {
|
|
|
motion.clear();
|
|
|
}
|