Fix rotation bug

main
Elijah Voigt 2 months ago
parent fc0f665afc
commit 1dfac5dd61

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

@ -43,6 +43,7 @@ impl Plugin for BlocksPlugin {
),
propogate_orientation.run_if(any_component_changed::<Orientation>),
propogate_grid_position.run_if(any_component_changed::<GridPosition>),
propogate_relative_position.run_if(any_component_changed::<RelativePosition>),
handle_kb_input.run_if(on_message::<KeyboardInput>),
handle_movement.run_if(on_message::<Movement>),
),
@ -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<RelativePosition>>,
parent: Query<&GridPosition, Without<ShapeBlock>>,
) {
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<Orientation>>,
mut children: Query<&mut GridPosition, Without<ShapeBlocks>>,
parent: Query<(&Orientation, &ShapeLayout, &ShapeBlocks), Changed<Orientation>>,
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;
});
});
}

Loading…
Cancel
Save