|
|
|
@ -2,6 +2,9 @@
|
|
|
|
use bevy::prelude::*;
|
|
|
|
use bevy::prelude::*;
|
|
|
|
use bevy_prototype_lyon::prelude::*;
|
|
|
|
use bevy_prototype_lyon::prelude::*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
|
|
|
struct IsLine;
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Resource)]
|
|
|
|
#[derive(Resource)]
|
|
|
|
struct WorldPluginState
|
|
|
|
struct WorldPluginState
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -40,34 +43,40 @@ impl Plugin for WorldPlugin
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn setup(mut commands: Commands, settings: Res<WorldPluginState>, mut meshes: ResMut<Assets<Mesh>>, mut materials: ResMut<Assets<ColorMaterial>>)
|
|
|
|
fn setup(mut commands: Commands, settings: Res<WorldPluginState>)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Camera
|
|
|
|
|
|
|
|
//commands.spawn(Camera2dBundle::default());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add Grid
|
|
|
|
// Add Grid
|
|
|
|
// let cell_width = settings.window_width / settings.grid_width;
|
|
|
|
let cell_width = settings.window_width / settings.grid_width;
|
|
|
|
// let cell_height = settings.window_height / settings.grid_height;
|
|
|
|
let cell_height = settings.window_height / settings.grid_height;
|
|
|
|
// let line_size = 2;
|
|
|
|
let line_size = 2.0;
|
|
|
|
// for i in 0..settings.grid_width as i32
|
|
|
|
let half_screen_width = settings.window_width / 2.0;
|
|
|
|
// {
|
|
|
|
let half_screen_height = settings.window_height / 2.0;
|
|
|
|
// for j in 0..settings.grid_height as i32
|
|
|
|
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 {
|
|
|
|
commands.spawn((
|
|
|
|
// mesh: meshes
|
|
|
|
ShapeBundle {
|
|
|
|
// .add(shape::Quad::new(Vec2::new(cell_width * i, cell_height * j)).into())
|
|
|
|
path: GeometryBuilder::build_as(&line),
|
|
|
|
// .into(),
|
|
|
|
..default()
|
|
|
|
// material: materials.add(ColorMaterial::from(Color::BLACK)),
|
|
|
|
},
|
|
|
|
// transform: Transform::from_translation(Vec3::new(50., 0., 0.)),
|
|
|
|
Stroke::new(Color::BLACK, line_size),
|
|
|
|
// ..default()
|
|
|
|
IsLine,
|
|
|
|
// });
|
|
|
|
));
|
|
|
|
// }
|
|
|
|
}
|