Skip to content

Commit

Permalink
Add VFX and SFX to throw techs
Browse files Browse the repository at this point in the history
  • Loading branch information
haihala committed Aug 27, 2024
1 parent 7059902 commit e2a8331
Show file tree
Hide file tree
Showing 23 changed files with 148 additions and 39 deletions.
11 changes: 9 additions & 2 deletions client/lib/src/assets/loaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use wag_core::{Animation, Icon, Model, SoundEffect, VisualEffect};

use super::{
animations::animation_paths,
materials::{BlockEffectMaterial, ClashSparkMaterial, HitSparkMaterial},
materials::{BlockEffectMaterial, ClashSparkMaterial, HitSparkMaterial, RingRippleMaterial},
models::model_paths,
sounds::Sounds,
Animations, AssetsLoading, Fonts, Icons, Models, Vfx,
Expand Down Expand Up @@ -107,23 +107,30 @@ pub fn vfx(
mut clash_spark_materials: ResMut<Assets<ClashSparkMaterial>>,
mut block_effect_materials: ResMut<Assets<BlockEffectMaterial>>,
mut hit_spark_materials: ResMut<Assets<HitSparkMaterial>>,
mut ring_ripple_materials: ResMut<Assets<RingRippleMaterial>>,
) {
let mesh_handles = vec![
(VisualEffect::Block, meshes.add(Rectangle::new(1.1, 2.0))),
(VisualEffect::Hit, meshes.add(Rectangle::new(1.5, 1.5))),
(VisualEffect::Hit, meshes.add(Rectangle::new(1.1, 1.1))),
(VisualEffect::Clash, meshes.add(Rectangle::new(1.5, 1.5))),
(
VisualEffect::ThrowTech,
meshes.add(Rectangle::new(2.0, 2.0)),
),
]
.into_iter()
.collect();

let clash_spark_material = clash_spark_materials.add(ClashSparkMaterial::default());
let block_effect_material = block_effect_materials.add(BlockEffectMaterial::default());
let hit_spark_material = hit_spark_materials.add(HitSparkMaterial::default());
let throw_tech_material = ring_ripple_materials.add(RingRippleMaterial::default());

commands.insert_resource(Vfx::new(
mesh_handles,
clash_spark_material,
block_effect_material,
hit_spark_material,
throw_tech_material,
));
}
41 changes: 41 additions & 0 deletions client/lib/src/assets/materials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use characters::FlashRequest;
use wag_core::{
BLOCK_EFFECT_BASE_COLOR, BLOCK_EFFECT_EDGE_COLOR, CLASH_SPARK_BASE_COLOR,
CLASH_SPARK_EDGE_COLOR, HIT_SPARK_BASE_COLOR, HIT_SPARK_EDGE_COLOR, HIT_SPARK_MID_COLOR,
RING_RIPPLE_BASE_COLOR, RING_RIPPLE_EDGE_COLOR,
};

#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
Expand Down Expand Up @@ -122,6 +123,46 @@ impl Material for ClashSparkMaterial {
}
}

#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
pub struct RingRippleMaterial {
#[uniform(0)]
base_color: LinearRgba,
#[uniform(1)]
edge_color: LinearRgba,
#[uniform(2)]
duration: f32,
#[uniform(3)]
ring_thickness: f32,
#[uniform(4)]
start_time: f32,
}
impl RingRippleMaterial {
pub(crate) fn reset(&mut self, time: f32) {
self.start_time = time;
}
}
impl Default for RingRippleMaterial {
fn default() -> Self {
Self {
edge_color: RING_RIPPLE_EDGE_COLOR.into(),
base_color: RING_RIPPLE_BASE_COLOR.into(),
duration: 0.7,
ring_thickness: 0.05,
start_time: 0.0,
}
}
}

impl Material for RingRippleMaterial {
fn fragment_shader() -> ShaderRef {
"shaders/ring_ripple.wgsl".into()
}

fn alpha_mode(&self) -> AlphaMode {
AlphaMode::Blend
}
}

// Extended Flash Material
pub type ExtendedFlashMaterial = ExtendedMaterial<StandardMaterial, FlashMaterial>;

