This commit is contained in:
parent
5e700a74b0
commit
1020f818b9
|
@ -30,7 +30,7 @@ bevy_tts = { git = "https://github.com/lightsoutgames/bevy_tts", default-feature
|
|||
coord_2d = "0.3"
|
||||
futures-lite = "1"
|
||||
gilrs = "0.9"
|
||||
here_be_dragons = "0.1"
|
||||
here_be_dragons = "0.2"
|
||||
leafwing_input_manager = { git = "https://github.com/leafwing-studios/leafwing-input-manager", branch = "dev" }
|
||||
maze_generator = "2"
|
||||
once_cell = "1"
|
||||
|
|
35
src/map.rs
35
src/map.rs
|
@ -196,19 +196,21 @@ fn spawn_colliders<D: 'static + Clone + Default + Send + Sync>(
|
|||
.insert(RigidBody::Fixed);
|
||||
for y in 0..map.height {
|
||||
for x in 0..map.width {
|
||||
let tile = map.at(x, y);
|
||||
if tile.blocks_motion() {
|
||||
let id = commands
|
||||
.spawn()
|
||||
.insert(Collider::cuboid(0.5, 0.5))
|
||||
.insert(Transform::from_xyz(x as f32 + 0.5, y as f32 + 0.5, 0.))
|
||||
.insert(GlobalTransform::default())
|
||||
.insert(MapObstruction)
|
||||
.id();
|
||||
if tile.blocks_visibility() {
|
||||
commands.entity(id).insert(Visible::opaque());
|
||||
if let Some(tile) = map.at(x, y) {
|
||||
if tile.blocks_motion() {
|
||||
let id =
|
||||
commands
|
||||
.spawn_bundle(TransformBundle::from_transform(
|
||||
Transform::from_xyz(x as f32 + 0.5, y as f32 + 0.5, 0.),
|
||||
))
|
||||
.insert(Collider::cuboid(0.5, 0.5))
|
||||
.insert(MapObstruction)
|
||||
.id();
|
||||
if tile.blocks_visibility() {
|
||||
commands.entity(id).insert(Visible::opaque());
|
||||
}
|
||||
commands.entity(map_entity).push_children(&[id]);
|
||||
}
|
||||
commands.entity(map_entity).push_children(&[id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -218,15 +220,14 @@ fn spawn_colliders<D: 'static + Clone + Default + Send + Sync>(
|
|||
Isometry2::new(Vector2::new(room.center().x(), room.center().y()), 0.);
|
||||
let aabb = shape.raw.compute_aabb(&position);
|
||||
let id = commands
|
||||
.spawn()
|
||||
.insert(shape)
|
||||
.insert(Sensor)
|
||||
.insert(ActiveEvents::COLLISION_EVENTS)
|
||||
.insert_bundle(TransformBundle::from_transform(Transform::from_xyz(
|
||||
.spawn_bundle(TransformBundle::from_transform(Transform::from_xyz(
|
||||
position.translation.x,
|
||||
position.translation.y,
|
||||
0.,
|
||||
)))
|
||||
.insert(shape)
|
||||
.insert(Sensor)
|
||||
.insert(ActiveEvents::COLLISION_EVENTS)
|
||||
.insert(Area(aabb))
|
||||
.insert(Zone)
|
||||
.id();
|
||||
|
|
|
@ -48,9 +48,11 @@ pub fn find_path<D: 'static + Clone + Default + Send + Sync>(
|
|||
&start.into(),
|
||||
|p| {
|
||||
let mut successors: Vec<((i32, i32), u32)> = vec![];
|
||||
if map.at(p.0 as usize, p.1 as usize).is_walkable() {
|
||||
for tile in map.get_available_exits(p.0 as usize, p.1 as usize) {
|
||||
successors.push(((tile.0 as i32, tile.1 as i32), (tile.2 * 100.) as u32));
|
||||
if let Some(tile) = map.at(p.0 as usize, p.1 as usize) {
|
||||
if tile.is_walkable() {
|
||||
for tile in map.get_available_exits(p.0 as usize, p.1 as usize) {
|
||||
successors.push(((tile.0 as i32, tile.1 as i32), (tile.2 * 100.) as u32));
|
||||
}
|
||||
}
|
||||
}
|
||||
successors
|
||||
|
@ -74,25 +76,30 @@ fn find_path_for_shape<D: 'static + Clone + Default + Send + Sync>(
|
|||
&start.i32(),
|
||||
|p| {
|
||||
let mut successors: Vec<((i32, i32), u32)> = vec![];
|
||||
if map.at(p.0 as usize, p.1 as usize).is_walkable() {
|
||||
for tile in map.get_available_exits(p.0 as usize, p.1 as usize) {
|
||||
let mut should_push = true;
|
||||
let shape_pos =
|
||||
Isometry2::new(Vector2::new(tile.0 as f32 + 0.5, tile.1 as f32 + 0.5), 0.);
|
||||
query_pipeline.intersections_with_shape(
|
||||
&rigid_body_set,
|
||||
&collider_set,
|
||||
&shape_pos,
|
||||
&*shape.raw,
|
||||
bevy_rapier2d::rapier::pipeline::QueryFilter::new()
|
||||
.predicate(&|h, _c| h != initiator),
|
||||
|_handle| {
|
||||
should_push = false;
|
||||
false
|
||||
},
|
||||
);
|
||||
if should_push {
|
||||
successors.push(((tile.0 as i32, tile.1 as i32), (tile.2 * 100.) as u32));
|
||||
if let Some(tile) = map.at(p.0 as usize, p.1 as usize) {
|
||||
if tile.is_walkable() {
|
||||
for tile in map.get_available_exits(p.0 as usize, p.1 as usize) {
|
||||
let mut should_push = true;
|
||||
let shape_pos = Isometry2::new(
|
||||
Vector2::new(tile.0 as f32 + 0.5, tile.1 as f32 + 0.5),
|
||||
0.,
|
||||
);
|
||||
query_pipeline.intersections_with_shape(
|
||||
&rigid_body_set,
|
||||
&collider_set,
|
||||
&shape_pos,
|
||||
&*shape.raw,
|
||||
bevy_rapier2d::rapier::pipeline::QueryFilter::new()
|
||||
.predicate(&|h, _c| h != initiator),
|
||||
|_handle| {
|
||||
should_push = false;
|
||||
false
|
||||
},
|
||||
);
|
||||
if should_push {
|
||||
successors
|
||||
.push(((tile.0 as i32, tile.1 as i32), (tile.2 * 100.) as u32));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -261,6 +268,6 @@ impl<D: 'static + Clone + Default + Send + Sync> Plugin for PathfindingPlugin<D>
|
|||
app.add_system(calculate_path::<D>)
|
||||
.add_system_to_stage(CoreStage::PostUpdate, remove_destination)
|
||||
.add_system(poll_tasks)
|
||||
.add_system(negotiate_path);
|
||||
.add_system(negotiate_path.after(crate::navigation::limit_speed));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user