Starting on the world mod

master
Joey Pollack 2 years ago
parent 09f8c2a49d
commit cbba37a993

@ -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()))

@ -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::<WindowPlugin>()[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<WorldPluginState>, mut meshes: ResMut<Assets<Mesh>>, mut materials: ResMut<Assets<ColorMaterial>>)
{
// 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()
// });
// }
Loading…
Cancel
Save