You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334
  1. use specs::prelude::*;
  2. use crate::components::*;
  3. use super::MovementCommand;
  4. const PLAYER_MOVEMENT_SPEED: i32 = 20;
  5. pub struct Keyboard;
  6. impl<'a> System<'a> for Keyboard {
  7. type SystemData = (
  8. ReadExpect<'a, Option<MovementCommand>>,
  9. ReadStorage<'a, KeyboardControlled>,
  10. WriteStorage<'a, Velocity>,
  11. );
  12. fn run(&mut self, mut data: Self::SystemData) {
  13. let movement_command = match &*data.0 {
  14. Some(movement_command) => movement_command,
  15. None => return,
  16. };
  17. for (_, vel) in (&data.1, &mut data.2).join() {
  18. match movement_command {
  19. &MovementCommand::Move(direction) => {
  20. vel.speed = PLAYER_MOVEMENT_SPEED;
  21. vel.direction = direction;
  22. },
  23. MovementCommand::Stop => vel.speed = 0,
  24. }
  25. }
  26. }
  27. }