45 lines
1.1 KiB
Rust
45 lines
1.1 KiB
Rust
|
use bevy::{color::palettes::css::RED, prelude::*};
|
||
|
|
||
|
use crate::common::velocity::VelocityPlugin;
|
||
|
|
||
|
pub struct EnemyPlugin;
|
||
|
|
||
|
impl Plugin for EnemyPlugin {
|
||
|
fn build(&self, app: &mut App) {
|
||
|
// app.add_systems(Startup, setup);
|
||
|
app.add_systems(Update, debug_direction);
|
||
|
app.add_systems(FixedUpdate, outside_bounds);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#[derive(Component)]
|
||
|
pub struct Enemy;
|
||
|
|
||
|
fn debug_direction(query: Query<&Transform, With<Enemy>>, mut gizmos: Gizmos) {
|
||
|
for enemy in &query {
|
||
|
// let start = enemy.translation.truncate();
|
||
|
// let end = enemy.rotation.xyz().truncate() - start;
|
||
|
// gizmos.arrow_2d(start, end, RED);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn outside_bounds(
|
||
|
enemies: Query<(Entity, &Transform), With<Enemy>>,
|
||
|
window: Query<&Window>,
|
||
|
mut commands: Commands,
|
||
|
) {
|
||
|
let window = window.single();
|
||
|
let screen_size: Vec3 = window.physical_size().as_vec2().extend(1.0);
|
||
|
|
||
|
for (entity, transform) in &enemies {
|
||
|
let pos = transform.translation.truncate();
|
||
|
if pos.x < -60.0
|
||
|
|| pos.y < -60.0
|
||
|
|| pos.x > screen_size.x + 60.0
|
||
|
|| pos.y > screen_size.y + 60.0
|
||
|
{
|
||
|
commands.entity(entity).despawn();
|
||
|
}
|
||
|
}
|
||
|
}
|