../..
This commit is contained in:
parent
34e58f52d1
commit
ada9131dfb
4 changed files with 29 additions and 12 deletions
|
@ -1,7 +1,8 @@
|
|||
use std::collections::HashMap;
|
||||
use std::time::Duration;
|
||||
|
||||
type BlockOffsets = HashMap<usize, (u32, u32)>;
|
||||
type AnimationFn = Box<Fn(BlockOffsets, f32) -> BlockOffsets>;
|
||||
pub type BlockOffsets = HashMap<usize, (u32, u32)>;
|
||||
pub type AnimationFn = Box<Fn(BlockOffsets, f32) -> BlockOffsets>;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct AnimationState {
|
||||
|
@ -19,4 +20,10 @@ impl AnimationState {
|
|||
self.progress = 0.0;
|
||||
self.progress_function = Some(f);
|
||||
}
|
||||
|
||||
pub fn make_progress(&mut self, delta: Duration) {}
|
||||
|
||||
pub fn is_done(&self) -> bool {
|
||||
self.progress > 1.0
|
||||
}
|
||||
}
|
||||
|
|
12
src/game.rs
12
src/game.rs
|
@ -105,8 +105,10 @@ impl<'a> Game<'a> {
|
|||
}
|
||||
|
||||
if self.animations.is_animating {
|
||||
let delta_ms = delta.as_millis();
|
||||
if self.animations.last_move_success {
|
||||
if self.animations.is_done() {
|
||||
self.animations.make_progress(delta);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
|
@ -122,17 +124,17 @@ impl<'a> Game<'a> {
|
|||
|
||||
// failed a move
|
||||
if !self.animations.last_move_success {
|
||||
self.animations
|
||||
.begin_transition(Box::new(|mut offsets, prog| {
|
||||
let func = |mut offsets: HashMap<_, _>, prog| {
|
||||
offsets.insert(0, (0, 0));
|
||||
offsets
|
||||
}));
|
||||
};
|
||||
self.animations.begin_transition(Box::new(func));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(&self, renderer: &mut Renderer) {
|
||||
let level = self.get_current_level();
|
||||
level.render(renderer);
|
||||
level.render(renderer, &self.animations.block_offsets);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ impl Block {
|
|||
.collect();
|
||||
let orientation = data.orientation.into();
|
||||
let color = Color::from_rgb_u32(data.color.0, data.color.1, data.color.2);
|
||||
|
||||
Block {
|
||||
index,
|
||||
movable,
|
||||
|
|
|
@ -4,6 +4,7 @@ mod player;
|
|||
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
|
||||
use crate::animations::BlockOffsets;
|
||||
use crate::color::Color;
|
||||
use crate::data::LevelData;
|
||||
use crate::enums::{Board, Orientation, PushDir, Shape};
|
||||
|
@ -197,7 +198,7 @@ impl Level {
|
|||
Some(())
|
||||
}
|
||||
|
||||
pub fn render(&self, renderer: &mut Renderer) {
|
||||
pub fn render(&self, renderer: &mut Renderer, block_offsets: &BlockOffsets) {
|
||||
// board positioning calculations
|
||||
let playfield_ratio = (2 * self.dimensions.0 + 6) as f32 / (self.dimensions.1 + 4) as f32;
|
||||
let screen_ratio = renderer.window.0 / renderer.window.1;
|
||||
|
@ -215,10 +216,16 @@ impl Level {
|
|||
(scale, xoff, 0)
|
||||
};
|
||||
|
||||
self.render_boards(renderer, scale, (xoff, yoff));
|
||||
self.render_boards(renderer, scale, (xoff, yoff), block_offsets);
|
||||
}
|
||||
|
||||
fn render_boards(&self, renderer: &mut Renderer, scale: i32, offset: (i32, i32)) {
|
||||
fn render_boards(
|
||||
&self,
|
||||
renderer: &mut Renderer,
|
||||
scale: i32,
|
||||
offset: (i32, i32),
|
||||
block_offsets: &BlockOffsets,
|
||||
) {
|
||||
let left_off = (offset.0 + 2 * scale, offset.1 + 2 * scale);
|
||||
let right_off = (
|
||||
offset.0 + (4 + self.dimensions.0 as i32) * scale,
|
||||
|
|
Loading…
Reference in a new issue