1
- use std:: { collections:: HashMap , io:: Read , sync:: Mutex } ;
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 , Shader , Text } , mint, nalgebra:: Point2 , timer} ;
3
+ use ggez:: { Context , GameResult , audio:: { SoundSource , Source } , event:: KeyCode , graphics:: { self , Color , DrawParam , Drawable , Shader , Text } , mint, nalgebra:: Point2 , timer} ;
4
4
use ggez_goodies:: {
5
5
camera:: { Camera , CameraDraw } ,
6
6
nalgebra_glm:: Vec2 ,
@@ -10,19 +10,14 @@ use graphics::{Font, GlBackendSpec, Image, Scale, ShaderGeneric, TextFragment};
10
10
use mint:: Vector2 ;
11
11
use rand:: Rng ;
12
12
13
- use crate :: {
14
- components:: {
13
+ use crate :: { HEIGHT , Screen , WIDTH , components:: {
15
14
barrel:: Barrel ,
16
15
bullet:: Turbofish ,
17
16
cloud:: Cloud ,
18
17
enemy:: Enemy ,
19
18
player:: { Direction , Player } ,
20
19
tile:: Tile ,
21
- } ,
22
- utils:: { lerp, remap} ,
23
- map:: Map ,
24
- Screen , HEIGHT , WIDTH ,
25
- } ;
20
+ } , map:: Map , utils:: { lerp, remap} } ;
26
21
27
22
use gfx:: * ;
28
23
@@ -64,7 +59,8 @@ pub struct Game {
64
59
65
60
end : Option < String > ,
66
61
67
- draw_end_text : ( bool , Option < usize > , bool , bool ) // Thread Sleeped?, Current Iters, Done?, Win?
62
+ draw_end_text : ( bool , Option < usize > , bool , bool ) , // Thread Sleeped?, Current Iters, Done?, Win?
63
+ can_die : bool
68
64
}
69
65
70
66
impl Game {
@@ -175,10 +171,11 @@ impl Game {
175
171
draw_end_text : ( false , None , false , false ) ,
176
172
177
173
end : map_1. end ,
174
+ can_die : true
178
175
} )
179
176
}
180
177
181
- pub fn draw ( & mut self , ctx : & mut Context ) -> GameResult < ( ) > {
178
+ pub fn draw ( & mut self , ctx : & mut Context ) -> GameResult < Option < Screen > > {
182
179
if let Some ( _t) = self . tics {
183
180
{
184
181
let _lock = graphics:: use_shader ( ctx, & self . dim_shader ) ;
@@ -215,12 +212,82 @@ impl Game {
215
212
216
213
draw_pos += 20.0 ;
217
214
}
215
+
216
+ // Press & to go to menu screen
217
+ let menu_rect = graphics:: Mesh :: new_rectangle (
218
+ ctx,
219
+ graphics:: DrawMode :: fill ( ) ,
220
+ graphics:: Rect :: new (
221
+ ( WIDTH / 2. ) + 20. ,
222
+ ( HEIGHT / 2. ) + ( draw_pos * 2. ) ,
223
+ 220.0 ,
224
+ 40.0 ,
225
+ ) ,
226
+ [ 36.0 / 255.0 , 36.0 / 255.0 , 36.0 / 255.0 , 0.9 ] . into ( ) ,
227
+ ) ?;
228
+
229
+ let menu_rect_dim = menu_rect. dimensions ( ctx) . unwrap ( ) ;
230
+
231
+ let menu_frag_to = & Text :: new ( TextFragment :: new ( "Press & go to the" )
232
+ . font ( self . consolas )
233
+ ) ;
234
+
235
+ let menu_screen = & Text :: new ( TextFragment :: new ( "MENU SCREEN" )
236
+ . font ( self . consolas )
237
+ . scale ( Scale :: uniform ( 20.0 ) )
238
+ ) ;
239
+
240
+ graphics:: draw ( ctx, & menu_rect, DrawParam :: default ( ) ) ?;
241
+ graphics:: draw (
242
+ ctx, menu_frag_to, DrawParam :: default ( )
243
+ . dest ( Point2 :: new ( ( WIDTH / 2. ) + 20. , ( ( HEIGHT / 2. ) + ( draw_pos * 2. ) ) - 20.0 ) )
244
+ ) ?;
245
+
246
+ graphics:: draw (
247
+ ctx, menu_screen, DrawParam :: default ( )
248
+ . dest ( Point2 :: new ( ( WIDTH / 2. ) + 70. , ( ( HEIGHT / 2. ) + ( draw_pos * 2. ) ) + 12.0 ) )
249
+ ) ?;
250
+
251
+ // Press * to quit
252
+ let quit_rect = graphics:: Mesh :: new_rectangle (
253
+ ctx,
254
+ graphics:: DrawMode :: fill ( ) ,
255
+ graphics:: Rect :: new (
256
+ ( ( WIDTH / 2. ) - menu_rect_dim. w ) - 20.0 ,
257
+ ( HEIGHT / 2. ) + ( draw_pos * 2. ) ,
258
+ 220.0 ,
259
+ 40.0 ,
260
+ ) ,
261
+ [ 36.0 / 255.0 , 36.0 / 255.0 , 36.0 / 255.0 , 0.9 ] . into ( ) ,
262
+ ) ?;
263
+
264
+ let quit_frag_to = & Text :: new ( TextFragment :: new ( "Press * to" )
265
+ . font ( self . consolas )
266
+ ) ;
267
+
268
+ let press_quit = & Text :: new ( TextFragment :: new ( "QUIT" )
269
+ . font ( self . consolas )
270
+ . scale ( Scale :: uniform ( 20. ) )
271
+ ) ;
272
+
273
+ graphics:: draw ( ctx, & quit_rect, DrawParam :: default ( ) ) ?;
274
+ 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. ) )
277
+ ) ?;
278
+
279
+ 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. ) )
282
+ ) ?;
218
283
}
219
284
} else {
220
285
self . inner_draw ( ctx) ?;
221
286
}
222
287
223
- graphics:: present ( ctx)
288
+ graphics:: present ( ctx) ?;
289
+
290
+ Ok ( None )
224
291
}
225
292
226
293
fn inner_draw ( & mut self , ctx : & mut Context ) -> GameResult < ( ) > {
@@ -368,6 +435,7 @@ impl Game {
368
435
pub fn inner_update ( & mut self , ctx : & mut Context ) -> GameResult < Option < crate :: Screen > > {
369
436
if self . enemies . len ( ) == 0 {
370
437
self . draw_end_text . 3 = true ;
438
+ self . can_die = false ;
371
439
372
440
if self . draw_end_text . 1 . is_none ( ) {
373
441
self . draw_end_text . 1 = Some ( timer:: ticks ( ctx) ) ;
@@ -415,7 +483,9 @@ impl Game {
415
483
. move_to ( Vec2 :: new ( self . player . pos_x , self . player . pos_y ) ) ;
416
484
417
485
if self . player . pos_y < -800. {
418
- return Ok ( Some ( Screen :: Dead ) ) ;
486
+ if self . can_die {
487
+ return Ok ( Some ( Screen :: Dead ) ) ;
488
+ }
419
489
}
420
490
421
491
for i in 0 ..self . enemies . len ( ) {
@@ -619,8 +689,13 @@ impl Game {
619
689
}
620
690
}
621
691
KeyCode :: Up => {
622
- // TODO: Add chromatic aberration on slow motion.
623
692
self . tics = Some ( 6 ) ;
693
+ } ,
694
+ KeyCode :: Key7 => {
695
+ return Some ( Screen :: Menu ) ;
696
+ }
697
+ KeyCode :: Key8 => {
698
+ exit ( 0 ) ;
624
699
}
625
700
_ => ( ) ,
626
701
}
0 commit comments