physics.rs 577 B

123456789101112131415161718192021222324252627
  1. use crate::components::{Velocity, Position};
  2. use crate::game::MyGame;
  3. use specs::RunNow;
  4. struct Physics;
  5. impl <'a> specs::System<'a> for Physics {
  6. type SystemData = (
  7. specs::ReadStorage<'a, Velocity>,
  8. specs::WriteStorage<'a, Position>,
  9. );
  10. fn run(&mut self, (velocity, mut position): Self::SystemData) {
  11. use specs::Join;
  12. for (vel, pos) in (&velocity, &mut position).join() {
  13. pos.x += vel.dx;
  14. pos.y += vel.dy;
  15. }
  16. }
  17. }
  18. pub fn systems(game: &mut MyGame) {
  19. Physics.run_now(&game.world.res);
  20. }