diff --git a/crates/core/src/core.rs b/crates/core/src/core.rs index 0e4c5ec..f937702 100644 --- a/crates/core/src/core.rs +++ b/crates/core/src/core.rs @@ -1,13 +1,16 @@ use bevy::prelude::*; +use crate::movement::{MovementPlugin, Velocity}; + pub struct CorePlugin; impl Plugin for CorePlugin { fn build(&self, app: &mut App) { - app.add_systems(Startup, setup); + app.add_plugins(MovementPlugin) + .add_systems(Startup, setup); } } @@ -43,11 +46,12 @@ fn setup(mut commands: Commands, server: Res, mut ambient_light: Re // BALL let ball_handle: Handle = server.load("ball.glb#Scene0"); - commands.spawn(SceneBundle { + commands.spawn((SceneBundle { scene: ball_handle, transform: Transform::from_xyz(0.0, -7.75, 0.0), ..default() - }); + }, + Velocity::new(0.5, 0.5, 0.0))); // PADDLE let paddle_handle: Handle = server.load("paddle.glb#Scene0"); diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 14d0377..2ca2a62 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -1,3 +1,4 @@ -pub mod core; \ No newline at end of file +pub mod core; +pub mod movement; \ No newline at end of file diff --git a/crates/core/src/movement.rs b/crates/core/src/movement.rs new file mode 100644 index 0000000..128e736 --- /dev/null +++ b/crates/core/src/movement.rs @@ -0,0 +1,39 @@ + + +use bevy::prelude::*; + +pub struct MovementPlugin; +impl Plugin for MovementPlugin +{ + fn build(&self, app: &mut App) + { + app.add_systems(Update, update_movement); + } +} + +#[derive(Component)] +pub struct Velocity(Vec3); + +impl Default for Velocity +{ + fn default() -> Self + { + Self { 0: Vec3::new(0.0, 0.0, 0.0)} + } +} + +impl Velocity +{ + pub fn new(x: f32, y: f32, z: f32) -> Self{ + Self { 0: Vec3::new(x, y, z) } + } +} + +// SYSTEMS +fn update_movement(mut moving_objects: Query<(&Velocity, &mut Transform)>, time: Res