Expand Down
1 change: 1 addition & 0 deletions client/lib/src/assets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ impl Plugin for AssetsPlugin {
MaterialPlugin::<materials::HitSparkMaterial>::default(),
MaterialPlugin::<materials::BlockEffectMaterial>::default(),
MaterialPlugin::<materials::ClashSparkMaterial>::default(),
MaterialPlugin::<materials::RingRippleMaterial>::default(),
MaterialPlugin::<ExtendedFlashMaterial>::default(),
))
.add_systems(
Expand Down
49 changes: 37 additions & 12 deletions client/lib/src/assets/vfx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ use bevy::{prelude::*, utils::HashMap};

use wag_core::{Clock, GameState, VisualEffect};

use crate::entity_management::{DespawnMarker, LivesInStates};
use crate::entity_management::DespawnMarker;

use super::materials::{BlockEffectMaterial, ClashSparkMaterial, HitSparkMaterial};
use super::materials::{
BlockEffectMaterial, ClashSparkMaterial, HitSparkMaterial, RingRippleMaterial,
};

#[derive(Debug)]
pub struct VfxRequest {
Expand All @@ -19,20 +21,23 @@ pub struct Vfx {
clash_spark_material: Handle<ClashSparkMaterial>,
block_effect_material: Handle<BlockEffectMaterial>,
hit_spark_material: Handle<HitSparkMaterial>,
throw_tech_material: Handle<RingRippleMaterial>,
}
impl Vfx {
pub fn new(
meshes: HashMap<VisualEffect, Handle<Mesh>>,
clash_spark_material: Handle<ClashSparkMaterial>,
block_effect_material: Handle<BlockEffectMaterial>,
hit_spark_material: Handle<HitSparkMaterial>,
throw_tech_material: Handle<RingRippleMaterial>,
) -> Vfx {
Vfx {
meshes,
queue: vec![],
hit_spark_material,
clash_spark_material,
block_effect_material,
throw_tech_material,
}
}

Expand All @@ -41,22 +46,23 @@ impl Vfx {
}
}

#[allow(clippy::too_many_arguments)]
pub fn handle_requests(
mut commands: Commands,
mut particles: ResMut<Vfx>,
mut vfx: ResMut<Vfx>,
clock: Res<Clock>,
time: Res<Time>,
mut block_materials: ResMut<Assets<BlockEffectMaterial>>,
mut clash_materials: ResMut<Assets<ClashSparkMaterial>>,
mut hit_spark_materials: ResMut<Assets<HitSparkMaterial>>,
mut throw_tech_material: ResMut<Assets<RingRippleMaterial>>,
) {
for VfxRequest { effect, position } in particles.queue.drain(..).collect::<Vec<_>>().into_iter()
{
let mesh = particles.meshes.get(&effect).unwrap().clone();
for VfxRequest { effect, position } in vfx.queue.drain(..).collect::<Vec<_>>().into_iter() {
let mesh = vfx.meshes.get(&effect).unwrap().clone();
let transform = Transform::from_translation(position.with_y(position.y.max(0.8)) + Vec3::Z);
match effect {
VisualEffect::Hit => {
let material_handle = particles.hit_spark_material.clone();
let material_handle = vfx.hit_spark_material.clone();

hit_spark_materials
.get_mut(&material_handle)
Expand All @@ -71,11 +77,11 @@ pub fn handle_requests(
..default()
},
DespawnMarker(clock.frame + 10),
LivesInStates(vec![GameState::Combat]),
StateScoped(GameState::Combat),
));
}
VisualEffect::Clash => {
let material_handle = particles.clash_spark_material.clone();
let material_handle = vfx.clash_spark_material.clone();

clash_materials
.get_mut(&material_handle)
Expand All @@ -90,11 +96,11 @@ pub fn handle_requests(
..default()
},
DespawnMarker(clock.frame + 10),
LivesInStates(vec![GameState::Combat]),
StateScoped(GameState::Combat),
));
}
VisualEffect::Block => {
let material_handle = particles.block_effect_material.clone();
let material_handle = vfx.block_effect_material.clone();

block_materials
.get_mut(&material_handle)
Expand All @@ -109,7 +115,26 @@ pub fn handle_requests(
..default()
},
DespawnMarker(clock.frame + 10),
LivesInStates(vec![GameState::Combat]),
StateScoped(GameState::Combat),
));
}
VisualEffect::ThrowTech => {
let material_handle = vfx.throw_tech_material.clone();

throw_tech_material
.get_mut(&material_handle)
.unwrap()
.reset(time.elapsed_seconds());

commands.spawn((
MaterialMeshBundle {
mesh,
transform,
material: material_handle,
..default()
},
DespawnMarker(clock.frame + 60),
StateScoped(GameState::Combat),
));
}
};
Expand Down
4 changes: 2 additions & 2 deletions client/lib/src/damage/hitboxes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use wag_core::{Area, Clock, Facing, GameState, Joints, Owner, Player};

use crate::{
assets::Models,
entity_management::{DespawnMarker, LivesInStates},
entity_management::DespawnMarker,
movement::{ConstantVelocity, Follow},
};

Expand Down Expand Up @@ -67,7 +67,7 @@ impl HitboxSpawner {
Owner(player),
hitbox,
attack.clone(),
LivesInStates(vec![GameState::Combat]),
StateScoped(GameState::Combat),
));

