| 52 | 52 |
}
|
| 53 | 53 |
}
|
| 54 | 54 |
|
| 55 | |
struct Intersection;
|
| 56 | |
|
| 57 | |
impl<'a> specs::System<'a> for Intersection {
|
| 58 | |
type SystemData = (
|
| 59 | |
specs::Entities<'a>,
|
| 60 | |
specs::ReadStorage<'a, Position>,
|
| 61 | |
specs::ReadStorage<'a, Velocity>,
|
| 62 | |
specs::ReadStorage<'a, Blocking>,
|
| 63 | |
specs::WriteStorage<'a, Collision>,
|
| 64 | |
);
|
| 65 | |
|
| 66 | |
fn run(&mut self, (entity, position, velocity, blocking, mut collision): Self::SystemData) {
|
| 67 | |
let mut spacemap = std::collections::HashMap::new();
|
| 68 | |
for (e, pos, _) in (&entity, &position, &blocking).join() {
|
| 69 | |
spacemap.insert(pos.to_grid(), e);
|
| 70 | |
}
|
| 71 | |
|
| 72 | |
for (pos, vel, col) in (&position, &velocity, &mut collision).join() {
|
| 73 | |
if let Some(_) = spacemap.get(&pos.moved(vel).to_grid()) {
|
| 74 | |
col.has_collision = true;
|
| 75 | |
}
|
| 76 | |
}
|
| 77 | |
}
|
| 78 | |
}
|
| 79 | |
|
| 80 | 55 |
struct Physics;
|
| 81 | 56 |
|
| 82 | 57 |
impl<'a> specs::System<'a> for Physics {
|
|
| 96 | 71 |
}
|
| 97 | 72 |
}
|
| 98 | 73 |
|
| 99 | |
struct ResetCollision;
|
| 100 | |
|
| 101 | |
impl<'a> specs::System<'a> for ResetCollision {
|
| 102 | |
type SystemData = specs::WriteStorage<'a, Collision>;
|
| 103 | |
|
| 104 | |
fn run(&mut self, mut collision: Self::SystemData) {
|
| 105 | |
for mut e in (&mut collision).join() {
|
| 106 | |
e.has_collision = false;
|
| 107 | |
}
|
| 108 | |
}
|
| 109 | |
}
|
| 110 | |
|
| 111 | 74 |
pub fn systems(game: &mut MyGame) {
|
| 112 | 75 |
Collide.run_now(&game.world);
|
| 113 | |
// Intersection.run_now(&game.world.res);
|
| 114 | 76 |
Physics.run_now(&game.world);
|
| 115 | |
// ResetCollision.run_now(&game.world);
|
| 116 | 77 |
}
|