Add keyboard event handler. "Q" to quit program
This commit is contained in:
@@ -10,7 +10,10 @@ impl Plugin for BoidsPlugin{
|
||||
app
|
||||
.insert_resource(ClearColor(BACKGROUND_COLOR))
|
||||
.add_systems(Startup, (spawn_camera, spawn_boids))
|
||||
.add_systems(FixedUpdate, apply_velocity);
|
||||
.add_systems(FixedUpdate, (
|
||||
apply_velocity,
|
||||
check_keyboard,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,3 +88,12 @@ fn apply_velocity(mut query: Query<(&mut Transform, &Velocity)>, time: Res<Time>
|
||||
transform.translation += delta_position;
|
||||
}
|
||||
}
|
||||
|
||||
fn check_keyboard(
|
||||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||
mut app_exit_events: ResMut<Events<bevy::app::AppExit>>,
|
||||
) {
|
||||
if keyboard_input.just_pressed(KeyCode::KeyQ) {
|
||||
app_exit_events.send(bevy::app::AppExit::Success);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user