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)] #[derive(Clone, Debug, Default, Deref, DerefMut)]
pub struct Areas(pub Vec<Area>); pub struct Areas(pub Vec<Area>);
#[derive(Clone, Debug, Default, Deref, DerefMut, Reflect)] #[derive(Clone, Debug, Default, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct Portal(Vec<(i32, i32)>); pub struct Portal;
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub struct Map { 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() { for y in 0..map.height() {
let tile = map.base.at(x, y); let tile = map.base.at(x, y);
if tile.blocks_motion() { 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 let id = commands
.spawn() .spawn()
.insert_bundle(collider) .insert_bundle(ColliderBundle {
.insert(collider_parent) 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(); .id();
if tile.blocks_visibility() { if tile.blocks_visibility() {
commands.entity(id).insert(BlocksVisibility); commands.entity(id).insert(BlocksVisibility);
@ -291,10 +289,19 @@ fn portal_spawner(
.spawn() .spawn()
.insert_bundle(PortalBundle { .insert_bundle(PortalBundle {
coordinates, coordinates,
portal: Portal(vec![coordinates.i32()]),
transform: Transform::from_translation(Vec3::new(x, y, 0.)),
..Default::default() ..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(); .id();
commands.entity(entity).push_children(&[portal]); commands.entity(entity).push_children(&[portal]);
} }

View File

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