diff --git a/src/main.rs b/src/main.rs index 9b6dcd8..4110b9c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,8 @@ use bevy::prelude::*; mod assets; mod camera; +mod movement; +mod player; fn main() { let mut app = App::new(); diff --git a/src/movement.rs b/src/movement.rs new file mode 100644 index 0000000..a70dece --- /dev/null +++ b/src/movement.rs @@ -0,0 +1,40 @@ +use bevy::prelude::*; + +pub struct MovementPlugin; + +#[derive(Component, Debug, Default)] +pub struct Velocity(Vec2); + +#[derive(Component, Debug, Default)] +pub struct Heading(Vec2); + +#[derive(Component, Debug, Default)] +pub struct Speed(f32); + +impl Velocity { + pub fn from_speed_heading(heading: Vec2, speed: f32) -> Self { + Self(heading.normalize_or_zero() * speed) + } + + pub fn new(x: f32, y: f32) -> Self { + Self(Vec2::new(x, y)) + } +} + +#[derive(Bundle, Debug, Default)] +pub struct MovementBundle { + pub velocity: Velocity, +} + +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