diff --git a/tetris/src/blocks.rs b/tetris/src/blocks.rs index e67b355..95a773b 100644 --- a/tetris/src/blocks.rs +++ b/tetris/src/blocks.rs @@ -379,7 +379,7 @@ fn setup_grid( mut materials: ResMut>, mut checklist: ResMut, ) { - let m: Mesh = Rectangle::new(SCALE, SCALE).into(); + let m: Mesh = Rectangle::new(SCALE * 0.9, SCALE * 0.9).into(); let mh: Handle = meshes.add(m); let m2d = Mesh2d(mh); let c: Color = WHITE.with_alpha(0.5).into(); @@ -387,10 +387,15 @@ fn setup_grid( let mat = MeshMaterial2d(ch); let t = Transform::from_xyz(0.0, 0.0, -1.0); - for x in 0..X_MAX { - for y in 0..Y_MAX { + for y in 0..Y_MAX { + // Spawn this line + let gp = GridPosition { x: 0, y }; + commands.spawn((gp, Line(y as u8), LineBlocks::default(), t)); + + // Spawn the grid squares for this line + for x in 0..X_MAX { let gp = GridPosition { x, y }; - commands.spawn((gp, m2d.clone(), mat.clone(), t.clone())); + commands.spawn((gp, m2d.clone(), mat.clone(), t)); } } @@ -407,6 +412,20 @@ struct ShapeBlock(Entity); #[relationship_target(relationship = ShapeBlock)] struct ShapeBlocks(Vec); +/// Line number component +#[derive(Component)] +struct Line(u8); + +/// Blocks <- Line Relationship +#[derive(Component)] +#[relationship(relationship_target = LineBlocks)] +struct LineBlock(Entity); + +/// Line -> Blocks Relationship +#[derive(Component, Default)] +#[relationship_target(relationship = LineBlock)] +struct LineBlocks(Vec); + /// Event handler for transforming a handle component into a thing fn add_shape( event: On>,