diff --git a/Cargo.toml b/Cargo.toml index 030945b..fc7a987 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/map.rs b/src/map.rs index 4d9e228..b97e6f2 100644 --- a/src/map.rs +++ b/src/map.rs @@ -196,19 +196,21 @@ fn spawn_colliders( .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( 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(); diff --git a/src/pathfinding.rs b/src/pathfinding.rs index fb234ad..9e5b1e8 100644 --- a/src/pathfinding.rs +++ b/src/pathfinding.rs @@ -48,9 +48,11 @@ pub fn find_path( &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( &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 Plugin for PathfindingPlugin app.add_system(calculate_path::) .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)); } }