52 lines
1.2 KiB
Rust
52 lines
1.2 KiB
Rust
|
use bevy::prelude::*;
|
||
|
|
||
|
#[derive(Component)]
|
||
|
struct Person;
|
||
|
|
||
|
#[derive(Component)]
|
||
|
struct Name(String);
|
||
|
|
||
|
#[derive(Component)]
|
||
|
struct Position {
|
||
|
x: f32,
|
||
|
y: f32,
|
||
|
}
|
||
|
|
||
|
#[derive(Resource)]
|
||
|
struct GreetTimer(Timer);
|
||
|
|
||
|
struct Entity(u64);
|
||
|
|
||
|
pub struct HelloPlugin;
|
||
|
|
||
|
impl Plugin for HelloPlugin {
|
||
|
fn build(&self, app: &mut App) {
|
||
|
// add things to your app here
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn add_people(mut commands: Commands) {
|
||
|
commands.spawn((Person, Name("Elaina Proctor".to_string())));
|
||
|
commands.spawn((Person, Name("Renzo Hume".to_string())));
|
||
|
commands.spawn((Person, Name("Zayna Nieves".to_string())));
|
||
|
}
|
||
|
fn main() {
|
||
|
let mut app = App::new();
|
||
|
app.add_plugins((DefaultPlugins, HelloPlugin))
|
||
|
.add_systems(Startup, add_people)
|
||
|
.add_systems(Update, greet_people)
|
||
|
.insert_resource(GreetTimer(Timer::from_seconds(0.2, TimerMode::Repeating)));
|
||
|
|
||
|
app.run()
|
||
|
}
|
||
|
|
||
|
fn greet_people(time: Res<Time>, mut timer: ResMut<GreetTimer>, query: Query<&Name, With<Person>>) {
|
||
|
// update our timer with the time elapsed since the last update
|
||
|
// if that caused the timer to finish, we say hello to everyone
|
||
|
if timer.0.tick(time.delta()).just_finished() {
|
||
|
for name in &query {
|
||
|
println!("hello {}!", name.0);
|
||
|
}
|
||
|
}
|
||
|
}
|