diff --git a/src/pathfinding.rs b/src/pathfinding.rs index b5b2631..8be2ce6 100644 --- a/src/pathfinding.rs +++ b/src/pathfinding.rs @@ -11,6 +11,7 @@ use bevy_rapier2d::{ }; use derive_more::{Deref, DerefMut}; use futures_lite::future; +use mapgen::Tile; use pathfinding::prelude::*; use crate::{ @@ -45,8 +46,10 @@ pub fn find_path( &start.into(), |p| { let mut successors: Vec<((i32, i32), u32)> = vec![]; - 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 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)); + } } successors }, @@ -147,22 +150,24 @@ fn find_path_for_shape( &start.i32(), |p| { let mut successors: Vec<((i32, i32), u32)> = vec![]; - for tile in map.get_available_exits(p.0 as usize, p.1 as usize) { - let mut should_push = true; - let shape_pos = Isometry::new(vector![tile.0 as f32, tile.1 as f32], 0.); - query_pipeline.intersections_with_shape( - &collider_set, - &shape_pos, - &**shape, - InteractionGroups::all(), - Some(&|v| v.entity() != 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 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 = Isometry::new(vector![tile.0 as f32, tile.1 as f32], 0.); + query_pipeline.intersections_with_shape( + &collider_set, + &shape_pos, + &**shape, + InteractionGroups::all(), + Some(&|v| v.entity() != initiator), + |_handle| { + should_push = false; + false + }, + ); + if should_push { + successors.push(((tile.0 as i32, tile.1 as i32), (tile.2 * 100.) as u32)); + } } } successors @@ -193,7 +198,8 @@ fn calculate_path( .remove::() .remove::() .remove::() - .remove::(); + .remove::() + .remove::(); continue; } for map in map.iter() { @@ -280,7 +286,8 @@ fn negotiate_path( continue; } } else { - commands.entity(entity).remove::(); + println!("Remove path1"); + commands.entity(entity).remove::().remove::(); velocity.linvel = Vec2::ZERO.into(); } **path = new_path; @@ -302,10 +309,13 @@ fn negotiate_path( velocity.linvel = direction.into(); } else { velocity.linvel = Vec2::ZERO.into(); + println!("Remove path2"); commands .entity(entity) .remove::() - .remove::(); + .remove::() + .remove::() + .remove::(); } } }