Hit detection not working, but not horribly broken either... somewhere in between.

main
Elijah Voigt 2 weeks ago
parent 2cab218e5c
commit f6aae11f8c

@ -92,6 +92,10 @@ struct BlockOf {
parent: Entity,
}
// Just marks a block either of a shape or line
#[derive(Component, Debug)]
struct Block;
#[derive(Component, Debug)]
#[require(GridPosition)]
struct RelativePosition {
@ -454,7 +458,7 @@ fn set_piece(
.entity(e)
.with_related_entities::<BlockOf>(|parent| {
positions.into_iter().for_each(|rp| {
parent.spawn((Mesh2d(mesh.clone()), MeshMaterial2d(mat.clone()), rp));
parent.spawn((Mesh2d(mesh.clone()), MeshMaterial2d(mat.clone()), rp, Block));
});
});
} else {
@ -569,9 +573,9 @@ fn clock_cycle(n: f32) -> impl FnMut(Res<Time>, Local<f32>) -> bool {
/// Check if the active piece is about to collide with the ground
fn check_collision(
active: Query<(&GridPosition, Entity), With<RelativePosition>>,
shape: Single<Entity, With<Shape>>,
inactive: Query<&GridPosition, Without<RelativePosition>>,
active: Query<(&GridPosition, Entity), (With<Block>, With<RelativePosition>)>,
shape: Single<(Entity, &GridPosition), With<ShapeBlocks>>,
inactive: Query<&GridPosition, (With<Block>, Without<RelativePosition>)>,
mut commands: Commands,
) {
// TODO: Easy optimizations
@ -582,13 +586,17 @@ fn check_collision(
// Check if active peice is near other blocks
let hit_block = inactive.iter().any(|b| {
debug!("Checking against: {:?}", b);
a.is_colliding_with(b)
if a.is_colliding_with(b) {
info!("{:?} is colliding with {:?}", a, b);
true
} else { false }
});
hit_floor || hit_block
});
if false {
if hit {
info!("hit detected!");
let blocks: Vec<Entity> = active
@ -599,8 +607,9 @@ fn check_collision(
debug_assert_eq!(blocks.len(), 4, "Shapes should have 4 blocks");
info!("De-relating blocks {:?} and shape {:?}", blocks, *shape);
let (shape_e, _shape_pos) = *shape;
commands
.entity(*shape)
.entity(shape_e)
.remove_related::<BlockOf>(blocks.as_slice())
.despawn();
}

Loading…
Cancel
Save