Replicate explosion effects (#56)
This commit is contained in:
@@ -1,21 +1,19 @@
|
||||
use crate::{
|
||||
GameState,
|
||||
abilities::TriggerCurver,
|
||||
billboards::Billboard,
|
||||
abilities::{BuildExplosionSprite, TriggerCurver},
|
||||
heads_database::HeadsDatabase,
|
||||
hitpoints::Hit,
|
||||
loading_assets::GameAssets,
|
||||
physics_layers::GameLayer,
|
||||
protocol::GltfSceneRoot,
|
||||
tb_entities::EnemySpawn,
|
||||
utils::{
|
||||
auto_rotate::AutoRotation, commands::CommandExt, global_observer,
|
||||
sprite_3d_animation::AnimationTimer,
|
||||
auto_rotate::AutoRotation,
|
||||
commands::{CommandExt, EntityCommandExt},
|
||||
global_observer,
|
||||
},
|
||||
};
|
||||
use avian3d::prelude::*;
|
||||
use bevy::{pbr::NotShadowCaster, prelude::*};
|
||||
use bevy_sprite3d::{Sprite3dBuilder, Sprite3dParams};
|
||||
use bevy::prelude::*;
|
||||
use lightyear::prelude::{NetworkTarget, Replicate};
|
||||
use std::f32::consts::PI;
|
||||
|
||||
@@ -27,14 +25,7 @@ struct CurverProjectile {
|
||||
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, enemy_hit).run_if(in_state(GameState::Playing)),
|
||||
@@ -47,16 +38,6 @@ pub fn plugin(app: &mut App) {
|
||||
global_observer!(app, on_trigger_missile);
|
||||
}
|
||||
|
||||
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_missile(
|
||||
trigger: Trigger<TriggerCurver>,
|
||||
mut commands: Commands,
|
||||
@@ -156,8 +137,6 @@ fn shot_collision(
|
||||
mut collision_event_reader: EventReader<CollisionStarted>,
|
||||
query_shot: Query<&Transform, With<CurverProjectile>>,
|
||||
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) {
|
||||
@@ -180,27 +159,10 @@ fn shot_collision(
|
||||
continue;
|
||||
}
|
||||
|
||||
let texture_atlas = TextureAtlas {
|
||||
layout: assets.layout.clone(),
|
||||
index: 0,
|
||||
};
|
||||
|
||||
commands
|
||||
.spawn(
|
||||
Sprite3dBuilder {
|
||||
image: assets.image.clone(),
|
||||
pixels_per_metre: 128.,
|
||||
alpha_mode: AlphaMode::Blend,
|
||||
unlit: true,
|
||||
..default()
|
||||
}
|
||||
.bundle_with_atlas(&mut sprite_params, texture_atlas),
|
||||
)
|
||||
.insert((
|
||||
Billboard::All,
|
||||
Transform::from_translation(shot_pos),
|
||||
NotShadowCaster,
|
||||
AnimationTimer::new(Timer::from_seconds(0.01, TimerMode::Repeating)),
|
||||
));
|
||||
commands.trigger_server(BuildExplosionSprite {
|
||||
pos: shot_pos,
|
||||
pixels_per_meter: 128.,
|
||||
time: 0.01,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
use super::TriggerMissile;
|
||||
use crate::{
|
||||
GameState,
|
||||
billboards::Billboard,
|
||||
abilities::BuildExplosionSprite,
|
||||
heads_database::HeadsDatabase,
|
||||
loading_assets::GameAssets,
|
||||
physics_layers::GameLayer,
|
||||
protocol::GltfSceneRoot,
|
||||
sounds::PlaySound,
|
||||
utils::{
|
||||
commands::CommandExt, explosions::Explosion, global_observer,
|
||||
sprite_3d_animation::AnimationTimer, trail::Trail,
|
||||
commands::{CommandExt, EntityCommandExt},
|
||||
explosions::Explosion,
|
||||
global_observer,
|
||||
trail::Trail,
|
||||
},
|
||||
};
|
||||
use avian3d::prelude::*;
|
||||
use bevy::{pbr::NotShadowCaster, prelude::*};
|
||||
use bevy_sprite3d::{Sprite3dBuilder, Sprite3dParams};
|
||||
use bevy::prelude::*;
|
||||
use lightyear::prelude::{NetworkTarget, Replicate};
|
||||
use std::f32::consts::PI;
|
||||
|
||||
@@ -27,14 +27,7 @@ struct MissileProjectile {
|
||||
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)));
|
||||
app.add_systems(
|
||||
FixedUpdate,
|
||||
@@ -44,16 +37,6 @@ pub fn plugin(app: &mut App) {
|
||||
global_observer!(app, on_trigger_missile);
|
||||
}
|
||||
|
||||
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_missile(
|
||||
trigger: Trigger<TriggerMissile>,
|
||||
mut commands: Commands,
|
||||
@@ -144,8 +127,6 @@ fn shot_collision(
|
||||
mut collision_event_reader: EventReader<CollisionStarted>,
|
||||
query_shot: Query<(&MissileProjectile, &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) {
|
||||
@@ -175,27 +156,10 @@ fn shot_collision(
|
||||
radius: 6.,
|
||||
});
|
||||
|
||||
let texture_atlas = TextureAtlas {
|
||||
layout: assets.layout.clone(),
|
||||
index: 0,
|
||||
};
|
||||
|
||||
commands
|
||||
.spawn(
|
||||
Sprite3dBuilder {
|
||||
image: assets.image.clone(),
|
||||
pixels_per_metre: 16.,
|
||||
alpha_mode: AlphaMode::Blend,
|
||||
unlit: true,
|
||||
..default()
|
||||
}
|
||||
.bundle_with_atlas(&mut sprite_params, texture_atlas),
|
||||
)
|
||||
.insert((
|
||||
Billboard::All,
|
||||
Transform::from_translation(shot_pos),
|
||||
NotShadowCaster,
|
||||
AnimationTimer::new(Timer::from_seconds(0.01, TimerMode::Repeating)),
|
||||
));
|
||||
commands.trigger_server(BuildExplosionSprite {
|
||||
pos: shot_pos,
|
||||
pixels_per_meter: 16.,
|
||||
time: 0.01,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
mod arrow;
|
||||
mod curver;
|
||||
mod gun;
|
||||
mod healing;
|
||||
mod missile;
|
||||
mod thrown;
|
||||
pub mod arrow;
|
||||
pub mod curver;
|
||||
pub mod gun;
|
||||
pub mod healing;
|
||||
pub mod missile;
|
||||
pub mod thrown;
|
||||
|
||||
use crate::{
|
||||
GameState,
|
||||
@@ -13,11 +13,14 @@ use crate::{
|
||||
head::ActiveHead,
|
||||
heads::ActiveHeads,
|
||||
heads_database::HeadsDatabase,
|
||||
loading_assets::GameAssets,
|
||||
physics_layers::GameLayer,
|
||||
player::{Player, PlayerBodyMesh},
|
||||
sounds::PlaySound,
|
||||
utils::{billboards::Billboard, sprite_3d_animation::AnimationTimer},
|
||||
};
|
||||
use bevy::prelude::*;
|
||||
use bevy::{pbr::NotShadowCaster, prelude::*};
|
||||
use bevy_sprite3d::{Sprite3dBuilder, Sprite3dParams};
|
||||
pub use healing::Healing;
|
||||
use healing::HealingStateChanged;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -109,12 +112,14 @@ pub fn plugin(app: &mut App) {
|
||||
app.add_plugins(healing::plugin);
|
||||
app.add_plugins(curver::plugin);
|
||||
|
||||
app.add_systems(OnEnter(GameState::Playing), setup);
|
||||
app.add_systems(
|
||||
Update,
|
||||
(update, update_heal_ability).run_if(in_state(GameState::Playing)),
|
||||
);
|
||||
|
||||
global_observer!(app, on_trigger_state);
|
||||
global_observer!(app, build_explosion_sprite);
|
||||
}
|
||||
|
||||
fn on_trigger_state(
|
||||
@@ -222,3 +227,57 @@ fn update_heal_ability(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
struct ShotAssets {
|
||||
image: Handle<Image>,
|
||||
layout: Handle<TextureAtlasLayout>,
|
||||
}
|
||||
|
||||
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,
|
||||
});
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Event, Serialize, Deserialize, PartialEq)]
|
||||
pub struct BuildExplosionSprite {
|
||||
pos: Vec3,
|
||||
pixels_per_meter: f32,
|
||||
time: f32,
|
||||
}
|
||||
|
||||
fn build_explosion_sprite(
|
||||
trigger: Trigger<BuildExplosionSprite>,
|
||||
mut commands: Commands,
|
||||
assets: Res<ShotAssets>,
|
||||
mut sprite_params: Sprite3dParams,
|
||||
) {
|
||||
commands.spawn((
|
||||
Transform::from_translation(trigger.event().pos),
|
||||
Sprite3dBuilder {
|
||||
image: assets.image.clone(),
|
||||
pixels_per_metre: trigger.event().pixels_per_meter,
|
||||
alpha_mode: AlphaMode::Blend,
|
||||
unlit: true,
|
||||
..default()
|
||||
}
|
||||
.bundle_with_atlas(
|
||||
&mut sprite_params,
|
||||
TextureAtlas {
|
||||
layout: assets.layout.clone(),
|
||||
index: 0,
|
||||
},
|
||||
),
|
||||
Billboard::All,
|
||||
NotShadowCaster,
|
||||
AnimationTimer::new(Timer::from_seconds(
|
||||
trigger.event().time,
|
||||
TimerMode::Repeating,
|
||||
)),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user