From cbba37a99340117fcc635eadb4426d2698abedbd Mon Sep 17 00:00:00 2001 From: Joey Pollack Date: Mon, 31 Jul 2023 09:53:07 -0400 Subject: [PATCH] Starting on the world mod --- src/main.rs | 11 ++++++-- src/world.rs | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 src/world.rs diff --git a/src/main.rs b/src/main.rs index bc52f1e..b402715 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,9 +4,11 @@ use bevy::{ diagnostic::{FrameTimeDiagnosticsPlugin, DiagnosticsStore}, window::{PresentMode, WindowTheme}, sprite::MaterialMesh2dBundle}; +use world::WorldPlugin; use std::time::Instant; +mod world; mod neural_net; #[derive(Component)] @@ -41,7 +43,7 @@ fn main() DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { title: "Life Sim".into(), - resolution: (1280., 720.).into(), + resolution: (1000., 1000.).into(), present_mode: PresentMode::AutoVsync, // Tells wasm to resize the window according to the available canvas fit_canvas_to_parent: true, @@ -52,7 +54,12 @@ fn main() }), ..default() }), - FrameTimeDiagnosticsPlugin + FrameTimeDiagnosticsPlugin, + + WorldPlugin { + grid_width: 100., + grid_height: 100. + } )) .insert_resource(SimulationState::new(200)) .insert_resource(Time::new(Instant::now())) diff --git a/src/world.rs b/src/world.rs new file mode 100644 index 0000000..53de95c --- /dev/null +++ b/src/world.rs @@ -0,0 +1,72 @@ + +use bevy::{prelude::*, sprite::MaterialMesh2dBundle}; + +#[derive(Resource)] +struct WorldPluginState +{ + window_width: f32, + window_height: f32, + grid_width: f32, + grid_height: f32, + +} + +pub struct WorldPlugin +{ + pub grid_width: f32, + pub grid_height: f32, +} + +impl Plugin for WorldPlugin +{ + fn build(&self, app: &mut App) + { + let window_plugin = app.get_added_plugins::()[0]; + if let Some(window) = &window_plugin.primary_window + { + println!("WorldPlugin: Window resolution is: ({}, {})", window.resolution.width(), window.resolution.height()); + + + app.insert_resource(WorldPluginState + { + window_width: window.resolution.width(), + window_height: window.resolution.height(), + grid_width: self.grid_width, + grid_height: self.grid_height + }) + .add_systems(Startup, setup); + } + } +} + +fn setup(mut commands: Commands, settings: Res, mut meshes: ResMut>, mut materials: ResMut>) +{ + // Camera + commands.spawn(Camera2dBundle::default()); + + // Add Grid + let cell_width = settings.window_width / settings.grid_width; + let cell_height = settings.window_height / settings.grid_height; + let line_size = 2; + for i in 0..settings.grid_width as i32 + { + for j in 0..settings.grid_height as i32 + { + + } + } +} + +// fn add_line(mut commands: Commands, point_a: Vec2, point_b: Vec2, line_size: i32) +// { + + +// commands.spawn(MaterialMesh2dBundle { +// mesh: meshes +// .add(shape::Quad::new(Vec2::new(cell_width * i, cell_height * j)).into()) +// .into(), +// material: materials.add(ColorMaterial::from(Color::BLACK)), +// transform: Transform::from_translation(Vec3::new(50., 0., 0.)), +// ..default() +// }); +// } \ No newline at end of file