r/o
1
use bevy::prelude::*;
2
3
use crate::{WINDOW_HEIGHT, WINDOW_WIDTH, WINDOW_WRAP_OVERSHOOT};
4
5
#[derive(Component)]
6
pub(crate) struct ScreenEdge(pub(crate) EdgeBehaviour);
7
8
#[derive(PartialEq)]
9
pub(crate) enum EdgeBehaviour {
10
Wraps,
11
Despawns,
12
}
13
14
pub(crate) fn check_edges(
15
mut commands: Commands,
16
mut query: Query<(Entity, &mut Transform, &ScreenEdge)>,
17
) {
18
for (entity, mut transform, ScreenEdge(edge_behaviour)) in &mut query {
19
let mut wrapped = false;
20
if transform.translation.x > WINDOW_WIDTH / 2.0 + WINDOW_WRAP_OVERSHOOT {
21
transform.translation.x -= WINDOW_WIDTH + WINDOW_WRAP_OVERSHOOT * 2.0;
22
wrapped = true;
23
}
24
if transform.translation.x < -(WINDOW_WIDTH / 2.0 + WINDOW_WRAP_OVERSHOOT) {
25
transform.translation.x += WINDOW_WIDTH + WINDOW_WRAP_OVERSHOOT * 2.0;
26
wrapped = true;
27
}
28
if transform.translation.y > WINDOW_HEIGHT / 2.0 + WINDOW_WRAP_OVERSHOOT {
29
transform.translation.y -= WINDOW_HEIGHT + WINDOW_WRAP_OVERSHOOT * 2.0;
30
wrapped = true;
31
}
32
if transform.translation.y < -(WINDOW_HEIGHT / 2.0 + WINDOW_WRAP_OVERSHOOT) {
33
transform.translation.y += WINDOW_HEIGHT + WINDOW_WRAP_OVERSHOOT * 2.0;
34
wrapped = true;
35
}
36
if wrapped && *edge_behaviour == EdgeBehaviour::Despawns {
37
commands.entity(entity).despawn();
38
}
39
}
40
}
41