Skip to content

Commit cd7d147

Browse files
Add sound effects
1 parent 1b96b4e commit cd7d147

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

resources/audio/Some(explode).mp3

8.61 KB
Binary file not shown.
2.08 KB
Binary file not shown.

src/game.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{io::Read, sync::Mutex};
22

3-
use ggez::{Context, GameResult, event::KeyCode, graphics::{self, Color, DrawMode, DrawParam, Scale, Text}, mint, nalgebra::Point2, timer};
3+
use ggez::{Context, GameResult, audio::{SoundSource, Source}, event::KeyCode, graphics::{self, Color, DrawMode, DrawParam, Scale, Text}, mint, nalgebra::Point2, timer};
44
use ggez_goodies::{camera::{Camera, CameraDraw}, nalgebra_glm::Vec2, particle::{EmissionShape, ParticleSystem, ParticleSystemBuilder, Transition}};
55
use graphics::{Font, Image, Mesh, TextFragment};
66
use rand::Rng;
@@ -21,6 +21,7 @@ pub struct Game {
2121
consolas: Font,
2222

2323
ui_resources: Vec<Image>,
24+
audio_resources: Vec<Source>,
2425

2526
camera: Camera,
2627
elapsed_shake: Option<(f32, Vec2)>,
@@ -117,6 +118,10 @@ impl Game {
117118
],
118119

119120
ui_resources: vec![Image::new(ctx, "/images/Some(ammo).png").unwrap()],
121+
audio_resources: vec![
122+
Source::new(ctx, "/audio/Some(turbofish_shoot).mp3").unwrap(),
123+
Source::new(ctx, "/audio/Some(explode).mp3").unwrap()
124+
],
120125

121126
camera,
122127

@@ -269,6 +274,8 @@ impl Game {
269274
.build(), go_start_x, -HEIGHT2 + 70., 0)
270275
);
271276

277+
self.audio_resources[1].play().expect("Cannot play Some(explode).mp3");
278+
272279
self.enemies.remove(i);
273280

274281
done = true;
@@ -336,6 +343,8 @@ impl Game {
336343
},
337344
KeyCode::S => {
338345
if let Some(fish) = self.player.shoot() {
346+
self.audio_resources[0].play().expect("Cannot play Some(turbofish_shoot).mp3");
347+
339348
self.player_bullets.push(fish);
340349
}
341350
},

0 commit comments

Comments
 (0)