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"
|
||||
|
|
21
src/map.rs
21
src/map.rs
|
@ -196,13 +196,14 @@ 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 let Some(tile) = map.at(x, y) {
|
||||
if tile.blocks_motion() {
|
||||
let id = commands
|
||||
.spawn()
|
||||
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(Transform::from_xyz(x as f32 + 0.5, y as f32 + 0.5, 0.))
|
||||
.insert(GlobalTransform::default())
|
||||
.insert(MapObstruction)
|
||||
.id();
|
||||
if tile.blocks_visibility() {
|
||||
|
@ -212,21 +213,21 @@ fn spawn_colliders<D: 'static + Clone + Default + Send + Sync>(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for room in &map.rooms {
|
||||
let shape = Collider::cuboid((room.width() / 2) as f32, (room.height() / 2) as f32);
|
||||
let position =
|
||||
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,11 +48,13 @@ 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() {
|
||||
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
|
||||
},
|
||||
|p| (p.distance_squared(destination) * 100.) as u32,
|
||||
|
@ -74,11 +76,14 @@ 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() {
|
||||
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.);
|
||||
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,
|
||||
|
@ -92,7 +97,9 @@ fn find_path_for_shape<D: 'static + Clone + Default + Send + Sync>(
|
|||
},
|
||||
);
|
||||
if should_push {
|
||||
successors.push(((tile.0 as i32, tile.1 as i32), (tile.2 * 100.) as u32));
|
||||
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