40 lines
982 B
Rust
40 lines
982 B
Rust
|
use super::Boid;
|
||
|
use bevy::prelude::*;
|
||
|
|
||
|
pub(crate) fn boid_border_teleport(
|
||
|
mut boids: Query<&mut Transform, With<Boid>>,
|
||
|
windows: Query<&Window>,
|
||
|
) {
|
||
|
let window = windows.get_single().unwrap();
|
||
|
let width = window.resolution.width();
|
||
|
let height = window.resolution.height();
|
||
|
|
||
|
let half_width = width / 2.;
|
||
|
let half_height = height / 2.;
|
||
|
|
||
|
let left_bound = -half_width;
|
||
|
let right_bound = half_width;
|
||
|
let top_bound = half_height;
|
||
|
let bottom_bound = -half_height;
|
||
|
|
||
|
for mut boid_transform in &mut boids {
|
||
|
let translation = &mut boid_transform.translation;
|
||
|
|
||
|
if translation.y > top_bound {
|
||
|
translation.y = bottom_bound;
|
||
|
}
|
||
|
|
||
|
if translation.y < bottom_bound {
|
||
|
translation.y = top_bound;
|
||
|
}
|
||
|
|
||
|
if translation.x < left_bound {
|
||
|
translation.x = right_bound;
|
||
|
}
|
||
|
|
||
|
if translation.x > right_bound {
|
||
|
translation.x = left_bound;
|
||
|
}
|
||
|
}
|
||
|
}
|