From 0b37adb79783aab6766be75e7cebcc0bd58eb12b Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Tue, 29 Jun 2021 09:29:49 -0500 Subject: [PATCH] Add new area system. --- src/map.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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,