circle time

This commit is contained in:
Zynh Ludwig 2024-07-30 00:37:40 -07:00
parent 64e272be5d
commit 772126b0de

View file

@ -1,38 +1,29 @@
use bevy::prelude::*;
use bevy::{
prelude::*,
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
};
fn main() {
App::new().add_plugins((DefaultPlugins, HelloPlugin)).run();
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
}
#[derive(Component)]
struct Person;
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
commands.spawn(Camera2dBundle::default());
#[derive(Component)]
struct Name(String);
let circle_mesh = Mesh2dHandle(meshes.add(Circle { radius: 50. }));
let color = Color::hsl(75., 0.95, 0.7);
fn add_people(mut commands: Commands) {
commands.spawn((Person, Name("Elaina Proctor".to_string())));
commands.spawn((Person, Name("Renzo Hume".to_string())));
commands.spawn((Person, Name("Zayna Nieves".to_string())));
}
#[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);
}
commands.spawn(MaterialMesh2dBundle {
mesh: circle_mesh,
material: materials.add(color),
transform: Transform::from_xyz(0., 0., 0.),
..default()
});
}