diff --git a/tetris/TODO.md b/tetris/TODO.md new file mode 100644 index 0000000..3261f02 --- /dev/null +++ b/tetris/TODO.md @@ -0,0 +1,11 @@ +# Tetris Game + +## Bugs + + +## Features + +* Drawing the grid where the piece can go +* Placing pieces in the grid +* Placing multiple pieces stacking +* Clearing lines when they are full diff --git a/tetris/src/blocks.rs b/tetris/src/blocks.rs index 6e98b5c..f38b81c 100644 --- a/tetris/src/blocks.rs +++ b/tetris/src/blocks.rs @@ -43,6 +43,7 @@ impl Plugin for BlocksPlugin { ), propogate_orientation.run_if(any_component_changed::), propogate_grid_position.run_if(any_component_changed::), + propogate_relative_position.run_if(any_component_changed::), handle_kb_input.run_if(on_message::), handle_movement.run_if(on_message::), ), @@ -444,17 +445,28 @@ fn propogate_grid_position( }); } -/// When a shape's orientation changes, the blocks need to move +/// When a block's relative position changes, update it's grid position +fn propogate_relative_position( + mut children: Query<(&mut GridPosition, &RelativePosition, &ShapeBlock), Changed>, + parent: Query<&GridPosition, Without>, +) { + children.iter_mut().for_each(|(mut gp, rp, sb)| { + let parent_gp = parent.get(sb.0).unwrap(); + *gp = parent_gp.clone() + *rp; + }); +} + +/// When a shape's orientation changes, the blocks need to move so assign new relative positions fn propogate_orientation( - parent: Query<(&GridPosition, &Orientation, &ShapeLayout, &ShapeBlocks), Changed>, - mut children: Query<&mut GridPosition, Without>, + parent: Query<(&Orientation, &ShapeLayout, &ShapeBlocks), Changed>, + mut children: Query<&mut RelativePosition>, ) { - parent.iter().for_each(|(parent_gp, parent_o, sl, sbs)| { + parent.iter().for_each(|(parent_o, sl, sbs)| { let new_layout = sl.positions(*parent_o); sbs.iter().zip(new_layout).for_each(|(e, rp)| { - let mut gp = children.get_mut(e).unwrap(); - *gp = parent_gp.clone() + rp; + let mut this_rp = children.get_mut(e).unwrap(); + *this_rp = rp; }); }); }