icebreaker/src/main.rs

41 lines
952 B
Rust
Raw Normal View History

2024-04-21 10:35:00 +00:00
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()))
.run();
}
fn hello_world() {
println!("hi!");
}
#[derive(Component)]
struct Person;
#[derive(Component)]
struct Name(String);
fn add_people(mut commands: Commands) {
commands.spawn((Person, Name("Albert Einstein".to_string())));
commands.spawn((Person, Name("Robert Oppenheimer".to_string())));
commands.spawn((Person, Name("Marie Skłodowska".to_string())));
}
fn greet_people(query: Query<&Name, With<Person>>) {
for name in &query {
println!("hello {}!", name.0);
}
}
fn update_people(mut query: Query<&mut Name, With<Person>>) {
for mut name in &mut query {
if name.0 == "Marie Skłodowska" {
name.0 = "Marie Curie".to_string();
break;
}
}
}