Skip to content

Commit

Permalink
(fix) infinite hold
Browse files Browse the repository at this point in the history
  • Loading branch information
GaspardCulis committed May 1, 2023
1 parent 2e434ec commit c5f6e02
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub struct Game {
current: PhysicalPiece,
next: Piece,
held: Option<Piece>,
has_held: bool,
score: u32,
rng: rand::rngs::ThreadRng,
time: Instant
Expand All @@ -30,6 +31,7 @@ impl Game {
},
next: *PIECES[rng.gen_range(0..PIECE_COUNT)],
held: None,
has_held: false,
score: 0,
rng,
time: Instant::now()
Expand All @@ -39,7 +41,7 @@ impl Game {
pub fn update(&mut self) {
let now = Instant::now();
let delta = now.duration_since(self.time).as_millis();
if delta > 100 {
if delta > 150 {
self.tick();
self.time = now;
}
Expand All @@ -50,11 +52,14 @@ impl Game {
self.boup();
let cleared = self.clear_lines();
self.score += self.compute_score(cleared);
self.has_held = false;
}
}

fn hold(&mut self) {
if self.held.is_none() {
if self.has_held {
return;
} else if self.held.is_none() {
self.held = Some(self.current.piece);
self.spawn_new();
} else {
Expand All @@ -67,6 +72,7 @@ impl Game {
piece: bkp.unwrap()
};
}
self.has_held = true;
}

pub fn handle_input(&mut self, keycode: char) {
Expand Down

0 comments on commit c5f6e02

Please sign in to comment.