diff --git a/Cargo.lock b/Cargo.lock index 2126eaa..503672b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2076,6 +2076,7 @@ version = "0.1.0" dependencies = [ "bevy", "bevy_prototype_lyon", + "rand", ] [[package]] @@ -2648,6 +2649,12 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + [[package]] name = "proc-macro-crate" version = "1.3.1" @@ -2688,6 +2695,36 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17fd96390ed3feda12e1dfe2645ed587e0bea749e319333f104a33ff62f77a0b" +[[package]] +name = "rand" +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", +] + +[[package]] +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" version = "0.1.3" diff --git a/Cargo.toml b/Cargo.toml index 4498558..2cfa3f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ edition = "2021" [dependencies] bevy = "0.11.0" bevy_prototype_lyon = "0.9.0" +rand = "0.8.5" # Enable high optimizations for dependencies (incl. Bevy), but not for our code: diff --git a/src/agent.rs b/src/agent.rs new file mode 100644 index 0000000..04d905d --- /dev/null +++ b/src/agent.rs @@ -0,0 +1,19 @@ + + +use bevy::{prelude::*}; + + +#[derive(Component)] +pub struct Agent +{ + pub pos_x: i32, + pub pos_y: i32, +} + +impl Agent +{ + pub fn new(x: i32, y: i32) -> Agent + { + Agent { pos_x: x, pos_y: y } + } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 914e9af..67797d4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,9 +11,8 @@ use std::time::Instant; mod world; mod neural_net; - -#[derive(Component)] -struct Agent; +mod agent; +use agent::Agent; #[derive(Component)] struct FpsText; @@ -60,7 +59,8 @@ fn main() WorldPlugin { grid_width: 100., grid_height: 100., - top_margin: 50.0 + top_margin: 50.0, + num_agents: 100, }, ShapePlugin )) @@ -75,18 +75,25 @@ fn main() fn setup(mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>) { // Camera - commands.spawn(Camera2dBundle::default()); + //commands.spawn(Camera2dBundle::default()); + commands.spawn(Camera2dBundle{ + projection: OrthographicProjection { + viewport_origin: Vec2 { x: 0.0, y: 0.0 }, + ..default() + }, + ..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() - }, - Agent - )); + // 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(0., 0., 0.)), + // ..default() + // }, + // Agent::new(0, 0) + // )); // UI // Text with multiple sections @@ -112,6 +119,7 @@ fn setup(mut commands: Commands, mut meshes: ResMut>, mut materials } fn tick_simulation(mut state: ResMut, delta_time: Res