Added piece rotation

master
hheik 2025-08-23 01:13:36 +03:00
parent db238c3248
commit 0433a1f90b
1 changed files with 59 additions and 28 deletions

View File

@ -58,9 +58,10 @@ pub fn apply_piece_movement(
blocks
};
let cast_shape =
|pos| collisions.cast_shape(pos, &blocks) || !game_area.is_shape_inside(pos, &blocks);
{
let cast_shape = |pos| {
collisions.cast_shape(pos, &blocks) || !game_area.is_shape_inside(pos, &blocks)
};
let piece_pos = &mut transform_query.get_mut(entity).unwrap().0.translation;
if controls.instant_drop {
@ -96,4 +97,34 @@ pub fn apply_piece_movement(
}
}
}
{
let cast_shape = |pos, blocks| {
collisions.cast_shape(pos, blocks) || !game_area.is_shape_inside(pos, blocks)
};
let rotate = |point: Vector2I, rotation: input::Rotation| match rotation {
input::Rotation::Clockwise => Vector2I::new(point.y, -point.x),
input::Rotation::CounterClockwise => Vector2I::new(-point.y, point.x),
};
let rotate_slice = |points: &[Vector2I], rotation: input::Rotation| {
points
.iter()
.map(|point| rotate(*point, rotation))
.collect::<Vec<Vector2I>>()
};
let piece_pos = transform_query.get(entity).unwrap().0.translation;
if let Some(rotation) = controls.rotation {
let rotated = rotate_slice(&blocks, rotation);
if !cast_shape(piece_pos, &rotated) {
for child in children.iter() {
if let Ok((mut transform, has_block)) = transform_query.get_mut(child) {
if has_block {
transform.translation = rotate(transform.translation, rotation);
}
}
}
}
}
}
}
}