From dbf00340ac2c4f768b98a7c207d4632e9bb4da4a Mon Sep 17 00:00:00 2001 From: Danny McGee Date: Wed, 27 Sep 2023 11:15:59 -0400 Subject: [PATCH] Bevy Book: ECS --- hello-world/src/main.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/hello-world/src/main.rs b/hello-world/src/main.rs index e7a11a9..af93c3f 100644 --- a/hello-world/src/main.rs +++ b/hello-world/src/main.rs @@ -1,3 +1,36 @@ +use bevy::prelude::*; + fn main() { + App::new() + .add_systems(Startup, add_people) + .add_systems(Update, (hello_world, greet_people)) + .run(); +} + +#[derive(Component)] +struct Person; + +#[derive(Component)] +struct Name(String); + +impl Name { + fn new>(name: S) -> Self { + Self(name.into()) + } +} + +fn add_people(mut cmds: Commands) { + cmds.spawn((Person, Name::new("Elaina Proctor"))); + cmds.spawn((Person, Name::new("Renzo Hume"))); + cmds.spawn((Person, Name::new("Zayna Nieves"))); +} + +fn hello_world() { println!("Hello, world!"); } + +fn greet_people(q: Query<&Name, With>) { + for name in &q { + println!("Hello, {}!", name.0); + } +}