add off_map

master
Astro 1 year ago
parent c8391f34f2
commit 3226bbc411

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

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

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

Loading…
Cancel
Save