use bevy::prelude::*;
use bevy_kindly::*;
#[derive(Debug, EntityKind)]
#[default_components(Position)]
#[components(Speed, Clearance)]
struct Agent(Entity);
#[derive(Component)]
struct Speed(f64);
#[derive(Component)]
struct Clearance(usize);
#[derive(Component, Default, Debug)]
struct Position(Vec2);
#[derive(Component)]
struct Destination(Position);
trait NavigateTo {
fn navigate_to(self, position: Position);
}
impl NavigateTo for &mut EntityKindCommands<'_, '_, '_, Agent> {
fn navigate_to(self, position: Position) {
self.insert(Destination(position));
}
}
fn spawn_agent(mut commands: Commands) {
let mut agent = commands
.spawn_with_kind::<Agent>((Speed(10.0), Clearance(2)));
info!("{:?} spawned", agent.get());
agent.navigate_to(Position(Vec2::new(5.0, 10.0)));
}
fn update_navigation(
mut query: Query<(
EntityWithKind<Agent>,
&Speed,
&Clearance,
&Destination,
&mut Position,
)>,
) {
for (agent, _speed, _clearance, destination, _position) in &mut query {
info!("TODO: {:?} is navigating to {:?} ...", agent, destination.0);
}
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, spawn_agent)
.add_systems(Update, update_navigation)
.run();
}