completed first steps
This commit is contained in:
parent
90ea7c8b92
commit
4d48236931
1 changed files with 23 additions and 10 deletions
33
src/main.rs
33
src/main.rs
|
@ -2,16 +2,10 @@ use bevy::prelude::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins((DefaultPlugins, HelloPlugin))
|
||||||
.add_systems(Startup, add_people)
|
|
||||||
.add_systems(Update, (hello_world, (update_people, greet_people).chain()))
|
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hello_world() {
|
|
||||||
println!("hi!");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
struct Person;
|
struct Person;
|
||||||
|
|
||||||
|
@ -24,9 +18,18 @@ fn add_people(mut commands: Commands) {
|
||||||
commands.spawn((Person, Name("Marie Skłodowska".to_string())));
|
commands.spawn((Person, Name("Marie Skłodowska".to_string())));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn greet_people(query: Query<&Name, With<Person>>) {
|
#[derive(Resource)]
|
||||||
for name in &query {
|
struct GreetTimer(Timer);
|
||||||
println!("hello {}!", name.0);
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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