From ed8c679e57ce9a668cca5f095166f9e44cbb02d5 Mon Sep 17 00:00:00 2001 From: Zynh Ludwig Date: Tue, 3 Sep 2024 00:15:05 -0700 Subject: [PATCH] random spawn position --- Cargo.lock | 26 ++++++++++++++++++++++++++ Cargo.toml | 1 + src/main.rs | 51 ++++++++++++++++++++++++++++++++++++++------------- 3 files changed, 65 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7366677..d242a72 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1209,6 +1209,7 @@ name = "boids-rs" version = "0.1.0" dependencies = [ "bevy", + "rand", ] [[package]] @@ -2962,6 +2963,15 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + [[package]] name = "presser" version = "0.3.1" @@ -3013,6 +3023,18 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", "rand_core", ] @@ -3021,6 +3043,9 @@ name = "rand_core" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] [[package]] name = "range-alloc" @@ -4282,6 +4307,7 @@ version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ + "byteorder", "zerocopy-derive", ] diff --git a/Cargo.toml b/Cargo.toml index 569b1b4..232e4a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] bevy = "0.14.1" +rand = { version = "0.8.5", features = ["small_rng"] } # Enable a small amount of optimization in the dev profile. [profile.dev] diff --git a/src/main.rs b/src/main.rs index 9d0c5f9..8ac4fd5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,15 +1,26 @@ +#![allow(unused)] + mod boid_mesh; mod boundary; use bevy::{color::palettes::tailwind, prelude::*, sprite::MaterialMesh2dBundle}; use boid_mesh::BoidMesh; +use rand::{Rng, SeedableRng}; fn main() { App::new() .init_resource::() .add_plugins(DefaultPlugins) .add_systems(Startup, (boid_mesh::build_boid_mesh, setup).chain()) - .add_systems(Update, (move_boids, boundary::boid_border_teleport).chain()) + .add_systems( + Update, + ( + (seperation, cohesion, alignment), + move_boids, + boundary::boid_border_teleport, + ) + .chain(), + ) .run(); } @@ -43,7 +54,11 @@ struct BoidBundle { cache: BoidAccelerationBundle, } -fn seperation(mut boids: Query<(&Transform, &mut SeperationAcceleration), With>) {} +fn seperation(mut boids: Query<(Entity, &Transform, &mut SeperationAcceleration), With>) {} + +fn cohesion(mut boids: Query<(Entity, &Transform, &mut SeperationAcceleration), With>) {} + +fn alignment(mut boids: Query<(Entity, &Transform, &mut SeperationAcceleration), With>) {} fn move_boids(mut boids: Query<(&mut Transform, &Velocity), With>, time: Res