Add new area system.
This commit is contained in:
parent
0700c3d30c
commit
0b37adb797
19
src/map.rs
19
src/map.rs
|
@ -21,6 +21,10 @@ impl From<mapgen::geometry::Point> for Coordinates {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, Reflect)]
|
||||||
|
#[reflect(Component)]
|
||||||
|
pub struct AreaTag;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deref, DerefMut)]
|
#[derive(Clone, Debug, Default, Deref, DerefMut)]
|
||||||
pub struct Areas(pub Vec<Area>);
|
pub struct Areas(pub Vec<Area>);
|
||||||
|
|
||||||
|
@ -327,6 +331,21 @@ fn add_areas(mut commands: Commands, query: Query<(Entity, &Map), (Added<Map>, W
|
||||||
for (entity, map) in query.iter() {
|
for (entity, map) in query.iter() {
|
||||||
let mut v = vec![];
|
let mut v = vec![];
|
||||||
for room in &map.rooms {
|
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 {
|
v.push(Area {
|
||||||
rect: *room,
|
rect: *room,
|
||||||
description: None,
|
description: None,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user