Compare commits
6 Commits
bc7569ecee
...
b7a9434b93
Author | SHA1 | Date |
---|---|---|
Zynh Ludwig | b7a9434b93 | |
Zynh Ludwig | 0db4cf5fce | |
Zynh Ludwig | 19f4c5280e | |
Zynh Ludwig | 16a9fca8ce | |
Zynh Ludwig | e395417794 | |
Zynh Ludwig | ebc89c75d9 |
37
src/main.rs
37
src/main.rs
|
@ -1,3 +1,38 @@
|
||||||
|
use bevy::prelude::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
App::new().add_plugins((DefaultPlugins, HelloPlugin)).run();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct Person;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct Name(String);
|
||||||
|
|
||||||
|
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())));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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, greet_people);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue