Setup basic resources

This commit is contained in:
Daniel Lynn 2021-07-12 23:01:35 -05:00
parent bc5eb9b006
commit 3fe46fd116
Signed by: daniel
GPG Key ID: 28496A140E180A9D
5 changed files with 16 additions and 6 deletions

View File

@ -1,4 +1,2 @@
use crate::prelude::*;
pub struct Name(pub String);
pub struct Player;

View File

@ -1,10 +1,12 @@
mod components;
mod plugins;
mod resources;
mod systems;
mod prelude {
pub use crate::components::*;
pub use crate::plugins::*;
pub use crate::resources::*;
pub use crate::systems::*;
pub use bevy::prelude::*;
}

View File

@ -4,7 +4,8 @@ pub struct PlayerPlugin;
impl Plugin for PlayerPlugin {
fn build(&self, app: &mut AppBuilder) {
app.add_startup_system(add_player.system())
app.insert_resource(GreetTimer(Timer::from_seconds(2.0, true)))
.add_startup_system(add_player.system())
.add_system(greet_player.system());
}
}

3
src/resources/mod.rs Normal file
View File

@ -0,0 +1,3 @@
use crate::prelude::*;
pub struct GreetTimer(pub Timer);

View File

@ -7,8 +7,14 @@ pub fn add_player(mut commands: Commands) {
.insert(Name("Player 1".to_string()));
}
pub fn greet_player(query: Query<&Name, With<Player>>) {
for name in query.iter() {
println!("Hello, {}!", name.0);
pub fn greet_player(
query: Query<&Name, With<Player>>,
time: Res<Time>,
mut timer: ResMut<GreetTimer>,
) {
if timer.0.tick(time.delta()).just_finished() {
for name in query.iter() {
println!("Hello, {}!", name.0);
}
}
}