1
1
use std:: { io:: Read , sync:: Mutex } ;
2
2
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} ;
4
4
use ggez_goodies:: { camera:: { Camera , CameraDraw } , nalgebra_glm:: Vec2 , particle:: { EmissionShape , ParticleSystem , ParticleSystemBuilder , Transition } } ;
5
5
use graphics:: { Font , Image , Mesh , TextFragment } ;
6
6
use rand:: Rng ;
@@ -21,6 +21,7 @@ pub struct Game {
21
21
consolas : Font ,
22
22
23
23
ui_resources : Vec < Image > ,
24
+ audio_resources : Vec < Source > ,
24
25
25
26
camera : Camera ,
26
27
elapsed_shake : Option < ( f32 , Vec2 ) > ,
@@ -117,6 +118,10 @@ impl Game {
117
118
] ,
118
119
119
120
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
+ ] ,
120
125
121
126
camera,
122
127
@@ -269,6 +274,8 @@ impl Game {
269
274
. build ( ) , go_start_x, -HEIGHT2 + 70. , 0 )
270
275
) ;
271
276
277
+ self . audio_resources [ 1 ] . play ( ) . expect ( "Cannot play Some(explode).mp3" ) ;
278
+
272
279
self . enemies . remove ( i) ;
273
280
274
281
done = true ;
@@ -336,6 +343,8 @@ impl Game {
336
343
} ,
337
344
KeyCode :: S => {
338
345
if let Some ( fish) = self . player . shoot ( ) {
346
+ self . audio_resources [ 0 ] . play ( ) . expect ( "Cannot play Some(turbofish_shoot).mp3" ) ;
347
+
339
348
self . player_bullets . push ( fish) ;
340
349
}
341
350
} ,
0 commit comments