mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-28 08:58:07 +00:00
Bevy Book: ECS
This commit is contained in:
@@ -1,3 +1,36 @@
|
|||||||
|
use bevy::prelude::*;
|
||||||
|
|
||||||
fn main() {
|
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<S: Into<String>>(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!");
|
println!("Hello, world!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn greet_people(q: Query<&Name, With<Person>>) {
|
||||||
|
for name in &q {
|
||||||
|
println!("Hello, {}!", name.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user