From 1c787d17ff920c21fc32161e13b78bfa36e7b057 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Wed, 20 Dec 2023 13:36:34 -0600 Subject: [PATCH] WIP movement --- src/main.rs | 2 ++ src/movement.rs | 40 ++++++++++++++++++++++++++++++++++ src/player.rs | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 src/movement.rs create mode 100644 src/player.rs 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