|
|
|
@ -6,47 +6,10 @@ use crate::start_menu::StartMenu;
|
|
|
|
|
/// The top-level structure of our game, which is a bevy plugin
|
|
|
|
|
pub struct Game {}
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
struct Person;
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
struct Name(String);
|
|
|
|
|
|
|
|
|
|
#[derive(Resource)]
|
|
|
|
|
struct Greeter {
|
|
|
|
|
timer: Timer,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn register_people(mut commands: Commands) {
|
|
|
|
|
commands.spawn((Person, Name(String::from("Alice"))));
|
|
|
|
|
commands.spawn((Person, Name(String::from("Bob"))));
|
|
|
|
|
commands.spawn((Person, Name(String::from("Carol"))));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn greet(time: Res<Time>, mut timer: ResMut<Greeter>, query: Query<&Name, With<Person>>) {
|
|
|
|
|
timer.timer.tick(time.delta());
|
|
|
|
|
if timer.timer.just_finished() {
|
|
|
|
|
for name in &query {
|
|
|
|
|
info!(
|
|
|
|
|
"Hello, {name}! elapsed: {elapsed:.2?} delta: {delta:.2?}",
|
|
|
|
|
name = name.0,
|
|
|
|
|
elapsed = time.elapsed(),
|
|
|
|
|
delta = time.delta(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Plugin for Game {
|
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
|
info!("Building rps Plugin");
|
|
|
|
|
let timer = Greeter {
|
|
|
|
|
timer: Timer::from_seconds(2.0, TimerMode::Repeating),
|
|
|
|
|
};
|
|
|
|
|
app.add_plugins(StartMenu {});
|
|
|
|
|
app.insert_resource(timer)
|
|
|
|
|
.add_systems(Startup, register_people)
|
|
|
|
|
.add_systems(Update, greet);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|