From 529258a7d442191dc5bdd06dd65a10921aa94d8c Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Wed, 20 Dec 2023 22:08:40 -0600 Subject: [PATCH] Player can move around --- src/main.rs | 7 ++++++- src/movement.rs | 54 ++++++++++++++++++++++--------------------------- src/player.rs | 31 ++++++++++++---------------- 3 files changed, 43 insertions(+), 49 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4110b9c..98c324e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,12 @@ fn main() { }), ..Default::default() })) - .add_plugins((camera::Camera, assets::AssetLoader)) + .add_plugins(( + camera::Camera, + assets::AssetLoader, + player::Player, + movement::Movement, + )) .add_systems(Update, keyboard_input_system) .insert_resource(ClearColor(Color::rgb(0.3, 0., 0.5))) .insert_resource(AmbientLight { diff --git a/src/movement.rs b/src/movement.rs index d118869..578b456 100644 --- a/src/movement.rs +++ b/src/movement.rs @@ -1,43 +1,37 @@ use bevy::prelude::*; -pub struct MovementPlugin; - -#[derive(Component, Debug, Default)] +#[derive(Component, Deref, DerefMut, Debug, Default)] pub struct Velocity(pub Vec2); -impl Velocity { - pub fn from_speed_heading(heading: Vec2, speed: f32) -> Self { - Self(heading.normalize_or_zero() * speed) - } -} - -#[derive(Component, Debug, Default)] +#[derive(Component, Deref, DerefMut, Debug, Default)] pub struct Heading(pub Vec2); -#[derive(Component, Debug, Default)] +#[derive(Component, Deref, DerefMut, Debug, Default)] pub struct Speed(pub f32); -impl Heading { - pub fn new(x: f32, y: f32) -> Self { - Self(Vec2::new(x, y)) - } -} - -#[derive(Bundle, Debug, Default)] -pub struct MovementBundle { - pub velocity: Velocity, - pub heading: Heading, - pub speed: Speed, -} - -impl Plugin for MovementPlugin { - fn build(&self, app: &mut App) { - app.add_systems(Update, update_position); - } -} - fn update_position(mut query: Query<(&Velocity, &mut Transform)>, time: Res