Replicate explosion effects (#56)

This commit is contained in:
PROMETHIA-27
2025-07-13 18:24:34 -04:00
committed by GitHub
parent d4bea5a7ac
commit 0e8b0bb677
8 changed files with 196 additions and 159 deletions

View File

@@ -1,21 +1,21 @@
use super::TriggerThrow;
use crate::{
GameState,
billboards::Billboard,
abilities::BuildExplosionSprite,
heads_database::HeadsDatabase,
loading_assets::GameAssets,
physics_layers::GameLayer,
protocol::GltfSceneRoot,
sounds::PlaySound,
utils::{
auto_rotate::AutoRotation, commands::CommandExt, explosions::Explosion, global_observer,
sprite_3d_animation::AnimationTimer,
auto_rotate::AutoRotation,
commands::{CommandExt, EntityCommandExt},
explosions::Explosion,
global_observer,
},
};
use avian3d::prelude::*;
use bevy::{pbr::NotShadowCaster, prelude::*};
use bevy::prelude::*;
use bevy_ballistic::launch_velocity;
use bevy_sprite3d::{Sprite3dBuilder, Sprite3dParams};
use lightyear::prelude::{NetworkTarget, Replicate};
use serde::{Deserialize, Serialize};
use std::f32::consts::PI;
@@ -26,29 +26,12 @@ pub struct ThrownProjectile {
damage: u32,
}
#[derive(Resource)]
struct ShotAssets {
image: Handle<Image>,
layout: Handle<TextureAtlasLayout>,
}
pub fn plugin(app: &mut App) {
app.add_systems(OnEnter(GameState::Playing), setup);
app.add_systems(Update, shot_collision.run_if(in_state(GameState::Playing)));
global_observer!(app, on_trigger_thrown);
}
fn setup(mut commands: Commands, assets: Res<GameAssets>, mut sprite_params: Sprite3dParams) {
let layout = TextureAtlasLayout::from_grid(UVec2::splat(256), 7, 6, None, None);
let texture_atlas_layout = sprite_params.atlas_layouts.add(layout);
commands.insert_resource(ShotAssets {
image: assets.impact_atlas.clone(),
layout: texture_atlas_layout,
});
}
fn on_trigger_thrown(
trigger: Trigger<TriggerThrow>,
mut commands: Commands,
@@ -113,8 +96,6 @@ fn shot_collision(
mut collision_event_reader: EventReader<CollisionStarted>,
query_shot: Query<(&ThrownProjectile, &Transform)>,
sensors: Query<(), With<Sensor>>,
assets: Res<ShotAssets>,
mut sprite_params: Sprite3dParams,
) {
for CollisionStarted(e1, e2) in collision_event_reader.read() {
if !query_shot.contains(*e1) && !query_shot.contains(*e2) {
@@ -156,29 +137,11 @@ fn shot_collision(
//TODO: support different impact animations
if animation {
commands
.spawn(
Sprite3dBuilder {
image: assets.image.clone(),
pixels_per_metre: 32.,
alpha_mode: AlphaMode::Blend,
unlit: true,
..default()
}
.bundle_with_atlas(
&mut sprite_params,
TextureAtlas {
layout: assets.layout.clone(),
index: 0,
},
),
)
.insert((
Billboard::All,
Transform::from_translation(shot_pos),
NotShadowCaster,
AnimationTimer::new(Timer::from_seconds(0.02, TimerMode::Repeating)),
));
commands.trigger_server(BuildExplosionSprite {
pos: shot_pos,
pixels_per_meter: 32.,
time: 0.02,
});
}
}
}