1
1
use std:: { io:: Read , sync:: Mutex } ;
2
2
3
- use ggez:: { Context , GameResult , audio:: { SoundSource , Source } , event:: KeyCode , graphics:: { self , Color , DrawParam , Scale , Shader , Text } , mint, nalgebra:: Point2 , timer} ;
3
+ use ggez:: {
4
+ audio:: { SoundSource , Source } ,
5
+ event:: KeyCode ,
6
+ graphics:: { self , Color , DrawParam , Scale , 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 ,
@@ -18,6 +25,7 @@ use crate::{
18
25
player:: { Direction , Player } ,
19
26
tile:: { Tile , TileType } ,
20
27
} ,
28
+ utils:: lerp,
21
29
Screen , HEIGHT , WIDTH ,
22
30
} ;
23
31
@@ -55,6 +63,7 @@ pub struct Game {
55
63
particles : Vec < ( ParticleSystem , f32 , f32 , i32 ) > ,
56
64
57
65
dim_shader : ShaderGeneric < GlBackendSpec , Dim > ,
66
+ dim_constant : Dim ,
58
67
}
59
68
60
69
impl Game {
@@ -77,18 +86,17 @@ impl Game {
77
86
let mut draw_pos = 0. ;
78
87
let draw_inc = 64. ;
79
88
80
- let dim_constant = Dim {
81
- rate : 0.5 ,
82
- } ;
89
+ let dim_constant = Dim { rate : 1.0 } ;
83
90
84
91
let dim_shader = Shader :: new (
85
92
ctx,
86
93
"/shaders/dim.basic.glslf" ,
87
94
"/shaders/dim.glslf" ,
88
95
dim_constant,
89
96
"Dim" ,
90
- None
91
- ) . unwrap ( ) ;
97
+ None ,
98
+ )
99
+ . unwrap ( ) ;
92
100
93
101
for id in buffer. chars ( ) {
94
102
match id {
@@ -197,7 +205,8 @@ impl Game {
197
205
tics : None ,
198
206
particles : vec ! [ ] ,
199
207
200
- dim_shader
208
+ dim_shader,
209
+ dim_constant,
201
210
} )
202
211
}
203
212
@@ -206,9 +215,7 @@ impl Game {
206
215
let _lock = graphics:: use_shader ( ctx, & self . dim_shader ) ;
207
216
208
217
self . inner_draw ( ctx)
209
- }
210
-
211
- else {
218
+ } else {
212
219
self . inner_draw ( ctx)
213
220
}
214
221
}
@@ -281,6 +288,13 @@ impl Game {
281
288
282
289
pub fn update ( & mut self , ctx : & mut Context ) -> GameResult < Option < crate :: Screen > > {
283
290
if let Some ( t) = self . tics {
291
+ if let Some ( _t) = self . tics {
292
+ if self . dim_constant . rate != 0.5 {
293
+ self . dim_constant . rate = lerp ( self . dim_constant . rate , 0.5 , 0.1 ) ;
294
+ self . dim_shader . send ( ctx, self . dim_constant ) ?;
295
+ }
296
+ }
297
+
284
298
if timer:: ticks ( ctx) % t as usize == 0 {
285
299
return self . inner_update ( ctx) ;
286
300
}
@@ -513,6 +527,7 @@ impl Game {
513
527
match keycode {
514
528
KeyCode :: Up => {
515
529
self . tics = None ;
530
+ self . dim_constant . rate = 1.0 ;
516
531
}
517
532
518
533
_ => ( ) ,
0 commit comments