command_system.cpp 922 B

123456789101112131415161718192021222324252627282930
  1. #include <component/input_listener_component.h>
  2. #include <component/velocity_component.h>
  3. #include <entt/entity/registry.hpp>
  4. #include <system/command_system.h>
  5. namespace testbed {
  6. void command_system(entt::registry &registry) {
  7. for([[maybe_unused]] auto [entt, input, vel]: registry.view<input_listener_component, velocity_component>().each()) {
  8. switch(input.command) {
  9. case input_listener_component::type::UP:
  10. vel.dy = -1.0f;
  11. break;
  12. case input_listener_component::type::DOWN:
  13. vel.dy = 1.0f;
  14. break;
  15. case input_listener_component::type::LEFT:
  16. vel.dx = -1.0f;
  17. break;
  18. case input_listener_component::type::RIGHT:
  19. vel.dx = 1.0f;
  20. break;
  21. case input_listener_component::type::NONE:
  22. vel.dx = vel.dy = 0.0f;
  23. break;
  24. }
  25. }
  26. }
  27. } // namespace testbed