add off_map

This commit is contained in:
Astro 2022-01-15 20:13:01 +01:00
parent c8391f34f2
commit 3226bbc411
3 changed files with 21 additions and 0 deletions

View File

@ -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();

17
src/off_map.rs Normal file
View File

@ -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<CanFallOffMap>>,
) {
for (entity, transform) in entities.iter() {
if transform.translation.y < MIN_Y {
commands.entity(entity).despawn_recursive();
}
}
}

View File

@ -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)