|
|
|
|
@ -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<AssetServer>,
|
|
|
|
|
@ -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<ButtonInput<KeyCode>>,
|
|
|
|
|
mut bird: Query<(&Transform, &mut ExternalForce), With<Bird>>,
|
|
|
|
|
) {
|
|
|
|
|
if keyboard.just_pressed(KeyCode::Space) {
|
|
|
|
|
bird.iter_mut().for_each(|(t, mut f)| {
|
|
|
|
|
f.apply_force(t.rotation * Vec3::NEG_Z * 1000.0);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|