From d719338097b9547ab9b04c8b53486dcbde047963 Mon Sep 17 00:00:00 2001 From: Edward Shen Date: Sun, 22 Mar 2020 17:33:38 -0400 Subject: [PATCH] fix lock timing --- src/game.rs | 39 ++++++++++++++++++++++----------------- src/main.rs | 1 - 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/game.rs b/src/game.rs index c9601e5..a7db1ae 100644 --- a/src/game.rs +++ b/src/game.rs @@ -85,7 +85,8 @@ impl Game { } fn update_gravity_tick(&mut self) { - self.next_gravity_tick = (-1 as i64) as u64; //self.tick + TICKS_PER_SECOND as u64; + // self.next_gravity_tick = (-1 as i64) as u64; + self.next_gravity_tick = self.tick + TICKS_PER_SECOND as u64; } fn update_lock_tick(&mut self) { @@ -141,11 +142,15 @@ pub trait Controllable { impl Controllable for Game { fn move_left(&mut self) { self.playfield.move_offset(-1, 0); - self.update_lock_tick(); + if !self.playfield.can_active_piece_move_down() { + self.update_lock_tick(); + } } fn move_right(&mut self) { self.playfield.move_offset(1, 0); - self.update_lock_tick(); + if !self.playfield.can_active_piece_move_down() { + self.update_lock_tick(); + } } fn move_down(&mut self) { if self.playfield.move_offset(0, 1) { @@ -190,20 +195,20 @@ impl Controllable for Game { } fn hold(&mut self) { - // if self.can_swap_hold { - // match self.hold_piece { - // None => { - // self.hold_piece = Some(self.active_piece); - // self.get_new_piece(); - // } - // Some(piece) => { - // self.hold_piece = Some(self.active_piece); - // self.active_piece = piece; - // self.reset_position(); - // } - // } + if self.can_swap_hold { + match self.hold_piece { + None => { + self.hold_piece = Some(self.active_piece); + self.get_new_piece(); + } + Some(piece) => { + self.hold_piece = Some(self.active_piece); + self.active_piece = piece; + self.reset_position(); + } + } - // self.can_swap_hold = false; - // } + self.can_swap_hold = false; + } } } diff --git a/src/main.rs b/src/main.rs index ea88917..0b67d1c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -85,6 +85,5 @@ async fn main() -> Result<(), Box> { interval.tick().await; } - dbg!(game); Ok(()) }