diff --git a/src/main.rs b/src/main.rs index 26d35cb..5af82fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ mod input; mod camera; mod map; mod player; +mod off_map; #[derive(PhysicsLayer)] pub enum Layer { @@ -33,6 +34,7 @@ fn main() { .add_system(map::collide) .add_system(player::spawn_player) .add_system(player::input.after("input")) + .add_system(off_map::check) .add_system(exit_on_escape) // .add_system(log_collisions) .run(); diff --git a/src/off_map.rs b/src/off_map.rs new file mode 100644 index 0000000..38671d2 --- /dev/null +++ b/src/off_map.rs @@ -0,0 +1,17 @@ +use bevy::prelude::*; + +#[derive(Component)] +pub struct CanFallOffMap; + +const MIN_Y: f32 = -20.0; + +pub fn check( + mut commands: Commands, + entities: Query<(Entity, &Transform), With>, +) { + for (entity, transform) in entities.iter() { + if transform.translation.y < MIN_Y { + commands.entity(entity).despawn_recursive(); + } + } +} diff --git a/src/player.rs b/src/player.rs index 50718d0..f4de0ba 100644 --- a/src/player.rs +++ b/src/player.rs @@ -5,6 +5,7 @@ use rand::prelude::*; use crate::{ input::{InputState, Key, Source as InputSource}, map::GroundContact, + off_map::CanFallOffMap, Layer, }; @@ -63,6 +64,7 @@ pub fn spawn_player( input_source: input_source.clone(), rotation: 0.0, }) + .insert(CanFallOffMap) .insert(GroundContact::default()) .insert(GlobalTransform::default()) .insert(transform)