Setup basic resources
This commit is contained in:
parent
bc5eb9b006
commit
3fe46fd116
@ -1,4 +1,2 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
pub struct Name(pub String);
|
||||
pub struct Player;
|
||||
|
@ -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::*;
|
||||
}
|
||||
|
@ -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
3
src/resources/mod.rs
Normal file
@ -0,0 +1,3 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
pub struct GreetTimer(pub Timer);
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user