Commit 5c12458 1 parent b7f0ee5 commit 5c12458 Copy full SHA for 5c12458
File tree 3 files changed +33
-4
lines changed
3 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ use crate::game::actor::faction::Faction;
14
14
use crate :: game:: actor:: movement:: input:: movement_action;
15
15
use crate :: game:: actor:: ActorConfig ;
16
16
use crate :: game:: combat:: damage:: HitboxDamage ;
17
+ use crate :: game:: combat:: death:: DeathSfx ;
17
18
use crate :: game:: combat:: hit:: Hitbox ;
18
19
use crate :: game:: combat:: hit:: HurtSfx ;
19
20
use crate :: game:: combat:: knockback:: HitboxKnockback ;
@@ -62,6 +63,7 @@ pub fn player(key: impl Into<String>) -> impl EntityCommand {
62
63
HitboxDamage ( 15.0 ) ,
63
64
HitboxKnockback ( 5.0 ) ,
64
65
HurtSfx ,
66
+ DeathSfx ,
65
67
) )
66
68
. set_parent ( parent)
67
69
. with_children ( |children| {
Original file line number Diff line number Diff line change 1
1
use bevy:: prelude:: * ;
2
+ use bevy_kira_audio:: prelude:: * ;
2
3
4
+ use crate :: screen:: playing:: PlayingAssets ;
3
5
use crate :: util:: prelude:: * ;
4
6
5
7
pub ( super ) fn plugin ( app : & mut App ) {
6
- app. configure :: < ( IsDead , DespawnOnDeath ) > ( ) ;
8
+ app. configure :: < ( IsDead , DespawnOnDeath , DeathSfx ) > ( ) ;
7
9
}
8
10
9
11
/// An observable event on an actor's death.
@@ -41,3 +43,28 @@ impl Configure for DespawnOnDeath {
41
43
fn despawn_on_death ( trigger : Trigger < OnDeath > , mut despawn : ResMut < LateDespawn > ) {
42
44
despawn. recursive ( r ! ( trigger. get_entity( ) ) ) ;
43
45
}
46
+
47
+ #[ derive( Component , Reflect ) ]
48
+ #[ reflect( Component ) ]
49
+ pub struct DeathSfx ;
50
+
51
+ impl Configure for DeathSfx {
52
+ fn configure ( app : & mut App ) {
53
+ app. register_type :: < Self > ( ) ;
54
+ app. observe ( play_death_sfx) ;
55
+ }
56
+ }
57
+
58
+ fn play_death_sfx (
59
+ trigger : Trigger < OnDeath > ,
60
+ sfx_query : Query < ( ) , With < DeathSfx > > ,
61
+ audio : Res < Audio > ,
62
+ assets : Res < PlayingAssets > ,
63
+ ) {
64
+ let entity = r ! ( trigger. get_entity( ) ) ;
65
+ if !sfx_query. contains ( entity) {
66
+ return ;
67
+ }
68
+
69
+ audio. play ( assets. sfx_restart . clone ( ) ) . with_volume ( 1.0 ) ;
70
+ }
Original file line number Diff line number Diff line change @@ -68,13 +68,13 @@ impl Configure for HurtSfx {
68
68
69
69
fn play_hurt_sfx (
70
70
trigger : Trigger < OnHit > ,
71
- hurt_query : Query < ( ) , With < HurtSfx > > ,
71
+ sfx_query : Query < ( ) , With < HurtSfx > > ,
72
72
audio : Res < Audio > ,
73
73
assets : Res < PlayingAssets > ,
74
74
) {
75
- if !hurt_query . contains ( trigger. event ( ) . 1 ) {
75
+ if !sfx_query . contains ( trigger. event ( ) . 1 ) {
76
76
return ;
77
77
}
78
78
79
- audio. play ( assets. sfx_hurt . clone ( ) ) . with_volume ( 0.6 ) ;
79
+ audio. play ( assets. sfx_hurt . clone ( ) ) . with_volume ( 1.0 ) ;
80
80
}
You can’t perform that action at this time.
0 commit comments