Use colliders for portals, and other cleanup.

This commit is contained in:
Nolan Darilek 2021-06-07 12:43:20 -05:00
parent c85fdb67c9
commit 08e6c4779a
2 changed files with 22 additions and 16 deletions

View File

@ -22,9 +22,9 @@ impl From<mapgen::geometry::Point> for Coordinates {
#[derive(Clone, Debug, Default, Deref, DerefMut)]
pub struct Areas(pub Vec<Area>);
#[derive(Clone, Debug, Default, Deref, DerefMut, Reflect)]
#[derive(Clone, Debug, Default, Reflect)]
#[reflect(Component)]
pub struct Portal(Vec<(i32, i32)>);
pub struct Portal;
#[derive(Clone, Default)]
pub struct Map {
@ -218,18 +218,16 @@ fn add_map_colliders(mut commands: Commands, maps: Query<(Entity, &Map), Added<M
for y in 0..map.height() {
let tile = map.base.at(x, y);
if tile.blocks_motion() {
let collider = ColliderBundle {
shape: ColliderShape::cuboid(0.5, 0.5),
..Default::default()
};
let collider_parent = ColliderParent {
handle: rigid_body_entity.handle(),
pos_wrt_parent: Vec2::new(x as f32 + 0.5, y as f32 + 0.5).into(),
};
let id = commands
.spawn()
.insert_bundle(collider)
.insert(collider_parent)
.insert_bundle(ColliderBundle {
shape: ColliderShape::cuboid(0.5, 0.5),
..Default::default()
})
.insert(ColliderParent {
handle: rigid_body_entity.handle(),
pos_wrt_parent: Vec2::new(x as f32 + 0.5, y as f32 + 0.5).into(),
})
.id();
if tile.blocks_visibility() {
commands.entity(id).insert(BlocksVisibility);
@ -291,10 +289,19 @@ fn portal_spawner(
.spawn()
.insert_bundle(PortalBundle {
coordinates,
portal: Portal(vec![coordinates.i32()]),
transform: Transform::from_translation(Vec3::new(x, y, 0.)),
..Default::default()
})
.insert_bundle(ColliderBundle {
collider_type: ColliderType::Sensor,
shape: ColliderShape::cuboid(0.5, 0.5),
flags: ActiveEvents::INTERSECTION_EVENTS.into(),
..Default::default()
})
.insert(ColliderPositionSync::Discrete)
.insert(ColliderParent {
handle: entity.handle(),
pos_wrt_parent: Vec2::new(x + 0.5, y + 0.5).into(),
})
.id();
commands.entity(entity).push_children(&[portal]);
}

View File

@ -7,10 +7,9 @@ use bevy_tts::Tts;
use derive_more::{Deref, DerefMut};
use crate::{
core::{Angle, CardinalDirection, Player, PointLike},
core::{Angle, CardinalDirection, Player},
error::error_handler,
exploration::{ExplorationFocused, Exploring},
map::{ITileType, Map},
pathfinding::Destination,
};