From 6542f8f7a7810e8d54cc7e1238449923a940fd1b Mon Sep 17 00:00:00 2001 From: Alexander Baranov Date: Wed, 27 May 2026 22:56:13 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20-=20WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bevy tutorial --- snake-game/examples/bevy_tutorial.rs | 53 ++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 snake-game/examples/bevy_tutorial.rs diff --git a/snake-game/examples/bevy_tutorial.rs b/snake-game/examples/bevy_tutorial.rs new file mode 100644 index 0000000..77c8a46 --- /dev/null +++ b/snake-game/examples/bevy_tutorial.rs @@ -0,0 +1,53 @@ +use bevy::prelude::*; + +fn main() { + App::new() + .add_systems(Startup, add_people) + .add_systems(Update, (hello_world, (update_people, greet_people).chain())) + .run(); +} + +#[derive(Component)] +struct Position { + x: f32, + y: f32, +} + +fn print_position_system(query: Query<&Position>) { + for position in &query { + println!("position: {} {}", position.x, position.y); + } +} + +struct Entity(u64); + +fn hello_world() { + println!("hello world!"); +} + +#[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("Zaina Nieves".to_string()))); +} + +fn greet_people(query: Query<&Name, With>) { + for name in &query { + println!("hello {}!", name.0); + } +} + +fn update_people(mut query: Query<&mut Name, With>) { + for mut name in &mut query { + if name.0 == "Elaina Proctor" { + name.0 = "Elaina Hume".to_string(); + break; // We don't need to change any other names. + } + } +}