From 51756046491a96080a70080bad0cb1eab1fc191e Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Fri, 24 Nov 2023 22:40:47 -0800 Subject: [PATCH] skeleton of update systems --- src/lib.rs | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++--- src/main.rs | 6 +++-- 2 files changed, 73 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2a31bd9..54d458b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,9 @@ use argh::FromArgs; use bevy::prelude::*; +const SPEED: f32 = 20.0; +const SPEED_DIFF_RANGE: f32 = 0.08; // +/- 8% + #[derive(Debug, FromArgs, Resource)] /// Toid Watching pub struct Config { @@ -26,6 +29,9 @@ impl Pointable for Vec3 { #[derive(Resource, Deref, DerefMut)] pub struct Index(pub rstar::RTree); +#[derive(Resource, Deref, DerefMut)] +pub struct Positions(pub std::collections::HashMap); + #[derive(Component, Debug, Clone, Deref, DerefMut, Default)] pub struct Buddies(Vec); @@ -33,12 +39,21 @@ pub struct Buddies(Vec); pub struct Velocity(Vec3); #[derive(Component)] -pub struct Toid; +pub struct Toid { + pub speed: f32, +} -pub fn turkey_time(commands: &mut Commands, scene: &Handle) -> Entity { +pub fn turkey_time( + commands: &mut Commands, + scene: &Handle, + r: &mut impl rand::prelude::Rng, +) -> Entity { + let speed_diff = r.gen_range(-SPEED_DIFF_RANGE..=SPEED_DIFF_RANGE); + let speed = SPEED + (SPEED * speed_diff); + let vel = unit_vec(r) * speed; commands .spawn(SpatialBundle::default()) - .insert((Velocity::default(), Buddies::default(), Toid)) + .insert((Velocity(vel), Buddies::default(), Toid { speed })) .with_children(|t| { t.spawn(SceneBundle { scene: scene.to_owned(), @@ -60,3 +75,54 @@ pub fn add_gizmos(mut gizmos: Gizmos, toids: Query<(&Transform, Entity), With, + time: Res