94 lines
2.5 KiB
Rust
94 lines
2.5 KiB
Rust
use bevy::prelude::*;
|
|
use bevy::sprite::MaterialMesh2dBundle;
|
|
|
|
pub struct GamarjobaPlugin;
|
|
|
|
impl Plugin for GamarjobaPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
app.add_startup_system(add_people)
|
|
.insert_resource(GreetTimer(Timer::from_seconds(2.0, TimerMode::Repeating)))
|
|
.add_system(greetings);
|
|
}
|
|
|
|
}
|
|
|
|
#[derive(Component)]
|
|
struct Person;
|
|
|
|
|
|
#[derive(Component)]
|
|
struct Name(String);
|
|
|
|
fn add_people(mut commands: Commands) {
|
|
|
|
commands.spawn((Person, Name("Skero Tlamenai".into())));
|
|
commands.spawn((Person, Name("Wagoyesa Luutunen".into())));
|
|
commands.spawn((Person, Name("Mak'lazi Heyorem".into())));
|
|
}
|
|
|
|
#[derive(Resource)]
|
|
struct GreetTimer(Timer);
|
|
|
|
fn greetings(query: Query<&Name, With<Person>>, time: Res<Time>, mut timer: ResMut<GreetTimer>) {
|
|
if timer.0.tick(time.delta()).just_finished() {
|
|
for name in &query {
|
|
println!("Gamarjoba, {}", name.0)
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins(DefaultPlugins)
|
|
.add_plugin(GamarjobaPlugin)
|
|
.add_startup_system(setup)
|
|
.run();
|
|
}
|
|
|
|
fn setup(
|
|
mut commands: Commands,
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
|
) {
|
|
commands.spawn(Camera2dBundle::default());
|
|
|
|
// Circle
|
|
commands.spawn(MaterialMesh2dBundle {
|
|
mesh: meshes.add(shape::Circle::new(50.).into()).into(),
|
|
material: materials.add(ColorMaterial::from(Color::PURPLE)),
|
|
transform: Transform::from_translation(Vec3::new(-150., 0., 0.)),
|
|
..default()
|
|
});
|
|
|
|
// Rectangle
|
|
commands.spawn(SpriteBundle {
|
|
sprite: Sprite {
|
|
color: Color::rgb(0.25, 0.25, 0.75),
|
|
custom_size: Some(Vec2::new(50.0, 100.0)),
|
|
..default()
|
|
},
|
|
transform: Transform::from_translation(Vec3::new(-50., 0., 0.)),
|
|
..default()
|
|
});
|
|
|
|
// Quad
|
|
commands.spawn(MaterialMesh2dBundle {
|
|
mesh: meshes
|
|
.add(shape::Quad::new(Vec2::new(50., 100.)).into())
|
|
.into(),
|
|
material: materials.add(ColorMaterial::from(Color::LIME_GREEN)),
|
|
transform: Transform::from_translation(Vec3::new(50., 0., 0.)),
|
|
..default()
|
|
});
|
|
|
|
// Hexagon
|
|
commands.spawn(MaterialMesh2dBundle {
|
|
mesh: meshes.add(shape::RegularPolygon::new(50., 6).into()).into(),
|
|
material: materials.add(ColorMaterial::from(Color::TURQUOISE)),
|
|
transform: Transform::from_translation(Vec3::new(150., 0., 0.)),
|
|
..default()
|
|
});
|
|
}
|
|
|