bevy-game/src/main.rs

46 lines
1.0 KiB
Rust
Raw Normal View History

2023-03-18 03:04:16 -07:00
use bevy::prelude::*;
2023-03-18 13:46:16 -07:00
pub struct GamarjobaPlugin;
impl Plugin for GamarjobaPlugin {
fn build(&self, app: &mut App) {
app.add_startup_system(add_people)
2023-03-18 14:15:17 -07:00
.insert_resource(GreetTimer(Timer::from_seconds(2.0, TimerMode::Repeating)))
2023-03-18 13:46:16 -07:00
.add_system(greetings);
}
}
2023-03-18 12:04:25 -07:00
#[derive(Component)]
struct Person;
#[derive(Component)]
struct Name(String);
fn add_people(mut commands: Commands) {
commands.spawn((Person, Name("Skero Tlamenai".into())));
commands.spawn((Person, Name("Wagoyesa Luutunen".into())));
commands.spawn((Person, Name("Mak'lazi Heyorem".into())));
}
2023-03-18 14:15:17 -07:00
#[derive(Resource)]
struct GreetTimer(Timer);
2023-03-18 12:04:25 -07:00
2023-03-18 14:15:17 -07:00
fn greetings(query: Query<&Name, With<Person>>, time: Res<Time>, mut timer: ResMut<GreetTimer>) {
if timer.0.tick(time.delta()).just_finished() {
for name in &query {
println!("Gamarjoba, {}", name.0)
}
}
2023-03-18 12:04:25 -07:00
}
2023-03-18 03:04:16 -07:00
2023-03-18 02:44:55 -07:00
fn main() {
2023-03-18 03:04:16 -07:00
App::new()
2023-03-18 13:01:54 -07:00
.add_plugins(DefaultPlugins)
2023-03-18 13:46:16 -07:00
.add_plugin(GamarjobaPlugin)
2023-03-18 03:04:16 -07:00
.run();
2023-03-18 02:44:55 -07:00
}