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"
|
||||||
|
|
21
src/map.rs
21
src/map.rs
|
@ -196,13 +196,14 @@ 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
|
||||||
|
.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(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)
|
.insert(MapObstruction)
|
||||||
.id();
|
.id();
|
||||||
if tile.blocks_visibility() {
|
if tile.blocks_visibility() {
|
||||||
|
@ -212,21 +213,21 @@ fn spawn_colliders<D: 'static + Clone + Default + Send + Sync>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for room in &map.rooms {
|
for room in &map.rooms {
|
||||||
let shape = Collider::cuboid((room.width() / 2) as f32, (room.height() / 2) as f32);
|
let shape = Collider::cuboid((room.width() / 2) as f32, (room.height() / 2) as f32);
|
||||||
let position =
|
let position =
|
||||||
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,11 +48,13 @@ 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) {
|
||||||
|
if tile.is_walkable() {
|
||||||
for tile in map.get_available_exits(p.0 as usize, p.1 as usize) {
|
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.push(((tile.0 as i32, tile.1 as i32), (tile.2 * 100.) as u32));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
successors
|
successors
|
||||||
},
|
},
|
||||||
|p| (p.distance_squared(destination) * 100.) as u32,
|
|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(),
|
&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) {
|
||||||
|
if tile.is_walkable() {
|
||||||
for tile in map.get_available_exits(p.0 as usize, p.1 as usize) {
|
for tile in map.get_available_exits(p.0 as usize, p.1 as usize) {
|
||||||
let mut should_push = true;
|
let mut should_push = true;
|
||||||
let shape_pos =
|
let shape_pos = Isometry2::new(
|
||||||
Isometry2::new(Vector2::new(tile.0 as f32 + 0.5, tile.1 as f32 + 0.5), 0.);
|
Vector2::new(tile.0 as f32 + 0.5, tile.1 as f32 + 0.5),
|
||||||
|
0.,
|
||||||
|
);
|
||||||
query_pipeline.intersections_with_shape(
|
query_pipeline.intersections_with_shape(
|
||||||
&rigid_body_set,
|
&rigid_body_set,
|
||||||
&collider_set,
|
&collider_set,
|
||||||
|
@ -92,7 +97,9 @@ fn find_path_for_shape<D: 'static + Clone + Default + Send + Sync>(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if should_push {
|
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>)
|
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