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