From bda06192baccced068759f0bf966e533cec9ee78 Mon Sep 17 00:00:00 2001 From: Theis Pieter Hollebeek Date: Tue, 4 Mar 2025 10:42:18 +0100 Subject: [PATCH] center pieces --- src/game.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/game.rs b/src/game.rs index 29cc051..d4acecf 100644 --- a/src/game.rs +++ b/src/game.rs @@ -11,11 +11,18 @@ pub struct CurrentTetromino { impl CurrentTetromino { fn new(tetromino: Tetromino) -> Self { - const PIECE_WIDTH: i8 = 4; + let width = tetromino + .pattern(&Direction::Up) + .into_iter() + .map(|(x, _y)| x) + .max() + .expect("pattern length > 0") + + 1; + let x = ((Board::WIDTH - width) / 2) as i8; Self { tetromino, direction: Direction::Up, - x: (Board::WIDTH as i8 - PIECE_WIDTH) / 2, + x, y: -1, } }