fix lock timing
This commit is contained in:
parent
765b2655a3
commit
d719338097
2 changed files with 22 additions and 18 deletions
39
src/game.rs
39
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,6 +85,5 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
interval.tick().await;
|
||||
}
|
||||
|
||||
dbg!(game);
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue