unify explosion handling

This commit is contained in:
2025-06-09 22:02:17 +02:00
parent 69e112082a
commit 59c5b1f808
5 changed files with 51 additions and 73 deletions

View File

@@ -3,11 +3,12 @@ use crate::{
GameState,
billboards::Billboard,
heads_database::HeadsDatabase,
hitpoints::Hit,
loading_assets::GameAssets,
physics_layers::GameLayer,
sounds::PlaySound,
utils::{global_observer, sprite_3d_animation::AnimationTimer, trail::Trail},
utils::{
explosions::Explosion, global_observer, sprite_3d_animation::AnimationTimer, trail::Trail,
},
};
use avian3d::prelude::*;
use bevy::{pbr::NotShadowCaster, prelude::*};
@@ -22,13 +23,6 @@ struct MissileProjectile {
damage: u32,
}
#[derive(Event, Debug)]
struct Explosion {
position: Vec3,
radius: f32,
damage: u32,
}
#[derive(Resource)]
struct ShotAssets {
image: Handle<Image>,
@@ -44,33 +38,6 @@ pub fn plugin(app: &mut App) {
);
global_observer!(app, on_trigger_missile);
global_observer!(app, on_explosion);
}
fn on_explosion(
explosion: Trigger<Explosion>,
mut commands: Commands,
spatial_query: SpatialQuery,
) {
let explosion = explosion.event();
let intersections = {
spatial_query.shape_intersections(
&Collider::sphere(explosion.radius),
explosion.position,
Quat::default(),
&SpatialQueryFilter::default().with_mask(LayerMask(
GameLayer::Npc.to_bits() | GameLayer::Player.to_bits(),
)),
)
};
for entity in intersections.iter() {
if let Ok(mut e) = commands.get_entity(*entity) {
e.trigger(Hit {
damage: explosion.damage,
});
}
}
}
fn setup(mut commands: Commands, assets: Res<GameAssets>, mut sprite_params: Sprite3dParams) {