Move to avian physics, stub out flappy bird (with rewind)

main
Elijah Voigt 3 months ago
parent df069d0337
commit 9c4b4a79b9

210
Cargo.lock generated

@ -322,6 +322,38 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
[[package]]
name = "avian3d"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0feaf6ed522e3e55130d820bfa2a3f3395092cbee2c986cfc1a464b60b50b4ca"
dependencies = [
"avian_derive",
"bevy",
"bevy_heavy",
"bevy_math",
"bevy_transform_interpolation",
"bitflags 2.9.1",
"derive_more",
"itertools 0.13.0",
"nalgebra",
"parry3d",
"parry3d-f64",
"thread_local",
]
[[package]]
name = "avian_derive"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12b257f601a1535e0d4a7a7796f535e3a13de62fd422b16dff7c14d27f0d4048"
dependencies = [
"proc-macro-error2",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "base64"
version = "0.21.7"
@ -707,6 +739,16 @@ dependencies = [
"tracing",
]
[[package]]
name = "bevy_heavy"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34ccc861fea2ff58c67f4df119512e204050bd7631a3a9c65e1a5e9d162cce28"
dependencies = [
"bevy_math",
"bevy_reflect",
]
[[package]]
name = "bevy_image"
version = "0.16.1"
@ -979,19 +1021,6 @@ version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df7370d0e46b60e071917711d0860721f5347bc958bf325975ae6913a5dfcf01"
[[package]]
name = "bevy_rapier3d"
version = "0.30.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdf74109573c2c82b05b217cb6101f7e71e6c53ad622aed6c370cc5783c59eb8"
dependencies = [
"bevy",
"bitflags 2.9.1",
"log",
"nalgebra",
"rapier3d",
]
[[package]]
name = "bevy_reflect"
version = "0.16.1"
@ -1260,6 +1289,15 @@ dependencies = [
"thiserror 2.0.12",
]
[[package]]
name = "bevy_transform_interpolation"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72c7c6c4e6a3d5415b3a29a17bd20c17cd0e2f068b96b24e263316d58d5346ea"
dependencies = [
"bevy",
]
[[package]]
name = "bevy_ui"
version = "0.16.1"
@ -1821,19 +1859,6 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b"
[[package]]
name = "crossbeam"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1137cd7e7fc0fb5d3c5a8678be38ec56e819125d8d7907411fe24ccb943faca8"
dependencies = [
"crossbeam-channel",
"crossbeam-deque",
"crossbeam-epoch",
"crossbeam-queue",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.15"
@ -2223,8 +2248,8 @@ dependencies = [
name = "games"
version = "0.1.0"
dependencies = [
"avian3d",
"bevy",
"bevy_rapier3d",
"chrono",
"indoc",
"itertools 0.14.0",
@ -3457,15 +3482,6 @@ dependencies = [
"num-traits",
]
[[package]]
name = "ordered-float"
version = "5.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2c1f9f56e534ac6a9b8a4600bdf0f530fb393b5f393e7b4d03489c3cf0c3f01"
dependencies = [
"num-traits",
]
[[package]]
name = "overload"
version = "0.1.1"
@ -3512,27 +3528,56 @@ dependencies = [
[[package]]
name = "parry3d"
version = "0.20.2"
version = "0.17.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bec55ce6f725367f8149f750575e79a8879d71b7257c02273259f9375822821f"
checksum = "6aeb9659a05b1783fb2e9bc94f48225ae5b40817eb45b62569c0e4dd767a6e51"
dependencies = [
"approx",
"arrayvec",
"bitflags 2.9.1",
"downcast-rs 2.0.1",
"downcast-rs 1.2.1",
"either",
"ena",
"hashbrown",
"log",
"nalgebra",
"num-derive",
"num-traits",
"ordered-float 5.0.0",
"ordered-float",
"rayon",
"rstar",
"rustc-hash 2.1.1",
"simba",
"slab",
"smallvec",
"spade",
"thiserror 2.0.12",
"thiserror 1.0.69",
]
[[package]]
name = "parry3d-f64"
version = "0.17.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4484c8ad93ff03c0e57aa1a4f3ff5406ab6301a1eb838ef6dea90e94f00a6c7"
dependencies = [
"approx",
"arrayvec",
"bitflags 2.9.1",
"downcast-rs 1.2.1",
"either",
"ena",
"log",
"nalgebra",
"num-derive",
"num-traits",
"ordered-float",
"rayon",
"rstar",
"rustc-hash 2.1.1",
"simba",
"slab",
"smallvec",
"spade",
"thiserror 1.0.69",
]
[[package]]
@ -3689,33 +3734,42 @@ dependencies = [
]
[[package]]
name = "proc-macro2"
version = "1.0.95"
name = "proc-macro-error-attr2"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
checksum = "96de42df36bb9bba5542fe9f1a054b8cc87e172759a1868aa05c1f3acc89dfc5"
dependencies = [
"unicode-ident",
"proc-macro2",
"quote",
]
[[package]]
name = "profiling"
version = "1.0.17"
name = "proc-macro-error2"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3eb8486b569e12e2c32ad3e204dbaba5e4b5b216e9367044f25f1dba42341773"
checksum = "11ec05c52be0a07b08061f7dd003e7d7092e0472bc731b4af7bb1ef876109802"
dependencies = [
"profiling-procmacros",
"proc-macro-error-attr2",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "profiling-procmacros"
version = "1.0.17"
name = "proc-macro2"
version = "1.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52717f9a02b6965224f95ca2a81e2e0c5c43baacd28ca057577988930b6c3d5b"
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
dependencies = [
"quote",
"syn",
"unicode-ident",
]
[[package]]
name = "profiling"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3eb8486b569e12e2c32ad3e204dbaba5e4b5b216e9367044f25f1dba42341773"
[[package]]
name = "quick-xml"
version = "0.37.5"
@ -3798,30 +3852,6 @@ version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f60fcc7d6849342eff22c4350c8b9a989ee8ceabc4b481253e8946b9fe83d684"
[[package]]
name = "rapier3d"
version = "0.25.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a35ec3d01c4f918675411442024a1fbfb7eafdd878a6e82479ff6e461a9092fc"
dependencies = [
"approx",
"arrayvec",
"bit-vec 0.8.0",
"bitflags 2.9.1",
"crossbeam",
"downcast-rs 2.0.1",
"log",
"nalgebra",
"num-derive",
"num-traits",
"ordered-float 5.0.0",
"parry3d",
"profiling",
"rustc-hash 2.1.1",
"simba",
"thiserror 2.0.12",
]
[[package]]
name = "raw-window-handle"
version = "0.6.2"
@ -3834,6 +3864,26 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3"
[[package]]
name = "rayon"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa"
dependencies = [
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2"
dependencies = [
"crossbeam-deque",
"crossbeam-utils",
]
[[package]]
name = "read-fonts"
version = "0.29.3"
@ -5007,7 +5057,7 @@ dependencies = [
"ndk-sys 0.5.0+25.2.9519653",
"objc",
"once_cell",
"ordered-float 4.6.0",
"ordered-float",
"parking_lot",
"profiling",
"range-alloc",

@ -10,8 +10,8 @@ thiserror = "2.0.12"
version = "1.0.219"
features = ["derive"]
[dependencies.bevy_rapier3d]
version = "0.30.0"
[dependencies.avian3d]
version = "0.3.1"
[dependencies.bevy]
version = "0.16.1"

@ -39,3 +39,6 @@ web/trees/serve: web/trees
itch.io/trees: web/trees
butler push dist/trees popgame/trees:html5 --userversion=$(VERSION)
clean:
rm -rf dist/trees

BIN
assets/flappy/bevy.png (Stored with Git LFS)

Binary file not shown.

@ -0,0 +1,55 @@
use std::f32::consts::PI;
use games::*;
fn main() {
App::new()
.add_plugins(BaseGamePlugin::default())
.add_systems(Startup, init_image)
.run();
}
fn init_image(
mut commands: Commands,
server: Res<AssetServer>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
mut std_materials: ResMut<Assets<StandardMaterial>>,
) {
// 2d
{
let texture = MeshMaterial2d(materials.add(ColorMaterial {
color: WHITE.into(),
alpha_mode: AlphaMode2d::Opaque,
texture: Some(server.load("flappy/bevy.png")),
..default()
}));
let mesh = Mesh2d(meshes.add(Rectangle::from_size(Vec2::splat(10.0))));
// opaque
// Each sprite should be square with the transparent parts being completely black
// The blue sprite should be on top with the white and green one behind it
commands.spawn((Name::new("2D Example"),mesh, texture));
}
// 3d
{
let material = MeshMaterial3d(std_materials.add(StandardMaterial {
base_color_texture: Some(server.load("flappy/bevy.png")),
base_color: WHITE.with_alpha(0.9).into(),
alpha_mode: AlphaMode::Blend,
..default()
}));
let mesh = Mesh3d(meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(1.0))));
let name = Name::new("3D example");
let t = Transform::from_xyz(0.0, 0.0, -10.0).with_rotation(Quat::from_rotation_x(PI / 2.0));
commands.spawn((name, mesh, material, t));
}
}

@ -25,7 +25,7 @@ impl Plugin for BaseGamePlugin {
}))
.add_plugins(DebuggingPlugin)
.add_plugins(MeshPickingPlugin)
.add_plugins(RapierPhysicsPlugin::<NoUserData>::default())
.add_plugins(PhysicsPlugins::default())
.add_plugins(LoadingPlugin)
.add_plugins(BaseUiPlugin)
.add_systems(Startup, setup_camera);

@ -0,0 +1,36 @@
use games::*;
fn main() {
App::new()
.add_plugins(BaseGamePlugin { name: "flappy bird (with rewind)".into() })
.add_systems(Startup, init_bird)
.run();
}
fn init_bird(
mut commands: Commands,
server: Res<AssetServer>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
let material = MeshMaterial3d(materials.add(StandardMaterial {
base_color_texture: Some(server.load("flappy/bevy.png")),
base_color: WHITE.with_alpha(0.9).into(),
alpha_mode: AlphaMode::Blend,
..default()
}));
let mesh = Mesh3d(meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(1.0))));
let name = Name::new("bird");
let t = Transform::from_xyz(0.0, 0.0, -10.0).with_rotation(Quat::from_rotation_x(PI / 2.0));
let mass = (
RigidBody::Dynamic,
Collider::capsule(1.0, 1.0),
Mass(5.0),
);
commands.spawn((name, mesh, material, mass, t));
}

@ -12,10 +12,7 @@ impl Plugin for DebuggingPlugin {
.init_resource::<Fps>()
.init_resource::<EntityCount>()
.init_resource::<Notice>()
.add_plugins(RapierDebugRenderPlugin::default().disabled())
// Added by Rapier
// .add_plugins(AabbGizmoPlugin)
// .add_plugins(LightGizmoPlugin)
.add_plugins(PhysicsDebugPlugin::default())
.add_systems(Startup, init_debug_ui)
.add_systems(
Update,
@ -49,7 +46,7 @@ impl Plugin for DebuggingPlugin {
})
.add_systems(
Update,
toggle_rapier_debug_render.run_if(state_changed::<DebuggingState>),
toggle_physics_debug_render.run_if(state_changed::<DebuggingState>),
)
.add_systems(OnEnter(DebuggingState::On), enable_wireframe)
.add_systems(OnExit(DebuggingState::On), disable_wireframe);
@ -194,15 +191,6 @@ fn toggle_debug_state(
info!("Toggling debug state: {:?} -> {:?}", curr, next);
}
/// Simple system that enables/disables rapier debug visuals when the debugging state changes
#[cfg(not(target_arch = "wasm32"))]
fn toggle_rapier_debug_render(
state: Res<State<DebuggingState>>,
mut context: ResMut<DebugRenderContext>,
) {
context.enabled = *state.get() == DebuggingState::On;
}
#[derive(Default, Resource)]
pub struct Notice(pub String);
@ -395,3 +383,14 @@ fn close_on_click(trigger: Trigger<Pointer<Click>>, mut query: Query<&mut Visibi
*v = Visibility::Hidden;
}
}
fn toggle_physics_debug_render(
state: Res<State<DebuggingState>>,
mut config_store: ResMut<GizmoConfigStore>,
) {
let (_, config) = config_store.config_mut::<PhysicsGizmos>();
*config = match state.get() {
DebuggingState::On => PhysicsGizmos::all(),
DebuggingState::Off => PhysicsGizmos::none(),
};
}

@ -8,9 +8,13 @@ mod scheduling;
mod ui;
mod version;
// Rust stdlib
pub use std::fmt::Display;
pub use std::f32::consts::PI;
// Community libraries
pub use bevy::{
sprite::AlphaMode2d,
asset::{AssetLoader, LoadContext, LoadState, LoadedFolder, io::Reader},
color::palettes::css::*,
gizmos::{aabb::AabbGizmoPlugin, light::LightGizmoPlugin},
@ -27,10 +31,11 @@ pub use bevy::{
reflect::TypePath,
window::WindowResized,
};
pub use bevy_rapier3d::prelude::*;
pub use avian3d::prelude::*;
pub use serde::Deserialize;
pub use thiserror::Error;
// Internal modules
pub use base_game::*;
pub use debug::*;
pub use loading::*;

Loading…
Cancel
Save