Add keyboard event handler. "Q" to quit program
This commit is contained in:
@@ -10,7 +10,10 @@ impl Plugin for BoidsPlugin{
|
|||||||
app
|
app
|
||||||
.insert_resource(ClearColor(BACKGROUND_COLOR))
|
.insert_resource(ClearColor(BACKGROUND_COLOR))
|
||||||
.add_systems(Startup, (spawn_camera, spawn_boids))
|
.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;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,13 +2,15 @@ use bevy::prelude::*;
|
|||||||
|
|
||||||
mod breakout_plugin;
|
mod breakout_plugin;
|
||||||
mod hello_world_plugin;
|
mod hello_world_plugin;
|
||||||
|
mod birdoids_plugin;
|
||||||
|
|
||||||
use breakout_plugin::BreakoutPlugin;
|
use breakout_plugin::BreakoutPlugin;
|
||||||
use hello_world_plugin::HelloPlugin;
|
use hello_world_plugin::HelloPlugin;
|
||||||
|
use birdoids_plugin::BoidsPlugin;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_plugins(BreakoutPlugin)
|
.add_plugins(BoidsPlugin)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user