movement
This commit is contained in:
+25
-1
@@ -120,11 +120,21 @@ impl Game {
|
||||
preview: SideMatrix::new(4, 20),
|
||||
piece: Piece::new(20),
|
||||
drop_timer: 0.0,
|
||||
drop_interval: 0.2,
|
||||
drop_interval: 1.0,
|
||||
}
|
||||
}
|
||||
|
||||
fn update(&mut self, dt: f32) {
|
||||
if is_key_pressed(KeyCode::A) {
|
||||
self.move_piece(-1, 0);
|
||||
}
|
||||
if is_key_pressed(KeyCode::D) {
|
||||
self.move_piece(1, 0);
|
||||
}
|
||||
if is_key_pressed(KeyCode::S) {
|
||||
self.drop_piece(); // sd
|
||||
}
|
||||
|
||||
self.drop_timer += dt;
|
||||
|
||||
if self.drop_timer >= self.drop_interval {
|
||||
@@ -149,6 +159,20 @@ impl Game {
|
||||
self.matrix.cells[self.piece.y as usize][self.piece.x as usize] = true;
|
||||
}
|
||||
}
|
||||
|
||||
fn move_piece(&mut self, dx: i32, dy: i32) {
|
||||
let next_x = self.piece.x + dx;
|
||||
let next_y = self.piece.y + dy;
|
||||
|
||||
if next_x >= 0 && next_x < self.matrix.width as i32 {
|
||||
if next_y >= 0 && next_y < self.matrix.height as i32 {
|
||||
if !self.matrix.cells[next_y as usize][next_x as usize] {
|
||||
self.piece.x = next_x;
|
||||
self.piece.y = next_y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[macroquad::main("tetrus")]
|
||||
|
||||
Reference in New Issue
Block a user