Extract entities

This commit is contained in:
Michael Bradley 2025-05-18 23:57:43 -04:00
parent b7780b8862
commit cef21f4a00
Signed by: MichaelBradley
SSH key fingerprint: SHA256:BKO2eI2LPsCbQS3n3i5SdwZTAIV3F1lHezR07qP+Ob0
4 changed files with 24 additions and 20 deletions

1
src/game/mod.rs Normal file
View file

@ -0,0 +1 @@
pub mod objects;

18
src/game/objects.rs Normal file
View file

@ -0,0 +1,18 @@
use avian2d::prelude::*;
use bevy::prelude::*;
#[derive(Component, Default)]
#[require(Collider, Mesh2d, MeshMaterial2d<ColorMaterial>, Restitution = Restitution::new(1.0), RigidBody, TransformInterpolation, Transform)]
struct GameObject;
#[derive(Component, Default)]
#[require(GameObject, RigidBody = RigidBody::Dynamic)]
pub struct Ball;
#[derive(Component, Default)]
#[require(Ball)]
pub struct Player;
#[derive(Component, Default)]
#[require(GameObject, RigidBody = RigidBody::Static)]
pub struct Wall;

View file

@ -13,9 +13,10 @@ use bevy_rand::prelude::{EntropyPlugin, GlobalEntropy, WyRand};
use rand::Rng;
use wyrand::WyRand as LocalRng;
pub mod utils;
use utils::AppSettings;
mod game;
use game::objects::{Ball, Player, Wall};
mod utils;
pub use utils::AppSettings;
const BALL_COUNT: u8 = 32;
const BALL_SIZES: Range<f32> = 10.0..25.0;
@ -72,18 +73,6 @@ fn setup_ui(mut commands: Commands) {
commands.spawn((Name::new("Camera"), Camera2d, IsDefaultUiCamera));
}
#[derive(Component, Default)]
#[require(Collider, Mesh2d, MeshMaterial2d<ColorMaterial>, Restitution = Restitution::new(1.0), RigidBody, TransformInterpolation, Transform)]
struct GameObject;
#[derive(Component, Default)]
#[require(GameObject, RigidBody = RigidBody::Dynamic)]
struct Ball;
#[derive(Component, Default)]
#[require(Ball)]
struct Player;
fn setup_player(
mut commands: Commands,
mut materials: ResMut<Assets<ColorMaterial>>,
@ -126,10 +115,6 @@ fn setup_balls(
}
}
#[derive(Component, Default)]
#[require(GameObject, RigidBody = RigidBody::Static)]
struct Wall;
fn setup_walls(
mut commands: Commands,
mut materials: ResMut<Assets<ColorMaterial>>,

View file

@ -1,7 +1,7 @@
use bevy::prelude::AppExit;
use clap::Parser;
use distributed_physics_test::{run_app, utils::AppSettings};
use distributed_physics_test::{AppSettings, run_app};
fn main() -> AppExit {
run_app(AppSettings::parse())