Skip to content

Commit

Permalink
Adds fire breathing sound effects
Browse files Browse the repository at this point in the history
  • Loading branch information
mnmaita committed Nov 19, 2023
1 parent 9e3475b commit 92a34bc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
Binary file added assets/sfx/breathend.ogg
Binary file not shown.
Binary file added assets/sfx/breathloop.ogg
Binary file not shown.
Binary file added assets/sfx/breathstart.ogg
Binary file not shown.
45 changes: 43 additions & 2 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ impl CursorWorldPositionChecker<'_, '_> {
}
}

#[derive(Component)]
struct FireBreathSfx;

fn mouse_input(
mouse_input: ResMut<Input<MouseButton>>,
cursor_world_position_checker: CursorWorldPositionChecker,
mut commands: Commands,
mut spawn_fire_breath_event_writer: EventWriter<SpawnFireBreathEvent>,
mut query: Query<&mut Transform, With<Player>>,
sfx_query: Query<Entity, With<FireBreathSfx>>,
asset_server: Res<AssetServer>,
cursor_world_position_checker: CursorWorldPositionChecker,
mouse_input: ResMut<Input<MouseButton>>,
) {
if mouse_input.pressed(MouseButton::Right) {
if let Some(cursor_position) = cursor_world_position_checker.cursor_world_position() {
Expand Down Expand Up @@ -64,6 +70,41 @@ fn mouse_input(
}
}
}

if mouse_input.just_pressed(MouseButton::Left) {
commands.spawn((
AudioBundle {
source: asset_server
.get_handle("sfx/breathstart.ogg")
.unwrap_or_default(),
settings: PlaybackSettings::DESPAWN,
},
FireBreathSfx,
));
commands.spawn((
AudioBundle {
source: asset_server
.get_handle("sfx/breathloop.ogg")
.unwrap_or_default(),
settings: PlaybackSettings::LOOP,
},
FireBreathSfx,
));
} else if mouse_input.just_released(MouseButton::Left) {
commands.spawn((
AudioBundle {
source: asset_server
.get_handle("sfx/breathend.ogg")
.unwrap_or_default(),
settings: PlaybackSettings::DESPAWN,
},
FireBreathSfx,
));
for entity in &sfx_query {
commands.entity(entity).despawn_recursive();
}
}

if mouse_input.pressed(MouseButton::Left) {
let player_transform = query.single();

Expand Down

0 comments on commit 92a34bc

Please sign in to comment.