File size: 1,230 Bytes
48ca417 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
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<IntGridCell> 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()
}
}
}
|