From e7693c747cbb439dbcb03e7cf86ef047c3fe6fd8 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Thu, 24 Jul 2025 16:04:53 -0700 Subject: [PATCH] Ladies and gentlemen... we have a bouncing bird --- src/bin/flappy/main.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/bin/flappy/main.rs b/src/bin/flappy/main.rs index 76854b6..7580d23 100644 --- a/src/bin/flappy/main.rs +++ b/src/bin/flappy/main.rs @@ -4,9 +4,13 @@ fn main() { App::new() .add_plugins(BaseGamePlugin { name: "flappy bird (with rewind)".into() }) .add_systems(Startup, init_bird) + .add_systems(Update, flap) .run(); } +#[derive(Component)] +struct Bird; + fn init_bird( mut commands: Commands, server: Res, @@ -29,8 +33,21 @@ fn init_bird( let mass = ( RigidBody::Dynamic, Collider::capsule(1.0, 1.0), - Mass(5.0), + Mass(1.0), ); - commands.spawn((name, mesh, material, mass, t)); + let force = ExternalForce::default().with_persistence(false); + + commands.spawn((name, mesh, material, mass, t, Bird, force)); +} + +fn flap( + keyboard: Res>, + mut bird: Query<(&Transform, &mut ExternalForce), With>, +) { + if keyboard.just_pressed(KeyCode::Space) { + bird.iter_mut().for_each(|(t, mut f)| { + f.apply_force(t.rotation * Vec3::NEG_Z * 1000.0); + }); + } }