From 2646e334babf7783ae2f89846ee1aae64e451b8b Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 19 May 2014 12:56:14 +0900 Subject: [PATCH] Center tetrad when spawned --- tetris.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tetris.py b/tetris.py index 6fd4614..3270472 100755 --- a/tetris.py +++ b/tetris.py @@ -57,6 +57,10 @@ class Tetrad: return Tetrad(self.position, self.config, (self.rotation + 1) % self.block_rotations) + def centered(self, width): + return Tetrad((width / 2 - 2, 0), self.config, self.rotation) + + @staticmethod def random(position=(0, 0)): config = random.randrange(len(Tetrad.block_configs)) @@ -184,6 +188,7 @@ class Game: self.board_prev = Board((self.board.grid_rect.right+padding, padding), (4, 4), border_width, block_dims) self.tetrad = Tetrad.random() + self.tetrad = self.tetrad.centered(self.board.grid_dims[0]) self.tetrad_next = Tetrad.random() self.tetrad_preview = None @@ -236,7 +241,7 @@ class Game: self.board.place_tetrad(self.tetrad) self.board.settle() - self.tetrad = self.tetrad_next + self.tetrad = self.tetrad_next.centered(self.board.grid_dims[0]) self.tetrad_next = Tetrad.random() if not self.try_placement(self.tetrad): @@ -271,7 +276,6 @@ class Game: pass - # # Engine #