fix lock timing

This commit is contained in:
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) {
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,12 +142,16 @@ pub trait Controllable {
impl Controllable for Game {
fn move_left(&mut self) {
self.playfield.move_offset(-1, 0);
if !self.playfield.can_active_piece_move_down() {
self.update_lock_tick();
}
}
fn move_right(&mut self) {
self.playfield.move_offset(1, 0);
if !self.playfield.can_active_piece_move_down() {
self.update_lock_tick();
}
}
fn move_down(&mut self) {
if self.playfield.move_offset(0, 1) {
self.score += 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;
}
}
}

View file

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