fix lock timing

master
Edward Shen 2020-03-22 17:33:38 -04:00
parent 765b2655a3
commit d719338097
Signed by: edward
GPG Key ID: 19182661E818369F
2 changed files with 22 additions and 18 deletions

View File

@ -85,7 +85,8 @@ impl Game {
} }
fn update_gravity_tick(&mut self) { 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) { fn update_lock_tick(&mut self) {
@ -141,11 +142,15 @@ pub trait Controllable {
impl Controllable for Game { impl Controllable for Game {
fn move_left(&mut self) { fn move_left(&mut self) {
self.playfield.move_offset(-1, 0); 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) { fn move_right(&mut self) {
self.playfield.move_offset(1, 0); 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) { fn move_down(&mut self) {
if self.playfield.move_offset(0, 1) { if self.playfield.move_offset(0, 1) {
@ -190,20 +195,20 @@ impl Controllable for Game {
} }
fn hold(&mut self) { fn hold(&mut self) {
// if self.can_swap_hold { if self.can_swap_hold {
// match self.hold_piece { match self.hold_piece {
// None => { None => {
// self.hold_piece = Some(self.active_piece); self.hold_piece = Some(self.active_piece);
// self.get_new_piece(); self.get_new_piece();
// } }
// Some(piece) => { Some(piece) => {
// self.hold_piece = Some(self.active_piece); self.hold_piece = Some(self.active_piece);
// self.active_piece = piece; self.active_piece = piece;
// self.reset_position(); self.reset_position();
// } }
// } }
// self.can_swap_hold = false; self.can_swap_hold = false;
// } }
} }
} }

View File

@ -85,6 +85,5 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
interval.tick().await; interval.tick().await;
} }
dbg!(game);
Ok(()) Ok(())
} }