diff --git a/src/main.rs b/src/main.rs index 9651ed1..5d65816 100644 --- a/src/main.rs +++ b/src/main.rs @@ -86,19 +86,7 @@ fn setup(mut commands: Commands, mut meshes: ResMut>, mut materials }, Agent )); - - // Line test - let line = shapes::Line(Vec2::ZERO, Vec2::new(100.0, 100.0)); - commands.spawn(( - ShapeBundle { - path: GeometryBuilder::build_as(&line), - ..default() - }, - Stroke::new(Color::ORANGE_RED, 5.0), - //Fill::color(Color::ORANGE_RED), - )); - - + // UI // Text with multiple sections commands.spawn(( diff --git a/src/world.rs b/src/world.rs index eea561d..3c214ac 100644 --- a/src/world.rs +++ b/src/world.rs @@ -2,6 +2,9 @@ use bevy::prelude::*; use bevy_prototype_lyon::prelude::*; +#[derive(Component)] +struct IsLine; + #[derive(Resource)] struct WorldPluginState { @@ -40,34 +43,40 @@ impl Plugin for WorldPlugin } } -fn setup(mut commands: Commands, settings: Res, mut meshes: ResMut>, mut materials: ResMut>) +fn setup(mut commands: Commands, settings: Res) { - // 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 - // { - - // } - // } -} + let cell_width = settings.window_width / settings.grid_width; + let cell_height = settings.window_height / settings.grid_height; + let line_size = 2.0; + let half_screen_width = settings.window_width / 2.0; + let half_screen_height = settings.window_height / 2.0; + for i in 0..settings.grid_width as i32 + { + let point_a = Vec2::new(i as f32 * cell_width - half_screen_width, -half_screen_height); + let point_b = Vec2::new(i as f32 * cell_width - half_screen_width, half_screen_height); + add_line(&mut commands, point_a, point_b, line_size); + } -// fn add_line(mut commands: Commands, point_a: Vec2, point_b: Vec2, line_size: i32) -// { + for i in 0..settings.grid_height as i32 + { + let point_a = Vec2::new(-half_screen_width, i as f32 * cell_height - half_screen_height); + let point_b = Vec2::new(half_screen_width, i as f32 * cell_height - half_screen_height); + add_line(&mut commands, point_a, point_b, line_size); + } +} +fn add_line(commands: &mut Commands, point_a: Vec2, point_b: Vec2, line_size: f32) +{ + let line = shapes::Line(point_a, point_b); -// 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 + commands.spawn(( + ShapeBundle { + path: GeometryBuilder::build_as(&line), + ..default() + }, + Stroke::new(Color::BLACK, line_size), + IsLine, + )); +} \ No newline at end of file