Проектная работа - WIP
bevy tutorial
This commit is contained in:
@@ -2,44 +2,33 @@ use bevy::prelude::*;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_systems(Startup, add_people)
|
||||
.add_systems(Update, (hello_world, (update_people, greet_people).chain()))
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugins(HelloPlugin)
|
||||
.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);
|
||||
|
||||
#[derive(Resource)]
|
||||
struct GreetTimer(Timer);
|
||||
|
||||
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<Person>>) {
|
||||
for name in &query {
|
||||
println!("hello {}!", name.0);
|
||||
fn greet_people(time: Res<Time>, mut timer: ResMut<GreetTimer>, query: Query<&Name, With<Person>>) {
|
||||
// update uor timer with the time elapsed since the last update
|
||||
// if that causes the timer to finish, we say hello to everyone
|
||||
if timer.0.tick(time.delta()).just_finished() {
|
||||
for name in &query {
|
||||
info!("hello {}!", name.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,3 +40,13 @@ fn update_people(mut query: Query<&mut Name, With<Person>>) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct HelloPlugin;
|
||||
|
||||
impl Plugin for HelloPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.insert_resource(GreetTimer(Timer::from_seconds(2.0, TimerMode::Repeating)));
|
||||
app.add_systems(Startup, add_people);
|
||||
app.add_systems(Update, (update_people, greet_people).chain());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user