Compare commits

...

6 Commits

Author SHA1 Message Date
Zynh Ludwig b7a9434b93 remove hello 2024-07-29 23:11:23 -07:00
Zynh Ludwig 0db4cf5fce resources 2024-07-29 23:10:36 -07:00
Zynh Ludwig 19f4c5280e custom plugin 2024-07-29 23:06:16 -07:00
Zynh Ludwig 16a9fca8ce default plugins 2024-07-29 23:03:53 -07:00
Zynh Ludwig e395417794 more bevy gettings started code 2024-07-29 23:03:20 -07:00
Zynh Ludwig ebc89c75d9 actually using bevy 2024-07-29 22:48:11 -07:00
1 changed files with 36 additions and 1 deletions

View File

@ -1,3 +1,38 @@
use bevy::prelude::*;
fn main() {
println!("Hello, world!");
App::new().add_plugins((DefaultPlugins, HelloPlugin)).run();
}
#[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("Zayna Nieves".to_string())));
}
#[derive(Resource)]
struct GreetTimer(Timer);
fn greet_people(time: Res<Time>, mut timer: ResMut<GreetTimer>, query: Query<&Name, With<Person>>) {
if timer.0.tick(time.delta()).just_finished() {
for name in &query {
println!("hello {}!", name.0);
}
}
}
pub struct HelloPlugin;
impl Plugin for HelloPlugin {
fn build(&self, app: &mut App) {
app.insert_resource(GreetTimer(Timer::from_seconds(2.0, TimerMode::Repeating)))
.add_systems(Startup, add_people)
.add_systems(Update, greet_people);
}
}