completed first steps
This commit is contained in:
parent
90ea7c8b92
commit
4d48236931
1 changed files with 23 additions and 10 deletions
29
src/main.rs
29
src/main.rs
|
@ -2,16 +2,10 @@ use bevy::prelude::*;
|
|||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_systems(Startup, add_people)
|
||||
.add_systems(Update, (hello_world, (update_people, greet_people).chain()))
|
||||
.add_plugins((DefaultPlugins, HelloPlugin))
|
||||
.run();
|
||||
}
|
||||
|
||||
fn hello_world() {
|
||||
println!("hi!");
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
struct Person;
|
||||
|
||||
|
@ -24,10 +18,19 @@ fn add_people(mut commands: Commands) {
|
|||
commands.spawn((Person, Name("Marie Skłodowska".to_string())));
|
||||
}
|
||||
|
||||
fn greet_people(query: Query<&Name, With<Person>>) {
|
||||
#[derive(Resource)]
|
||||
struct GreetTimer(Timer);
|
||||
|
||||
fn greet_people(
|
||||
time: Res<Time>,
|
||||
mut timer: ResMut<GreetTimer>,
|
||||
query: Query<&Name, With<Person>>
|
||||
) {
|
||||
if timer.0.tick(time.delta()).just_finished() {
|
||||
for name in &query {
|
||||
println!("hello {}!", name.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update_people(mut query: Query<&mut Name, With<Person>>) {
|
||||
|
@ -38,3 +41,13 @@ fn update_people(mut query: Query<&mut Name, With<Person>>) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct HelloPlugin;
|
||||
|
||||
impl Plugin for HelloPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.insert_resource(GreetTimer(Timer::from_seconds(2.0, TimerMode::Repeating)))
|
||||
.add_systems(Startup,add_people)
|
||||
.add_systems(Update, (update_people, greet_people).chain());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue