diff --git a/src/map.rs b/src/map.rs index 4921a65..cc86905 100644 --- a/src/map.rs +++ b/src/map.rs @@ -21,6 +21,10 @@ impl From for Coordinates { } } +#[derive(Clone, Debug, Default, Reflect)] +#[reflect(Component)] +pub struct AreaTag; + #[derive(Clone, Debug, Default, Deref, DerefMut)] pub struct Areas(pub Vec); @@ -327,6 +331,21 @@ fn add_areas(mut commands: Commands, query: Query<(Entity, &Map), (Added, W for (entity, map) in query.iter() { let mut v = vec![]; for room in &map.rooms { + commands + .spawn_bundle(ColliderBundle { + collider_type: ColliderType::Sensor, + shape: ColliderShape::cuboid( + (room.width() / 2) as f32, + (room.height() / 2) as f32, + ), + flags: ActiveEvents::INTERSECTION_EVENTS.into(), + ..Default::default() + }) + .insert(ColliderParent { + handle: entity.handle(), + pos_wrt_parent: Vec2::new(room.center().x(), room.center().y()).into(), + }) + .insert(AreaTag); v.push(Area { rect: *room, description: None,