|
- use glc::vector::Vector4f;
- use space_crush_common::{
- components::{Position, Ship, ShipObstacle, Velocity},
- continue_if_none,
- };
- use specs::{prelude::*, ReadStorage, System, World, WriteExpect};
-
- use crate::resources::Geometry;
-
- #[derive(Default)]
- pub struct Ships;
-
- #[derive(SystemData)]
- pub struct ShipsData<'a> {
- geometry: WriteExpect<'a, Geometry>,
- positions: ReadStorage<'a, Position>,
- velocities: ReadStorage<'a, Velocity>,
- ships: ReadStorage<'a, Ship>,
- }
-
- impl<'a> System<'a> for Ships {
- type SystemData = ShipsData<'a>;
-
- fn run(&mut self, data: Self::SystemData) {
- let ShipsData {
- mut geometry,
- positions,
- velocities,
- ships,
- } = data;
-
- gl::enable(gl::BLEND);
- gl::blend_func(gl::SRC_ALPHA, gl::ONE);
-
- for (position, velocity, ship) in (&positions, &velocities, &ships).join() {
- let ship_pos = position.pos;
-
- geometry.render_lines(
- Vector4f::new(0.0, 0.0, 1.0, 0.2),
- &[ship_pos, ship_pos + velocity.dir * velocity.speed],
- );
- geometry.render_lines(
- Vector4f::new(1.0, 0.0, 0.0, 0.2),
- &[ship_pos, ship_pos + ship.target_dir * 100.0],
- );
- geometry.render_lines(
- Vector4f::new(1.0, 1.0, 1.0, 0.2),
- &[ship_pos, ship.target_pos],
- );
-
- if let ShipObstacle::Known(obstacle) = ship.obstacle {
- let obstacle_pos = continue_if_none!(positions.get(obstacle)).pos;
-
- geometry.render_lines(Vector4f::new(0.0, 1.0, 0.0, 0.2), &[ship_pos, obstacle_pos]);
- }
- }
-
- gl::disable(gl::BLEND);
- }
- }
|