aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-08-08 15:49:38 +0800
committer魏曹先生 <1992414357@qq.com>2026-08-08 15:49:38 +0800
commit8ff60fdeb0dda7cb6eb7ed91c5084fc107f33365 (patch)
tree8b72bc3e2aa684b28e5623ac91653ee713fd638e
parentebd8f440ae5a2d131cd4e6c064b2d97209cf0858 (diff)
feat: add gravity and gravity-movement plugins
Add CHGravityPlugin to manage the global gravity resource and CHGravityMovementGluePlugin to apply gravity to movement velocity each fixed update. Update workspace dependencies and include the new crates in the main app.
-rw-r--r--Cargo.lock19
-rw-r--r--Cargo.toml15
-rw-r--r--plugins/glues/gravity_movement/Cargo.toml9
-rw-r--r--plugins/glues/gravity_movement/src/lib.rs29
-rw-r--r--plugins/gravity/Cargo.toml8
-rw-r--r--plugins/gravity/src/gravity.rs12
-rw-r--r--plugins/gravity/src/lib.rs19
-rw-r--r--src/main.rs2
8 files changed, 110 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 76b093d..707d3c9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1969,6 +1969,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527"
[[package]]
+name = "ch-gravity"
+version = "0.1.0"
+dependencies = [
+ "bevy",
+ "ch-macro-rules",
+]
+
+[[package]]
+name = "ch-gravity-movement"
+version = "0.1.0"
+dependencies = [
+ "bevy",
+ "ch-gravity",
+ "ch-movement",
+]
+
+[[package]]
name = "ch-macro-rules"
version = "0.1.0"
@@ -1994,6 +2011,8 @@ name = "cigarette_hacker_bevy"
version = "0.1.0"
dependencies = [
"bevy",
+ "ch-gravity",
+ "ch-gravity-movement",
"ch-movement",
]
diff --git a/Cargo.toml b/Cargo.toml
index 9d073ca..ce898e3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,7 +5,9 @@ edition.workspace = true
[dependencies]
bevy.workspace = true
-ch-movement = { path = "plugins/movement" }
+ch-movement.workspace = true
+ch-gravity.workspace = true
+ch-gravity-movement.workspace = true
[workspace.dependencies]
# Core
@@ -16,6 +18,11 @@ proc-macro2 = "1.0.107"
quote = "1.0.47"
syn = "3.0.3"
+# Plugins
+ch-movement = { path = "plugins/movement" }
+ch-gravity = { path = "plugins/gravity" }
+ch-gravity-movement = { path = "plugins/glues/gravity_movement" }
+
# Utils
ch-macros = { path = "utils/macros" }
ch-macro-rules = { path = "utils/macro_rules" }
@@ -25,7 +32,9 @@ version = "0.1.0"
edition = "2024"
[workspace]
-members = [
- "plugins/movement", "utils/macro_rules",
+members = ["plugins/glues/gravity_movement",
+ "plugins/gravity",
+ "plugins/movement",
+ "utils/macro_rules",
"utils/macros"
]
diff --git a/plugins/glues/gravity_movement/Cargo.toml b/plugins/glues/gravity_movement/Cargo.toml
new file mode 100644
index 0000000..4b5790c
--- /dev/null
+++ b/plugins/glues/gravity_movement/Cargo.toml
@@ -0,0 +1,9 @@
+[package]
+name = "ch-gravity-movement"
+version.workspace = true
+edition.workspace = true
+
+[dependencies]
+bevy.workspace = true
+ch-movement.workspace = true
+ch-gravity.workspace = true
diff --git a/plugins/glues/gravity_movement/src/lib.rs b/plugins/glues/gravity_movement/src/lib.rs
new file mode 100644
index 0000000..da31061
--- /dev/null
+++ b/plugins/glues/gravity_movement/src/lib.rs
@@ -0,0 +1,29 @@
+//! CH Glue - Gravity & Movement
+//!
+//! This module provides the glue layer for the Gravity and Movement modules.
+
+#![deny(missing_docs)]
+
+use bevy::{
+ app::{FixedUpdate, Plugin},
+ ecs::system::{Query, Res},
+};
+use ch_gravity::Gravity;
+use ch_movement::{Movement, Velocity};
+
+/// Cigarette Hacker gravity movement glue
+pub struct CHGravityMovementGluePlugin;
+
+impl Plugin for CHGravityMovementGluePlugin {
+ fn build(&self, app: &mut bevy::app::App) {
+ app.add_systems(FixedUpdate, apply_gravity_to_movement);
+ }
+}
+
+fn apply_gravity_to_movement(mut query: Query<(&mut Velocity, &Movement)>, gravity: Res<Gravity>) {
+ for (mut velocity, _movement) in query.iter_mut() {
+ velocity.x += gravity.x;
+ velocity.y += gravity.y;
+ velocity.z += gravity.z;
+ }
+}
diff --git a/plugins/gravity/Cargo.toml b/plugins/gravity/Cargo.toml
new file mode 100644
index 0000000..1221f40
--- /dev/null
+++ b/plugins/gravity/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "ch-gravity"
+version.workspace = true
+edition.workspace = true
+
+[dependencies]
+bevy.workspace = true
+ch-macro-rules.workspace = true
diff --git a/plugins/gravity/src/gravity.rs b/plugins/gravity/src/gravity.rs
new file mode 100644
index 0000000..6d7030c
--- /dev/null
+++ b/plugins/gravity/src/gravity.rs
@@ -0,0 +1,12 @@
+use bevy::{
+ ecs::resource::Resource,
+ math::Vec3,
+ prelude::{Deref, DerefMut},
+};
+
+/// Represents the global gravity
+#[derive(Resource, Deref, DerefMut, PartialEq, Default, Clone)]
+pub struct Gravity {
+ #[deref]
+ pub(crate) gravity: Vec3,
+}
diff --git a/plugins/gravity/src/lib.rs b/plugins/gravity/src/lib.rs
new file mode 100644
index 0000000..4282256
--- /dev/null
+++ b/plugins/gravity/src/lib.rs
@@ -0,0 +1,19 @@
+//! CH Modules - Gravity
+//!
+//! CH Gravity provides the basic in-game representation of gravity
+
+use bevy::{app::Plugin, math::Vec3};
+use ch_macro_rules::import;
+
+import!(gravity);
+
+/// Cigarette Hacker gravity plugin
+pub struct CHGravityPlugin;
+
+impl Plugin for CHGravityPlugin {
+ fn build(&self, app: &mut bevy::app::App) {
+ app.insert_resource(Gravity {
+ gravity: Vec3::new(0., 1., 0.) * -9.8,
+ });
+ }
+}
diff --git a/src/main.rs b/src/main.rs
index 4906590..df08db9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -9,5 +9,7 @@ fn main() {
let mut app = App::new();
app.add_plugins(DefaultPlugins);
app.add_plugins(ch_movement::CHMovementPlugin);
+ app.add_plugins(ch_gravity::CHGravityPlugin);
+ app.add_plugins(ch_gravity_movement::CHGravityMovementGluePlugin);
app.run();
}