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"
|
coord_2d = "0.3"
|
||||||
futures-lite = "1"
|
futures-lite = "1"
|
||||||
gilrs = "0.9"
|
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" }
|
leafwing_input_manager = { git = "https://github.com/leafwing-studios/leafwing-input-manager", branch = "dev" }
|
||||||
maze_generator = "2"
|
maze_generator = "2"
|
||||||
once_cell = "1"
|
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);
|
.insert(RigidBody::Fixed);
|
||||||
for y in 0..map.height {
|
for y in 0..map.height {
|
||||||
for x in 0..map.width {
|
for x in 0..map.width {
|
||||||
let tile = map.at(x, y);
|
if let Some(tile) = map.at(x, y) {
|
||||||
if tile.blocks_motion() {
|
if tile.blocks_motion() {
|
||||||
let id = commands
|
let id =
|
||||||
.spawn()
|
commands
|
||||||
.insert(Collider::cuboid(0.5, 0.5))
|
.spawn_bundle(TransformBundle::from_transform(
|
||||||
.insert(Transform::from_xyz(x as f32 + 0.5, y as f32 + 0.5, 0.))
|
Transform::from_xyz(x as f32 + 0.5, y as f32 + 0.5, 0.),
|
||||||
.insert(GlobalTransform::default())
|
))
|
||||||
.insert(MapObstruction)
|
.insert(Collider::cuboid(0.5, 0.5))
|
||||||
.id();
|
.insert(MapObstruction)
|
||||||
if tile.blocks_visibility() {
|
.id();
|
||||||
commands.entity(id).insert(Visible::opaque());
|
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.);
|
Isometry2::new(Vector2::new(room.center().x(), room.center().y()), 0.);
|
||||||
let aabb = shape.raw.compute_aabb(&position);
|
let aabb = shape.raw.compute_aabb(&position);
|
||||||
let id = commands
|
let id = commands
|
||||||
.spawn()
|
.spawn_bundle(TransformBundle::from_transform(Transform::from_xyz(
|
||||||
.insert(shape)
|
|
||||||
.insert(Sensor)
|
|
||||||
.insert(ActiveEvents::COLLISION_EVENTS)
|
|
||||||
.insert_bundle(TransformBundle::from_transform(Transform::from_xyz(
|
|
||||||
position.translation.x,
|
position.translation.x,
|
||||||
position.translation.y,
|
position.translation.y,
|
||||||
0.,
|
0.,
|
||||||
)))
|
)))
|
||||||
|
.insert(shape)
|
||||||
|
.insert(Sensor)
|
||||||
|
.insert(ActiveEvents::COLLISION_EVENTS)
|
||||||
.insert(Area(aabb))
|
.insert(Area(aabb))
|
||||||
.insert(Zone)
|
.insert(Zone)
|
||||||
.id();
|
.id();
|
||||||
|
|
|
@ -48,9 +48,11 @@ pub fn find_path<D: 'static + Clone + Default + Send + Sync>(
|
||||||
&start.into(),
|
&start.into(),
|
||||||
|p| {
|
|p| {
|
||||||
let mut successors: Vec<((i32, i32), u32)> = vec![];
|
let mut successors: Vec<((i32, i32), u32)> = vec![];
|
||||||
if map.at(p.0 as usize, p.1 as usize).is_walkable() {
|
if let Some(tile) = map.at(p.0 as usize, p.1 as usize) {
|
||||||
for tile in map.get_available_exits(p.0 as usize, p.1 as usize) {
|
if tile.is_walkable() {
|
||||||
successors.push(((tile.0 as i32, tile.1 as i32), (tile.2 * 100.) as u32));
|
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
|
successors
|
||||||
|
@ -74,25 +76,30 @@ fn find_path_for_shape<D: 'static + Clone + Default + Send + Sync>(
|
||||||
&start.i32(),
|
&start.i32(),
|
||||||
|p| {
|
|p| {
|
||||||
let mut successors: Vec<((i32, i32), u32)> = vec![];
|
let mut successors: Vec<((i32, i32), u32)> = vec![];
|
||||||
if map.at(p.0 as usize, p.1 as usize).is_walkable() {
|
if let Some(tile) = map.at(p.0 as usize, p.1 as usize) {
|
||||||
for tile in map.get_available_exits(p.0 as usize, p.1 as usize) {
|
if tile.is_walkable() {
|
||||||
let mut should_push = true;
|
for tile in map.get_available_exits(p.0 as usize, p.1 as usize) {
|
||||||
let shape_pos =
|
let mut should_push = true;
|
||||||
Isometry2::new(Vector2::new(tile.0 as f32 + 0.5, tile.1 as f32 + 0.5), 0.);
|
let shape_pos = Isometry2::new(
|
||||||
query_pipeline.intersections_with_shape(
|
Vector2::new(tile.0 as f32 + 0.5, tile.1 as f32 + 0.5),
|
||||||
&rigid_body_set,
|
0.,
|
||||||
&collider_set,
|
);
|
||||||
&shape_pos,
|
query_pipeline.intersections_with_shape(
|
||||||
&*shape.raw,
|
&rigid_body_set,
|
||||||
bevy_rapier2d::rapier::pipeline::QueryFilter::new()
|
&collider_set,
|
||||||
.predicate(&|h, _c| h != initiator),
|
&shape_pos,
|
||||||
|_handle| {
|
&*shape.raw,
|
||||||
should_push = false;
|
bevy_rapier2d::rapier::pipeline::QueryFilter::new()
|
||||||
false
|
.predicate(&|h, _c| h != initiator),
|
||||||
},
|
|_handle| {
|
||||||
);
|
should_push = false;
|
||||||
if should_push {
|
false
|
||||||
successors.push(((tile.0 as i32, tile.1 as i32), (tile.2 * 100.) as u32));
|
},
|
||||||
|
);
|
||||||
|
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>)
|
app.add_system(calculate_path::<D>)
|
||||||
.add_system_to_stage(CoreStage::PostUpdate, remove_destination)
|
.add_system_to_stage(CoreStage::PostUpdate, remove_destination)
|
||||||
.add_system(poll_tasks)
|
.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