Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

fleets.rs 1.6 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. use glc::vector::{Angle, Vector2f, Vector4f};
  2. use space_crush_common::{
  3. components::{Fleet, Position},
  4. constants::SHIP_ORBIT_DISTANCE_MAX,
  5. };
  6. use specs::{prelude::*, ReadStorage, System, World, WriteExpect};
  7. use crate::resources::Geometry;
  8. #[derive(Default)]
  9. pub struct Fleets;
  10. #[derive(SystemData)]
  11. pub struct FleetData<'a> {
  12. geometry: WriteExpect<'a, Geometry>,
  13. position: ReadStorage<'a, Position>,
  14. fleet: ReadStorage<'a, Fleet>,
  15. }
  16. impl<'a> System<'a> for Fleets {
  17. type SystemData = FleetData<'a>;
  18. fn run(&mut self, data: Self::SystemData) {
  19. let FleetData {
  20. mut geometry,
  21. position,
  22. fleet,
  23. } = data;
  24. gl::enable(gl::BLEND);
  25. gl::blend_func(gl::SRC_ALPHA, gl::ONE);
  26. for (p, f) in (&position, &fleet).join() {
  27. geometry.render_lines(
  28. Vector4f::new(0.5, 0.5, 0.5, 0.2),
  29. &create_circle(p.pos, f.orbit_min),
  30. );
  31. geometry.render_lines(
  32. Vector4f::new(0.5, 0.5, 0.5, 0.2),
  33. &create_circle(p.pos, f.orbit_max),
  34. );
  35. geometry.render_lines(
  36. Vector4f::new(0.5, 0.5, 0.5, 0.1),
  37. &create_circle(p.pos, SHIP_ORBIT_DISTANCE_MAX * f.orbit_max),
  38. );
  39. }
  40. gl::disable(gl::BLEND);
  41. }
  42. }
  43. fn create_circle(p: Vector2f, r: f32) -> Vec<Vector2f> {
  44. let mut points = Vec::new();
  45. for i in 0..=180 {
  46. points.push(Vector2f::new(
  47. p.x + r * Angle::Deg(i as f32 * 2.0).cos(),
  48. p.y + r * Angle::Deg(i as f32 * 2.0).sin(),
  49. ));
  50. }
  51. points
  52. }