use bevy::ecs::bundle::Bundle; use bevy_ecs_ldtk::{ IntGridCell, LdtkIntCell }; use bevy_rapier2d::{ dynamics::LockedAxes, geometry::{ ActiveEvents, Collider, Sensor } }; #[derive(Clone, Default, Bundle, LdtkIntCell)] pub struct SensorBundle { pub collider: Collider, pub sensor: Sensor, pub active_events: ActiveEvents, pub rotation_constraints: LockedAxes, } impl From for SensorBundle { fn from(int_grid_cell: IntGridCell) -> SensorBundle { let rotation_constraints = LockedAxes::ROTATION_LOCKED; // Ladder if int_grid_cell.value == 2 { SensorBundle { collider: Collider::cuboid(8.0, 8.0), sensor: Sensor, rotation_constraints, active_events: ActiveEvents::COLLISION_EVENTS, } // Water } else if int_grid_cell.value == 4 { SensorBundle { collider: Collider::cuboid(8.0, 8.0), sensor: Sensor, rotation_constraints, active_events: ActiveEvents::COLLISION_EVENTS, } } else { SensorBundle::default() } } }