//! Custom physics items //! //! TODO: Refactor in terms of Rapier2D, *or* implement colliders and remove it. //! //! Position, both translation and rotation, are tracked by the built-in //! Bevy [`Transform`] component. This module adds a (Linear) [`Velocity`] and //! [`AngularVelocity`] component to the mix. //! These two components are operated by simple integrator systems to //! accumulate translation and rotation from the velocities. //! //! The [`Wrapping`] component marks things that should wrap around the world //! boundaries. It's a kind of physical property of this world, so I'm putting //! it here. //! //! Collisions are also considered physics. After all, I got *a physics engine* //! to detect them for me (so that I don't have to write clipping code). use crate::{ WorldSize, messages, objects::{Asteroid, Bullet, Ship}, }; use bevy::prelude::*; use bevy_rapier2d::pipeline::CollisionEvent; #[derive(Clone, Component)] pub(crate) struct Velocity(pub(crate) bevy::math::Vec2); #[derive(Component)] pub(crate) struct AngularVelocity(pub(crate) f32); /// Marker for any entity that should wrap on screen edges #[derive(Component)] pub(crate) struct Wrapping; /// Integrate linear velocity and update the entity's transform. pub(crate) fn integrate_velocity(mut query: Query<(&mut Transform, &Velocity)>, time: Res