From fc0d77d6838b16d811ffe5e999d3d77d499b470f Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sat, 8 Aug 2026 15:23:24 +0800 Subject: chore: initialize project workspace and movement plugin --- plugins/movement/src/lib.rs | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 plugins/movement/src/lib.rs (limited to 'plugins/movement/src/lib.rs') diff --git a/plugins/movement/src/lib.rs b/plugins/movement/src/lib.rs new file mode 100644 index 0000000..f7f6ba5 --- /dev/null +++ b/plugins/movement/src/lib.rs @@ -0,0 +1,52 @@ +//! CH Modules - Movement +//! +//! CH Movement provides a set of systems for driving Entity movement. +//! +//! # Included +//! +//! - **Velocity**: Represents the entity's current momentum, used by systems to calculate the next frame's position +//! - **Position**: Represents the entity's current location +//! - **Movement**: A pure marker, used to flag this entity as movable +//! - **VelocityReducer**: Controls how Velocity is reduced + +#![deny(missing_docs)] + +use bevy::{ + app::{FixedUpdate, Plugin}, + ecs::{query::With, system::Query}, +}; +use ch_macro_rules::import; + +// Basic data +import!(position, velocity, movement); + +// Modifiers +import!(reducer); + +/// Cigarette Hacker movement plugin +/// +/// Used to describe the movement of characters in the game +pub struct CHMovementPlugins; + +impl Plugin for CHMovementPlugins { + fn build(&self, app: &mut bevy::app::App) { + app.add_systems(FixedUpdate, update_movement); + } +} + +fn update_movement( + query: Query<(&mut Position, &mut Velocity, Option<&VelocityReducer>), With>, +) { + for (mut pos, mut velo, reducer) in query { + // Add Velocity to Position + pos.x += velo.x; + pos.y += velo.y; + pos.z += velo.z; + + // Apply velocity reduction (default to Lerp(0.25) if no reducer present) + match reducer { + Some(reducer) => reducer.calculate(&mut velo), + None => VelocityReducer::Lerp(0.25).calculate(&mut velo), + } + } +} -- cgit