1
1
use std:: { io:: Read , sync:: Mutex } ;
2
2
3
- use ggez:: { Context , GameResult , event:: KeyCode , graphics:: { self , Color , DrawMode , DrawParam , Scale , Text } , nalgebra:: Point2 , timer} ;
4
- use ggez_goodies:: { camera:: Camera , nalgebra_glm:: Vec2 } ;
3
+ use ggez:: { Context , GameResult , event:: KeyCode , graphics:: { self , Color , DrawMode , DrawParam , Scale , Text } , mint , nalgebra:: Point2 , timer} ;
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 ;
7
7
@@ -24,7 +24,8 @@ pub struct Game {
24
24
25
25
camera : Camera ,
26
26
elapsed_shake : Option < ( f32 , Vec2 ) > ,
27
- tics : Option < i32 >
27
+ tics : Option < i32 > ,
28
+ particles : Vec < ( ParticleSystem , f32 , f32 , i32 ) >
28
29
}
29
30
30
31
impl Game {
@@ -122,6 +123,7 @@ impl Game {
122
123
consolas : graphics:: Font :: new ( ctx, "/fonts/Consolas.ttf" ) . unwrap ( ) ,
123
124
elapsed_shake : None ,
124
125
tics : None ,
126
+ particles : vec ! [ ]
125
127
} )
126
128
}
127
129
@@ -187,6 +189,15 @@ impl Game {
187
189
fish. draw ( ctx, & self . camera , & self . bullet_resources ) ?;
188
190
}
189
191
192
+ for sys in & mut self . particles {
193
+ & sys. 0 . draw_camera (
194
+ & self . camera ,
195
+ ctx,
196
+ Vec2 :: new ( sys. 1 , sys. 2 ) ,
197
+ 0.
198
+ ) ;
199
+ }
200
+
190
201
graphics:: present ( ctx)
191
202
}
192
203
@@ -204,7 +215,7 @@ impl Game {
204
215
Ok ( None )
205
216
}
206
217
207
- pub fn inner_update ( & mut self , _ctx : & mut Context ) -> GameResult < Option < crate :: Screen > > {
218
+ pub fn inner_update ( & mut self , ctx : & mut Context ) -> GameResult < Option < crate :: Screen > > {
208
219
let ferris_pos_x = self . player . pos_x ;
209
220
let mut ferris_is_falling_down: bool = true ;
210
221
@@ -238,6 +249,26 @@ impl Game {
238
249
239
250
for fish in & self . player_bullets {
240
251
if fish. pos_x >= go_start_x && fish. pos_x <= go_end_x {
252
+ const HEIGHT2 : f32 = HEIGHT / 2. ;
253
+
254
+ self . particles . push (
255
+ ( ParticleSystemBuilder :: new ( ctx)
256
+ . count ( 100 )
257
+ . emission_rate ( 100.0 )
258
+ . start_max_age ( 5.0 )
259
+ . start_size_range ( 2.0 , 15.0 )
260
+ . start_color_range (
261
+ graphics:: Color :: from ( ( 0 , 0 , 0 ) ) ,
262
+ graphics:: Color :: from ( ( 255 , 255 , 255 ) ) ,
263
+ )
264
+ . delta_color ( Transition :: range (
265
+ ggez:: graphics:: Color :: from ( ( 255 , 0 , 0 ) ) ,
266
+ ggez:: graphics:: Color :: from ( ( 255 , 255 , 0 ) ) ,
267
+ ) )
268
+ . emission_shape ( EmissionShape :: Circle ( mint:: Point2 { x : 0.0 , y : 0.0 } , 100.0 ) )
269
+ . build ( ) , go_start_x, -HEIGHT2 + 70. , 0 )
270
+ ) ;
271
+
241
272
self . enemies . remove ( i) ;
242
273
243
274
done = true ;
@@ -276,6 +307,19 @@ impl Game {
276
307
}
277
308
}
278
309
310
+ for sys in & mut self . particles {
311
+ sys. 0 . update ( 0.5 ) ;
312
+ sys. 3 += 1 ;
313
+ }
314
+
315
+ for i in 0 ..self . particles . len ( ) {
316
+ let sys = & self . particles [ i] ;
317
+
318
+ if sys. 3 > 6 {
319
+ self . particles . remove ( i) ;
320
+ }
321
+ }
322
+
279
323
Ok ( None )
280
324
}
281
325
0 commit comments