From d8a83b77c257a16ea289143c0f36ed1f9feb3910 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Mon, 11 Aug 2025 22:47:48 -0500 Subject: [PATCH] Move ship & bullet to the objects module --- src/lib.rs | 5 ++--- src/objects.rs | 6 ++++++ src/ship.rs | 8 +------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 336e851..e554afc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,9 +13,8 @@ use crate::config::{ PLAYER_SHIP_COLOR, SHIP_ROTATION, SHIP_THRUST, SHIP_THRUSTER_COLOR_ACTIVE, SHIP_THRUSTER_COLOR_INACTIVE, WINDOW_SIZE, }; -use crate::objects::Asteroid; +use crate::objects::{Asteroid, Bullet, Ship}; use crate::physics::AngularVelocity; -use crate::ship::{Bullet, Ship}; use bevy::prelude::*; use bevy_inspector_egui::InspectorOptions; @@ -336,7 +335,7 @@ fn input_ship_shoot( // For now, spawn one for each press of the spacebar. if keyboard_input.just_pressed(KeyCode::Space) { commands.spawn(( - ship::Bullet, + Bullet, Collider::ball(0.2), Sensor, ActiveEvents::COLLISION_EVENTS, diff --git a/src/objects.rs b/src/objects.rs index b4ba8e6..77674eb 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -23,3 +23,9 @@ impl AsteroidSize { } } } + +#[derive(Component)] +pub struct Ship; + +#[derive(Component)] +pub struct Bullet; diff --git a/src/ship.rs b/src/ship.rs index 54d4abe..8c6f0c7 100644 --- a/src/ship.rs +++ b/src/ship.rs @@ -1,19 +1,13 @@ use crate::{ AngularVelocity, GameAssets, GameState, Lives, - objects::Asteroid, events::{BulletDestroy, ShipDestroy}, + objects::{Asteroid, Ship}, physics::{Velocity, Wrapping}, }; use bevy::prelude::*; use bevy_rapier2d::prelude::*; -#[derive(Component)] -pub struct Ship; - -#[derive(Component)] -pub struct Bullet; - pub fn spawn_player(mut commands: Commands, game_assets: Res) { commands .spawn((