Skip to content

Commit 6611a98

Browse files
Add lerp on slow motion
1 parent e0d4d41 commit 6611a98

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

src/game.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
use std::{io::Read, sync::Mutex};
22

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+
};
411
use ggez_goodies::{
512
camera::{Camera, CameraDraw},
613
nalgebra_glm::Vec2,
@@ -18,6 +25,7 @@ use crate::{
1825
player::{Direction, Player},
1926
tile::{Tile, TileType},
2027
},
28+
utils::lerp,
2129
Screen, HEIGHT, WIDTH,
2230
};
2331

@@ -55,6 +63,7 @@ pub struct Game {
5563
particles: Vec<(ParticleSystem, f32, f32, i32)>,
5664

5765
dim_shader: ShaderGeneric<GlBackendSpec, Dim>,
66+
dim_constant: Dim,
5867
}
5968

6069
impl Game {
@@ -77,18 +86,17 @@ impl Game {
7786
let mut draw_pos = 0.;
7887
let draw_inc = 64.;
7988

80-
let dim_constant = Dim {
81-
rate: 0.5,
82-
};
89+
let dim_constant = Dim { rate: 1.0 };
8390

8491
let dim_shader = Shader::new(
8592
ctx,
8693
"/shaders/dim.basic.glslf",
8794
"/shaders/dim.glslf",
8895
dim_constant,
8996
"Dim",
90-
None
91-
).unwrap();
97+
None,
98+
)
99+
.unwrap();
92100

93101
for id in buffer.chars() {
94102
match id {
@@ -197,7 +205,8 @@ impl Game {
197205
tics: None,
198206
particles: vec![],
199207

200-
dim_shader
208+
dim_shader,
209+
dim_constant,
201210
})
202211
}
203212

@@ -206,9 +215,7 @@ impl Game {
206215
let _lock = graphics::use_shader(ctx, &self.dim_shader);
207216

208217
self.inner_draw(ctx)
209-
}
210-
211-
else {
218+
} else {
212219
self.inner_draw(ctx)
213220
}
214221
}
@@ -281,6 +288,13 @@ impl Game {
281288

282289
pub fn update(&mut self, ctx: &mut Context) -> GameResult<Option<crate::Screen>> {
283290
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+
284298
if timer::ticks(ctx) % t as usize == 0 {
285299
return self.inner_update(ctx);
286300
}
@@ -513,6 +527,7 @@ impl Game {
513527
match keycode {
514528
KeyCode::Up => {
515529
self.tics = None;
530+
self.dim_constant.rate = 1.0;
516531
}
517532

518533
_ => (),

0 commit comments

Comments
 (0)