From d7a50ba057494cbf0e30cecd7f1e1ac49b15db35 Mon Sep 17 00:00:00 2001 From: RedStone576 Date: Mon, 23 Mar 2026 22:02:33 +0700 Subject: [PATCH] collision --- src/main.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2bb7d21..1710545 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,8 +43,14 @@ impl SideMatrix { fn draw_matrix(matrix: &Matrix, x: f32, y: f32, cell_size: f32) { for (i, row) in matrix.visible_cells().iter().enumerate() { - for (j, _) in row.iter().enumerate() { - let color = if (i + j) % 2 == 0 { RED } else { YELLOW }; + for (j, is_filled) in row.iter().enumerate() { + let color = if *is_filled { + GRAY + } else if (i + j) % 2 == 0 { + RED + } else { + YELLOW + }; draw_rectangle( x + j as f32 * cell_size, @@ -114,7 +120,7 @@ impl Game { preview: SideMatrix::new(4, 20), piece: Piece::new(20), drop_timer: 0.0, - drop_interval: 1.0, + drop_interval: 0.2, } } @@ -130,7 +136,7 @@ impl Game { fn drop_piece(&mut self) { let next_y = self.piece.y + 1; - if next_y >= self.matrix.height as i32 { + if next_y >= self.matrix.height as i32 || self.matrix.cells[next_y as usize][self.piece.x as usize] { self.lock_piece(); self.piece = Piece::new(20); } else { @@ -139,7 +145,9 @@ impl Game { } fn lock_piece(&mut self) { - self.matrix.cells[self.piece.y as usize][self.piece.x as usize] = true; + if self.piece.y >= 0 && self.piece.y < self.matrix.height as i32 { + self.matrix.cells[self.piece.y as usize][self.piece.x as usize] = true; + } } }