aboutsummaryrefslogtreecommitdiff
path: root/plugins/movement/src/lib.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-08-08 15:23:24 +0800
committer魏曹先生 <1992414357@qq.com>2026-08-08 15:23:24 +0800
commitfc0d77d6838b16d811ffe5e999d3d77d499b470f (patch)
tree00565a452f9045b4fb357ae04a1cae349163839a /plugins/movement/src/lib.rs
chore: initialize project workspace and movement plugin
Diffstat (limited to 'plugins/movement/src/lib.rs')
-rw-r--r--plugins/movement/src/lib.rs52
1 files changed, 52 insertions, 0 deletions
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<Movement>>,
+) {
+ 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),
+ }
+ }
+}