1
1
use std:: { collections:: HashMap , io:: Read , process:: exit, sync:: Mutex } ;
2
2
3
- use ggez:: { Context , GameResult , audio:: { SoundSource , Source } , event:: KeyCode , graphics:: { self , Color , DrawParam , Drawable , Shader , Text } , mint, nalgebra:: Point2 , timer} ;
3
+ use ggez:: {
4
+ audio:: { SoundSource , Source } ,
5
+ event:: KeyCode ,
6
+ graphics:: { self , Color , DrawParam , Drawable , Shader , Text } ,
7
+ mint,
8
+ nalgebra:: Point2 ,
9
+ timer, Context , GameResult ,
10
+ } ;
4
11
use ggez_goodies:: {
5
12
camera:: { Camera , CameraDraw } ,
6
13
nalgebra_glm:: Vec2 ,
@@ -10,14 +17,19 @@ use graphics::{Font, GlBackendSpec, Image, Scale, ShaderGeneric, TextFragment};
10
17
use mint:: Vector2 ;
11
18
use rand:: Rng ;
12
19
13
- use crate :: { HEIGHT , Screen , WIDTH , components:: {
20
+ use crate :: {
21
+ components:: {
14
22
barrel:: Barrel ,
15
23
bullet:: Turbofish ,
16
24
cloud:: Cloud ,
17
25
enemy:: Enemy ,
18
26
player:: { Direction , Player } ,
19
27
tile:: Tile ,
20
- } , map:: Map , utils:: { lerp, remap} } ;
28
+ } ,
29
+ map:: Map ,
30
+ utils:: { lerp, remap} ,
31
+ Screen , HEIGHT , WIDTH ,
32
+ } ;
21
33
22
34
use gfx:: * ;
23
35
@@ -60,7 +72,7 @@ pub struct Game {
60
72
end : Option < String > ,
61
73
62
74
draw_end_text : ( bool , Option < usize > , bool , bool ) , // Thread Sleeped?, Current Iters, Done?, Win?
63
- can_die : bool
75
+ can_die : bool ,
64
76
}
65
77
66
78
impl Game {
@@ -160,7 +172,7 @@ impl Game {
160
172
camera,
161
173
162
174
consolas : graphics:: Font :: new ( ctx, "/fonts/Consolas.ttf" ) . unwrap ( ) ,
163
-
175
+
164
176
elapsed_shake : None ,
165
177
tics : None ,
166
178
particles : vec ! [ ] ,
@@ -171,7 +183,7 @@ impl Game {
171
183
draw_end_text : ( false , None , false , false ) ,
172
184
173
185
end : map_1. end ,
174
- can_die : true
186
+ can_die : true ,
175
187
} )
176
188
}
177
189
@@ -187,29 +199,38 @@ impl Game {
187
199
let mut draw_pos = 0. ;
188
200
189
201
// You Win
190
- let end_frag = & Text :: new ( TextFragment :: new ( "You Win!" )
191
- . font ( self . consolas )
192
- . scale ( Scale :: uniform ( 50. ) )
202
+ let end_frag = & Text :: new (
203
+ TextFragment :: new ( "You Win!" )
204
+ . font ( self . consolas )
205
+ . scale ( Scale :: uniform ( 50. ) ) ,
193
206
) ;
194
207
195
208
let end_dimensions = end_frag. dimensions ( ctx) ;
196
209
197
- graphics:: draw ( ctx, end_frag, DrawParam :: default ( )
198
- . dest ( Point2 :: new ( ( WIDTH / 2.0 ) - ( end_dimensions. 0 / 2 ) as f32 , 50.0 ) )
210
+ graphics:: draw (
211
+ ctx,
212
+ end_frag,
213
+ DrawParam :: default ( ) . dest ( Point2 :: new (
214
+ ( WIDTH / 2.0 ) - ( end_dimensions. 0 / 2 ) as f32 ,
215
+ 50.0 ,
216
+ ) ) ,
199
217
) ?;
200
-
218
+
201
219
// End quote
202
220
for line in self . end . as_ref ( ) . unwrap ( ) . split ( "\\ n" ) . collect :: < Vec < _ > > ( ) {
203
- let end_frag = & Text :: new ( TextFragment :: new ( line)
204
- . font ( self . consolas )
205
- ) ;
206
-
221
+ let end_frag = & Text :: new ( TextFragment :: new ( line) . font ( self . consolas ) ) ;
222
+
207
223
let end_dimensions = end_frag. dimensions ( ctx) ;
208
-
209
- graphics:: draw ( ctx, end_frag, DrawParam :: default ( )
210
- . dest ( Point2 :: new ( ( WIDTH / 2.0 ) - ( end_dimensions. 0 / 2 ) as f32 , HEIGHT / 2. + draw_pos) )
224
+
225
+ graphics:: draw (
226
+ ctx,
227
+ end_frag,
228
+ DrawParam :: default ( ) . dest ( Point2 :: new (
229
+ ( WIDTH / 2.0 ) - ( end_dimensions. 0 / 2 ) as f32 ,
230
+ HEIGHT / 2. + draw_pos,
231
+ ) ) ,
211
232
) ?;
212
-
233
+
213
234
draw_pos += 20.0 ;
214
235
}
215
236
@@ -228,24 +249,32 @@ impl Game {
228
249
229
250
let menu_rect_dim = menu_rect. dimensions ( ctx) . unwrap ( ) ;
230
251
231
- let menu_frag_to = & Text :: new ( TextFragment :: new ( "Press & go to the" )
232
- . font ( self . consolas )
233
- ) ;
252
+ let menu_frag_to =
253
+ & Text :: new ( TextFragment :: new ( "Press & go to the" ) . font ( self . consolas ) ) ;
234
254
235
- let menu_screen = & Text :: new ( TextFragment :: new ( "MENU SCREEN" )
236
- . font ( self . consolas )
237
- . scale ( Scale :: uniform ( 20.0 ) )
255
+ let menu_screen = & Text :: new (
256
+ TextFragment :: new ( "MENU SCREEN" )
257
+ . font ( self . consolas )
258
+ . scale ( Scale :: uniform ( 20.0 ) ) ,
238
259
) ;
239
260
240
261
graphics:: draw ( ctx, & menu_rect, DrawParam :: default ( ) ) ?;
241
262
graphics:: draw (
242
- ctx, menu_frag_to, DrawParam :: default ( )
243
- . dest ( Point2 :: new ( ( WIDTH / 2. ) + 20. , ( ( HEIGHT / 2. ) + ( draw_pos * 2. ) ) - 20.0 ) )
263
+ ctx,
264
+ menu_frag_to,
265
+ DrawParam :: default ( ) . dest ( Point2 :: new (
266
+ ( WIDTH / 2. ) + 20. ,
267
+ ( ( HEIGHT / 2. ) + ( draw_pos * 2. ) ) - 20.0 ,
268
+ ) ) ,
244
269
) ?;
245
270
246
271
graphics:: draw (
247
- ctx, menu_screen, DrawParam :: default ( )
248
- . dest ( Point2 :: new ( ( WIDTH / 2. ) + 70. , ( ( HEIGHT / 2. ) + ( draw_pos * 2. ) ) + 12.0 ) )
272
+ ctx,
273
+ menu_screen,
274
+ DrawParam :: default ( ) . dest ( Point2 :: new (
275
+ ( WIDTH / 2. ) + 70. ,
276
+ ( ( HEIGHT / 2. ) + ( draw_pos * 2. ) ) + 12.0 ,
277
+ ) ) ,
249
278
) ?;
250
279
251
280
// Press * to quit
@@ -261,24 +290,31 @@ impl Game {
261
290
[ 36.0 / 255.0 , 36.0 / 255.0 , 36.0 / 255.0 , 0.9 ] . into ( ) ,
262
291
) ?;
263
292
264
- let quit_frag_to = & Text :: new ( TextFragment :: new ( "Press * to" )
265
- . font ( self . consolas )
266
- ) ;
293
+ let quit_frag_to = & Text :: new ( TextFragment :: new ( "Press * to" ) . font ( self . consolas ) ) ;
267
294
268
- let press_quit = & Text :: new ( TextFragment :: new ( "QUIT" )
269
- . font ( self . consolas )
270
- . scale ( Scale :: uniform ( 20. ) )
295
+ let press_quit = & Text :: new (
296
+ TextFragment :: new ( "QUIT" )
297
+ . font ( self . consolas )
298
+ . scale ( Scale :: uniform ( 20. ) ) ,
271
299
) ;
272
300
273
301
graphics:: draw ( ctx, & quit_rect, DrawParam :: default ( ) ) ?;
274
302
graphics:: draw (
275
- ctx, quit_frag_to, DrawParam :: default ( )
276
- . dest ( Point2 :: new ( ( ( WIDTH / 2. ) - menu_rect_dim. w ) - 20. , ( ( HEIGHT / 2. ) + ( draw_pos * 2. ) ) - 20. ) )
303
+ ctx,
304
+ quit_frag_to,
305
+ DrawParam :: default ( ) . dest ( Point2 :: new (
306
+ ( ( WIDTH / 2. ) - menu_rect_dim. w ) - 20. ,
307
+ ( ( HEIGHT / 2. ) + ( draw_pos * 2. ) ) - 20. ,
308
+ ) ) ,
277
309
) ?;
278
310
279
311
graphics:: draw (
280
- ctx, press_quit, DrawParam :: default ( )
281
- . dest ( Point2 :: new ( ( ( ( WIDTH / 2. ) - menu_rect_dim. w ) - 20. ) + 90. , ( ( ( HEIGHT / 2. ) + ( draw_pos * 2. ) ) - 20. ) + 30. ) )
312
+ ctx,
313
+ press_quit,
314
+ DrawParam :: default ( ) . dest ( Point2 :: new (
315
+ ( ( ( WIDTH / 2. ) - menu_rect_dim. w ) - 20. ) + 90. ,
316
+ ( ( ( HEIGHT / 2. ) + ( draw_pos * 2. ) ) - 20. ) + 30. ,
317
+ ) ) ,
282
318
) ?;
283
319
}
284
320
} else {
@@ -439,16 +475,12 @@ impl Game {
439
475
440
476
if self . draw_end_text . 1 . is_none ( ) {
441
477
self . draw_end_text . 1 = Some ( timer:: ticks ( ctx) ) ;
442
- }
443
-
444
- else if !self . draw_end_text . 2 {
478
+ } else if !self . draw_end_text . 2 {
445
479
if timer:: ticks ( ctx) - self . draw_end_text . 1 . unwrap ( ) > 30 {
446
480
self . draw_end_text . 0 = true ;
447
481
self . draw_end_text . 2 = true ;
448
482
}
449
- }
450
-
451
- else {
483
+ } else {
452
484
self . tics = Some ( 1 ) ;
453
485
454
486
if self . dim_constant . rate != 0.0 {
@@ -457,7 +489,7 @@ impl Game {
457
489
}
458
490
}
459
491
}
460
-
492
+
461
493
let ferris_pos_x = self . player . pos_x ;
462
494
let ferris_pos_y = self . player . pos_y ;
463
495
@@ -646,13 +678,13 @@ impl Game {
646
678
match v. 0 . as_str ( ) {
647
679
"ammo" => {
648
680
self . player . ammo = lerp ( self . player . ammo , * v. 1 , 0.3 ) ;
649
- } ,
681
+ }
650
682
651
683
"health" => {
652
684
// TODO: Health lerping
653
685
}
654
686
655
- _ => panic ! ( )
687
+ _ => panic ! ( ) ,
656
688
}
657
689
}
658
690
@@ -690,7 +722,7 @@ impl Game {
690
722
}
691
723
KeyCode :: Up => {
692
724
self . tics = Some ( 6 ) ;
693
- } ,
725
+ }
694
726
KeyCode :: Key7 => {
695
727
return Some ( Screen :: Menu ) ;
696
728
}
0 commit comments