@@ -3,7 +3,7 @@ use std::{io::Read, sync::Mutex};
3
3
use ggez:: {
4
4
audio:: { SoundSource , Source } ,
5
5
event:: KeyCode ,
6
- graphics:: { self , Color , DrawParam , Scale , Shader , Text } ,
6
+ graphics:: { self , Color , DrawParam , Shader } ,
7
7
mint,
8
8
nalgebra:: Point2 ,
9
9
timer, Context , GameResult ,
@@ -13,7 +13,8 @@ use ggez_goodies::{
13
13
nalgebra_glm:: Vec2 ,
14
14
particle:: { EmissionShape , ParticleSystem , ParticleSystemBuilder , Transition } ,
15
15
} ;
16
- use graphics:: { Font , GlBackendSpec , Image , ShaderGeneric , TextFragment } ;
16
+ use graphics:: { Font , GlBackendSpec , Image , ShaderGeneric } ;
17
+ use mint:: Vector2 ;
17
18
use rand:: Rng ;
18
19
19
20
use crate :: {
@@ -25,7 +26,7 @@ use crate::{
25
26
player:: { Direction , Player } ,
26
27
tile:: { Tile , TileType } ,
27
28
} ,
28
- utils:: lerp,
29
+ utils:: { lerp, remap } ,
29
30
Screen , HEIGHT , WIDTH ,
30
31
} ;
31
32
@@ -55,6 +56,7 @@ pub struct Game {
55
56
barrel_resources : Vec < Image > ,
56
57
cloud_resources : Vec < Image > ,
57
58
59
+ #[ allow( dead_code) ]
58
60
consolas : Font ,
59
61
60
62
camera : Camera ,
@@ -189,7 +191,10 @@ impl Game {
189
191
190
192
bullet_resources : vec ! [ Image :: new( ctx, "/images/Some(turbofish).png" ) . unwrap( ) ] ,
191
193
192
- ui_resources : vec ! [ Image :: new( ctx, "/images/Some(ammo).png" ) . unwrap( ) ] ,
194
+ ui_resources : vec ! [
195
+ Image :: new( ctx, "/images/Some(profile).png" ) . unwrap( ) ,
196
+ Image :: new( ctx, "/images/Some(fish).png" ) . unwrap( ) ,
197
+ ] ,
193
198
194
199
barrel_resources : vec ! [ Image :: new( ctx, "/images/Some(barrel).png" ) . unwrap( ) ] ,
195
200
@@ -249,43 +254,100 @@ impl Game {
249
254
self . player
250
255
. draw ( ctx, & self . camera , & self . player_resources ) ?;
251
256
257
+ // Player Bullets
258
+ for fish in & mut self . player_bullets {
259
+ fish. draw ( ctx, & self . camera , & self . bullet_resources ) ?;
260
+ }
261
+
262
+ // Particles
263
+ for sys in & mut self . particles {
264
+ & sys. 0
265
+ . draw_camera ( & self . camera , ctx, Vec2 :: new ( sys. 1 , sys. 2 ) , 0. ) ;
266
+ }
267
+
268
+ // User Profile, etc..
269
+ self . draw_ui ( ctx) ?;
270
+
271
+ graphics:: present ( ctx)
272
+ }
273
+
274
+ fn draw_ui ( & mut self , ctx : & mut Context ) -> GameResult < ( ) > {
252
275
graphics:: draw (
253
276
ctx,
254
277
& self . ui_resources [ 0 ] ,
255
- DrawParam :: default ( ) . dest ( Point2 :: new ( 10.0 , 10.0 ) ) ,
278
+ DrawParam :: default ( )
279
+ . dest ( Point2 :: new ( 10.0 , 10.0 ) )
280
+ . scale ( Vector2 { x : 0.5 , y : 0.5 } ) ,
256
281
) ?;
257
282
258
- let ammo_frag = TextFragment {
259
- text : self . player . ammo . to_string ( ) ,
260
- font : Some ( self . consolas ) ,
261
- scale : Some ( Scale :: uniform ( 30.0 ) ) ,
262
- color : {
263
- if self . player . ammo > 10 / 2 {
264
- Some ( Color :: from_rgb ( 255 , 255 , 255 ) )
265
- } else {
266
- Some ( Color :: from_rgb ( 255 , 80 , 76 ) )
267
- }
268
- } ,
283
+ let ammo_rect = graphics :: Mesh :: new_rectangle (
284
+ ctx ,
285
+ graphics :: DrawMode :: fill ( ) ,
286
+ graphics :: Rect :: new (
287
+ ( ( self . ui_resources [ 0 ] . width ( ) / 2 ) + 10 ) as f32 ,
288
+ ( self . ui_resources [ 0 ] . height ( ) / 3 ) as f32 ,
289
+ 150. ,
290
+ 15. ,
291
+ ) ,
292
+ Color :: from_rgb ( 54 , 50 , 49 ) ,
293
+ ) ? ;
269
294
270
- ..Default :: default ( )
271
- } ;
295
+ let hp_rect = graphics:: Mesh :: new_rectangle (
296
+ ctx,
297
+ graphics:: DrawMode :: fill ( ) ,
298
+ graphics:: Rect :: new (
299
+ ( ( self . ui_resources [ 0 ] . width ( ) / 2 ) + 10 ) as f32 ,
300
+ ( self . ui_resources [ 0 ] . height ( ) / 5 ) as f32 ,
301
+ 150. ,
302
+ 15. ,
303
+ ) ,
304
+ Color :: from_rgb ( 54 , 50 , 49 ) ,
305
+ ) ?;
272
306
273
- graphics:: draw (
307
+ let cur_ammo_rect = graphics:: Mesh :: new_rectangle (
274
308
ctx,
275
- & Text :: new ( ammo_frag) ,
276
- DrawParam :: default ( ) . dest ( Point2 :: new ( 30.0 , 25.0 ) ) ,
309
+ graphics:: DrawMode :: fill ( ) ,
310
+ graphics:: Rect :: new (
311
+ ( ( self . ui_resources [ 0 ] . width ( ) / 2 ) + 10 ) as f32 ,
312
+ ( self . ui_resources [ 0 ] . height ( ) / 3 ) as f32 ,
313
+ remap ( self . player . ammo as f32 , 0. , 10. , 0. , 150. ) ,
314
+ 15. ,
315
+ ) ,
316
+ Color :: from_rgb ( 21 , 156 , 228 ) ,
277
317
) ?;
278
318
279
- for fish in & mut self . player_bullets {
280
- fish. draw ( ctx, & self . camera , & self . bullet_resources ) ?;
281
- }
319
+ let cur_hp_rect = graphics:: Mesh :: new_rectangle (
320
+ ctx,
321
+ graphics:: DrawMode :: fill ( ) ,
322
+ graphics:: Rect :: new (
323
+ ( ( self . ui_resources [ 0 ] . width ( ) / 2 ) + 10 ) as f32 ,
324
+ ( self . ui_resources [ 0 ] . height ( ) / 5 ) as f32 ,
325
+ remap ( self . player . health as f32 , 0. , 100. , 0. , 150. ) ,
326
+ 15. ,
327
+ ) ,
328
+ Color :: from_rgb ( 34 , 205 , 124 ) ,
329
+ ) ?;
282
330
283
- for sys in & mut self . particles {
284
- & sys. 0
285
- . draw_camera ( & self . camera , ctx, Vec2 :: new ( sys. 1 , sys. 2 ) , 0. ) ;
286
- }
331
+ graphics:: draw ( ctx, & ammo_rect, DrawParam :: default ( ) ) ?;
287
332
288
- graphics:: present ( ctx)
333
+ graphics:: draw ( ctx, & hp_rect, DrawParam :: default ( ) ) ?;
334
+
335
+ graphics:: draw ( ctx, & cur_ammo_rect, DrawParam :: default ( ) ) ?;
336
+
337
+ graphics:: draw ( ctx, & cur_hp_rect, DrawParam :: default ( ) ) ?;
338
+
339
+ graphics:: draw (
340
+ ctx,
341
+ & self . ui_resources [ 1 ] ,
342
+ DrawParam :: default ( )
343
+ . dest ( Point2 :: new (
344
+ ( ( self . ui_resources [ 0 ] . width ( ) / 2 ) - 10 ) as f32 ,
345
+ ( self . ui_resources [ 0 ] . height ( ) / 3 ) as f32 ,
346
+ ) )
347
+ . scale ( Vector2 { x : 0.7 , y : 0.7 } ) ,
348
+ ) ?;
349
+
350
+ Ok ( ( ) )
289
351
}
290
352
291
353
pub fn update ( & mut self , ctx : & mut Context ) -> GameResult < Option < crate :: Screen > > {
0 commit comments