circle time
This commit is contained in:
parent
64e272be5d
commit
772126b0de
1 changed files with 22 additions and 31 deletions
53
src/main.rs
53
src/main.rs
|
@ -1,38 +1,29 @@
|
||||||
use bevy::prelude::*;
|
use bevy::{
|
||||||
|
prelude::*,
|
||||||
|
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
|
||||||
|
};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new().add_plugins((DefaultPlugins, HelloPlugin)).run();
|
App::new()
|
||||||
|
.add_plugins(DefaultPlugins)
|
||||||
|
.add_systems(Startup, setup)
|
||||||
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component)]
|
fn setup(
|
||||||
struct Person;
|
mut commands: Commands,
|
||||||
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||||
|
) {
|
||||||
|
commands.spawn(Camera2dBundle::default());
|
||||||
|
|
||||||
#[derive(Component)]
|
let circle_mesh = Mesh2dHandle(meshes.add(Circle { radius: 50. }));
|
||||||
struct Name(String);
|
let color = Color::hsl(75., 0.95, 0.7);
|
||||||
|
|
||||||
fn add_people(mut commands: Commands) {
|
commands.spawn(MaterialMesh2dBundle {
|
||||||
commands.spawn((Person, Name("Elaina Proctor".to_string())));
|
mesh: circle_mesh,
|
||||||
commands.spawn((Person, Name("Renzo Hume".to_string())));
|
material: materials.add(color),
|
||||||
commands.spawn((Person, Name("Zayna Nieves".to_string())));
|
transform: Transform::from_xyz(0., 0., 0.),
|
||||||
}
|
..default()
|
||||||
|
});
|
||||||
#[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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue