1
0

Clear filled rows
Some checks failed
CI / Typos (push) Successful in 12s
CI / Clippy (push) Successful in 36s
CI / Build (push) Has been cancelled

This commit is contained in:
Mark 2025-03-01 20:32:23 -08:00
parent e44bb2767c
commit 8b714bd197
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
3 changed files with 35 additions and 2 deletions

View File

@ -1,4 +1,3 @@
- clear lines
- deadlocks?
- fix arrow keys
- better rng

View File

@ -165,7 +165,7 @@ extern "x86-interrupt" fn timer_handler(_stack_frame: InterruptStackFrame) {
board.draw(&mut v, fall.as_ref());
if let Some(fall_inner) = fall.as_mut() {
if t % 6 == 0 {
if t % 5 == 0 {
let mut fall_test = fall_inner.clone();
fall_test.translate(0, 1);
@ -175,6 +175,7 @@ extern "x86-interrupt" fn timer_handler(_stack_frame: InterruptStackFrame) {
let mut x = None;
core::mem::swap(&mut x, &mut fall);
board.place_tetromino(x.unwrap());
board.collapse();
}
}
} else {

View File

@ -28,6 +28,39 @@ impl TetrisBoard {
}
}
pub fn collapse(&mut self) {
let mut y = Self::BOARD_HEIGHT - 1;
'outer: loop {
for x in 0..Self::BOARD_WIDTH {
let cell = self.get_cell(x, y);
if cell == Some(&TetrisCell::Empty) {
if y == 0 {
break 'outer;
}
y -= 1;
continue 'outer;
}
}
// We found a row that needs to be cleared
// Shift everything down
for yy in (1..=y).rev() {
for x in 0..Self::BOARD_WIDTH {
let top = *self.get_cell(x, yy - 1).unwrap();
let bot = self.get_cell_mut(x, yy).unwrap();
*bot = top;
}
}
// Clear the top row
for x in 0..Self::BOARD_WIDTH {
*self.get_cell_mut(x, 0).unwrap() = TetrisCell::Empty;
}
}
}
pub fn place_tetromino(&mut self, tetromino: FallingTetromino) {
for (x, y) in tetromino.tiles() {
let cell = self.get_cell_mut(x, y);