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.

47 lines
1.3 KiB

  1. use glc::vector::Vector4f;
  2. use space_crush_common::components::{Position, Ship, Velocity};
  3. use specs::{prelude::*, ReadStorage, System, World, WriteExpect};
  4. use crate::resources::Geometry;
  5. #[derive(Default)]
  6. pub struct Ships;
  7. #[derive(SystemData)]
  8. pub struct ShipsData<'a> {
  9. geometry: WriteExpect<'a, Geometry>,
  10. position: ReadStorage<'a, Position>,
  11. velocity: ReadStorage<'a, Velocity>,
  12. ship: ReadStorage<'a, Ship>,
  13. }
  14. impl<'a> System<'a> for Ships {
  15. type SystemData = ShipsData<'a>;
  16. fn run(&mut self, data: Self::SystemData) {
  17. let ShipsData {
  18. mut geometry,
  19. position,
  20. velocity,
  21. ship,
  22. } = data;
  23. gl::enable(gl::BLEND);
  24. gl::blend_func(gl::SRC_ALPHA, gl::ONE);
  25. for (p, v, s) in (&position, &velocity, &ship).join() {
  26. geometry.render_lines(
  27. Vector4f::new(0.0, 0.0, 1.0, 0.2),
  28. &[p.pos, p.pos + v.dir * v.speed],
  29. );
  30. geometry.render_lines(
  31. Vector4f::new(1.0, 0.0, 0.0, 0.2),
  32. &[p.pos, p.pos + s.target_dir * 100.0],
  33. );
  34. geometry.render_lines(Vector4f::new(1.0, 1.0, 1.0, 0.2), &[p.pos, s.target_pos]);
  35. }
  36. gl::disable(gl::BLEND);
  37. }
  38. }