move up held in next pieces

This commit is contained in:
adrienmalin 2019-10-06 10:57:45 +02:00
parent fe69557bc6
commit 0db5dd4d0d
5 changed files with 10 additions and 21 deletions

@ -26,7 +26,7 @@ from tetrislogic import TetrisLogic, Color, Phase, Coord, I_Tetrimino, Movement
# Matrix # Matrix
LINES = 20 LINES = 20
COLLUMNS = 10 COLLUMNS = 10
NEXT_PIECES = 5 NEXT_PIECES = 6
# Delays (seconds) # Delays (seconds)
LOCK_DELAY = 0.5 LOCK_DELAY = 0.5
@ -36,8 +36,8 @@ AUTOREPEAT_PERIOD = 0.010
# Piece init coord # Piece init coord
MATRIX_PIECE_COORD = Coord(4, LINES) MATRIX_PIECE_COORD = Coord(4, LINES)
NEXT_PIECES_COORDS = [Coord(COLLUMNS + 4, LINES - 4 * n - 3) for n in range(COLLUMNS)] NEXT_PIECES_COORDS = [Coord(COLLUMNS + 4, LINES - 4 * n) for n in range(NEXT_PIECES)]
HELD_PIECE_COORD = Coord(-5, LINES - 3) HELD_PIECE_COORD = Coord(-5, LINES)
# Window # Window
WINDOW_WIDTH = 800 WINDOW_WIDTH = 800
@ -212,10 +212,6 @@ class TetrArcade(TetrisLogic, arcade.Window):
self.bg = arcade.Sprite(WINDOW_BG_PATH) self.bg = arcade.Sprite(WINDOW_BG_PATH)
self.matrix.bg = arcade.Sprite(MATRIX_BG_PATH) self.matrix.bg = arcade.Sprite(MATRIX_BG_PATH)
self.matrix.bg.alpha = MATRIX_BG_ALPHA self.matrix.bg.alpha = MATRIX_BG_ALPHA
self.held.bg = arcade.Sprite(HELD_BG_PATH)
self.held.bg.alpha = BAR_ALPHA
self.next.bg = arcade.Sprite(NEXT_BG_PATH)
self.next.bg.alpha = BAR_ALPHA
self.matrix.sprites = MatrixSprites(self.matrix) self.matrix.sprites = MatrixSprites(self.matrix)
self.on_resize(self.init_width, self.init_height) self.on_resize(self.init_width, self.init_height)
@ -401,11 +397,12 @@ AGAIN""".format(
if combo_score: if combo_score:
self.show_text("COMBO x{:n}\n{:n}".format(nb_combo, combo_score)) self.show_text("COMBO x{:n}\n{:n}".format(nb_combo, combo_score))
def on_hold(self, held_piece): def on_hold(self, held_piece, falling_piece, ghost_piece):
held_piece.coord = HELD_PIECE_COORD held_piece.coord = HELD_PIECE_COORD
if type(held_piece) == I_Tetrimino: if type(held_piece) == I_Tetrimino:
held_piece.coord += Movement.LEFT held_piece.coord += Movement.LEFT
held_piece.sprites.refresh() held_piece.sprites.refresh()
ghost_piece.sprites = TetrominoSprites(ghost_piece, self, GHOST_ALPHA)
def pause(self): def pause(self):
super().pause() super().pause()
@ -455,8 +452,6 @@ AGAIN""".format(
if self.phase not in (Phase.STARTING, Phase.PAUSED): if self.phase not in (Phase.STARTING, Phase.PAUSED):
self.matrix.bg.draw() self.matrix.bg.draw()
self.held.bg.draw()
self.next.bg.draw()
self.matrix.sprites.draw() self.matrix.sprites.draw()
for tetromino in [ for tetromino in [
@ -545,14 +540,6 @@ AGAIN""".format(
self.matrix.bg.left = int(self.matrix.bg.left) self.matrix.bg.left = int(self.matrix.bg.left)
self.matrix.bg.top = int(self.matrix.bg.top) self.matrix.bg.top = int(self.matrix.bg.top)
self.held.bg.scale = self.scale
self.held.bg.right = self.matrix.bg.left
self.held.bg.top = self.matrix.bg.top
self.next.bg.scale = self.scale
self.next.bg.left = self.matrix.bg.right
self.next.bg.top = self.matrix.bg.top
self.matrix.sprites.resize(self.scale) self.matrix.sprites.resize(self.scale)
for tetromino in [ for tetromino in [

Binary file not shown.

Before

(image error) Size: 499 B

Binary file not shown.

Before

(image error) Size: 475 B

@ -175,6 +175,7 @@ class TetrisLogic:
pass pass
def generation_phase(self): def generation_phase(self):
self.phase = Phase.GENERATION
self.matrix.piece = self.next.pieces.pop(0) self.matrix.piece = self.next.pieces.pop(0)
self.next.pieces.append(Tetromino()) self.next.pieces.append(Tetromino())
self.matrix.piece.coord = self.MATRIX_PIECE_COORD self.matrix.piece.coord = self.MATRIX_PIECE_COORD
@ -273,16 +274,16 @@ class TetrisLogic:
self.stop(self.fall) self.stop(self.fall)
self.matrix.piece, self.held.piece = self.held.piece, self.matrix.piece self.matrix.piece, self.held.piece = self.held.piece, self.matrix.piece
self.on_hold(self.held.piece)
if self.matrix.piece: if self.matrix.piece:
self.matrix.piece.coord = self.MATRIX_PIECE_COORD self.matrix.piece.coord = self.MATRIX_PIECE_COORD
self.matrix.ghost = self.matrix.piece.ghost() self.matrix.ghost = self.matrix.piece.ghost()
self.on_hold(self.held.piece, self.matrix.piece, self.matrix.ghost)
self.falling_phase() self.falling_phase()
else: else:
self.generation_phase() self.generation_phase()
self.on_hold(self.held.piece, self.matrix.piece, self.matrix.ghost)
def on_hold(self, held_piece): def on_hold(self, held_piece, falling_piece, ghost_piece):
pass pass
def pattern_phase(self): def pattern_phase(self):

@ -42,6 +42,7 @@ class Color:
class Phase: class Phase:
STARTING = "STARTING" STARTING = "STARTING"
GENERATION = "GENERATION"
FALLING = "FALLING" FALLING = "FALLING"
LOCK = "LOCK" LOCK = "LOCK"
PATTERN = "PATTERN" PATTERN = "PATTERN"