if let Some(velocity) = attack.to_hit.velocity {
Expand Down
4 changes: 2 additions & 2 deletions client/lib/src/damage/hitreg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ pub(super) fn apply_connections(
ConnectionType::Tech | ConnectionType::Stunlock => (
vec![Movement::impulse(Vec2::X * -4.0).into()],
vec![],
SoundEffect::Clash,
VisualEffect::Clash,
SoundEffect::BottleBonk,
VisualEffect::ThrowTech,
true,
),
};
Expand Down
22 changes: 1 addition & 21 deletions client/lib/src/entity_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ pub struct DespawnMarker(pub usize);
#[derive(Debug, Component, Deref)]
pub struct VisibleInStates(pub Vec<GameState>);

#[derive(Debug, Component, Deref)]
pub struct LivesInStates(pub Vec<GameState>);

pub struct EntityManagementPlugin;

impl Plugin for EntityManagementPlugin {
Expand All @@ -18,10 +15,7 @@ impl Plugin for EntityManagementPlugin {
FixedUpdate,
despawn_marked.after(crate::damage::handle_despawn_flags),
)
.add_systems(
Update,
(despawn_on_state_change, update_visibility_on_state_change),
)
.add_systems(Update, update_visibility_on_state_change)
.enable_state_scoped_entities::<GameState>()
.enable_state_scoped_entities::<InMenu>()
.enable_state_scoped_entities::<InMatch>();
Expand All @@ -40,20 +34,6 @@ fn despawn_marked(
}
}

fn despawn_on_state_change(
state: Res<State<GameState>>,
mut commands: Commands,
query: Query<(Entity, &LivesInStates)>,
) {
if state.is_changed() {
for (entity, restriction) in &query {
if !restriction.contains(state.get()) {
commands.entity(entity).despawn_recursive();
}
}
}
}

fn update_visibility_on_state_change(
state: Res<State<GameState>>,
mut query: Query<(&mut Visibility, &VisibleInStates)>,
Expand Down
49 changes: 49 additions & 0 deletions client/main/assets/shaders/ring_ripple.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#import bevy_pbr::forward_io::VertexOutput
#import bevy_pbr::mesh_view_bindings::{globals, view};

@group(2) @binding(0) var<uniform> base_color: vec4<f32>;
@group(2) @binding(1) var<uniform> edge_color: vec4<f32>;
@group(2) @binding(2) var<uniform> duration: f32;
@group(2) @binding(3) var<uniform> ring_thickness: f32;
@group(2) @binding(4) var<uniform> start_time: f32;

const PI = 3.14159265359;
const offset = PI * 2 / 3;

@fragment
fn fragment(
mesh: VertexOutput,
) -> @location(0) vec4<f32> {
// Coordinate relative to middle
let centered = 2 * (mesh.uv - 0.5);
let time = easeOutQuint((globals.time - start_time) / duration);

let normdist = length(centered);

let half_ring = ring_thickness / 2.0;
let ring_midpoint = normdist + half_ring;

let t = abs(time - ring_midpoint);
var alpha = 0.0;
if t < half_ring {
let distance_fade = 1 - time;
// Technically, this should be 1.0, but the 1.2 makes for a less sharp
// falloff and the mid color is more pronounced
let sdf_fade = 1.2 - (t / half_ring);
alpha = distance_fade * sdf_fade;
} else {
alpha = 0.0;
}
var color = lerp(t / half_ring, edge_color, base_color);
color.a *= alpha;
return color;
}

fn lerp(t: f32, c1: vec4<f32>, c2: vec4<f32>) -> vec4<f32> {
return t * c1 + (1 - t) * c2;
}

fn easeOutQuint(x: f32) -> f32 {
return 1 - pow(1 - x, 5.0);
}

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions client/wag_core/src/color_palette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ pub const HIT_SPARK_EDGE_COLOR: Color = Color::srgb(1.0, 1.0, 0.1);
pub const BLOCK_EFFECT_BASE_COLOR: Color = Color::WHITE;
pub const BLOCK_EFFECT_EDGE_COLOR: Color = Color::srgb(0.1, 0.2, 1.0);

pub const RING_RIPPLE_EDGE_COLOR: Color = Color::WHITE;
pub const RING_RIPPLE_BASE_COLOR: Color = Color::srgb(0.2, 1.0, 0.5);

pub const CLASH_SPARK_BASE_COLOR: Color = Color::srgb(1.0, 0.5, 1.0);
pub const CLASH_SPARK_EDGE_COLOR: Color = Color::srgb(0.9, 0.1, 0.9);

Expand Down
3 changes: 3 additions & 0 deletions client/wag_core/src/effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub enum SoundEffect {
PlasticCupTap,
CheekSlap,
FemaleExhale,
BottleBonk,
}

impl SoundEffect {
Expand All @@ -36,6 +37,7 @@ impl SoundEffect {
SoundEffect::PlasticCupTap => Self::clips("plastic-cup-tap", 20),
SoundEffect::CheekSlap => Self::clips("cheek-slap", 20),
SoundEffect::FemaleExhale => Self::clips("female-exhale", 16),
SoundEffect::BottleBonk => Self::clips("bottle-bonk", 12),
}
}

Expand All @@ -51,4 +53,5 @@ pub enum VisualEffect {
Clash,
Block,
Hit,
ThrowTech,
}
Binary file added intermediate_assets/audacity/bottle-bonk.aup3
Binary file not shown.

0 comments on commit e2a8331

Please sign in to comment.