little improvements
This commit is contained in:
parent
28a8ea0953
commit
c5c21c5017
@ -207,6 +207,7 @@ class TetrominoSprites(MinoesSprites):
|
|||||||
def set_texture(self, texture):
|
def set_texture(self, texture):
|
||||||
for mino in self.tetromino:
|
for mino in self.tetromino:
|
||||||
mino.sprite.set_texture(texture)
|
mino.sprite.set_texture(texture)
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
|
||||||
class MatrixSprites(MinoesSprites):
|
class MatrixSprites(MinoesSprites):
|
||||||
@ -413,14 +414,15 @@ AGAIN""".format(
|
|||||||
for piece, coord in zip(next_pieces, NEXT_PIECES_COORDS):
|
for piece, coord in zip(next_pieces, NEXT_PIECES_COORDS):
|
||||||
piece.coord = coord
|
piece.coord = coord
|
||||||
|
|
||||||
def on_falling_phase(self, falling_piece, ghost_piece):
|
def on_falling_phase(self, falling_piece):
|
||||||
falling_piece.sprites.set_texture(Texture.NORMAL)
|
falling_piece.sprites.set_texture(Texture.NORMAL)
|
||||||
|
|
||||||
def on_lock_phase(self, falling_piece):
|
def on_locked(self, falling_piece):
|
||||||
falling_piece.sprites.set_texture(Texture.LOCKED)
|
falling_piece.sprites.set_texture(Texture.LOCKED)
|
||||||
|
|
||||||
def on_locks_down(self, matrix, locked_piece):
|
def on_locks_down(self, matrix, falling_piece):
|
||||||
for mino in locked_piece:
|
falling_piece.sprites.set_texture(Texture.NORMAL)
|
||||||
|
for mino in falling_piece:
|
||||||
matrix.sprites.append(mino.sprite)
|
matrix.sprites.append(mino.sprite)
|
||||||
|
|
||||||
def on_animate_phase(self, matrix, lines_to_remove):
|
def on_animate_phase(self, matrix, lines_to_remove):
|
||||||
@ -436,7 +438,7 @@ AGAIN""".format(
|
|||||||
2 * COLLUMNS * MINO_SIZE,
|
2 * COLLUMNS * MINO_SIZE,
|
||||||
5 * MINO_SIZE,
|
5 * MINO_SIZE,
|
||||||
),
|
),
|
||||||
lifetime=1,
|
lifetime=.2,
|
||||||
center_xy=arcade.rand_on_line((0, 0), (matrix.bg.width, 0)),
|
center_xy=arcade.rand_on_line((0, 0), (matrix.bg.width, 0)),
|
||||||
scale=self.scale,
|
scale=self.scale,
|
||||||
alpha=NORMAL_ALPHA,
|
alpha=NORMAL_ALPHA,
|
||||||
@ -639,11 +641,9 @@ High score could not be saved:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def update(self, delta_time):
|
def update(self, delta_time):
|
||||||
for piece in [self.held.piece, self.matrix.ghost] + self.next.pieces:
|
for piece in [self.held.piece, self.matrix.piece, self.matrix.ghost] + self.next.pieces:
|
||||||
if piece:
|
if piece:
|
||||||
piece.sprites.update()
|
piece.sprites.update()
|
||||||
if self.matrix.piece:
|
|
||||||
self.matrix.piece.sprites.update()
|
|
||||||
for exploding_minoes in self.exploding_minoes:
|
for exploding_minoes in self.exploding_minoes:
|
||||||
if exploding_minoes:
|
if exploding_minoes:
|
||||||
exploding_minoes.update()
|
exploding_minoes.update()
|
||||||
|
@ -197,6 +197,8 @@ class TetrisLogic:
|
|||||||
def on_new_level(self, level):
|
def on_new_level(self, level):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Tetris Engine
|
||||||
|
|
||||||
def generation_phase(self, held_piece=None):
|
def generation_phase(self, held_piece=None):
|
||||||
if not held_piece:
|
if not held_piece:
|
||||||
self.matrix.piece = self.next.pieces.pop(0)
|
self.matrix.piece = self.next.pieces.pop(0)
|
||||||
@ -204,8 +206,8 @@ class TetrisLogic:
|
|||||||
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.refresh_ghost()
|
self.refresh_ghost()
|
||||||
if self.pressed_actions:
|
#if self.pressed_actions:
|
||||||
self.timer.postpone(self.repeat_action, self.AUTOREPEAT_DELAY)
|
# self.timer.postpone(self.repeat_action, self.AUTOREPEAT_DELAY)
|
||||||
|
|
||||||
self.on_generation_phase(
|
self.on_generation_phase(
|
||||||
self.matrix, self.matrix.piece, self.matrix.ghost, self.next.pieces
|
self.matrix, self.matrix.piece, self.matrix.ghost, self.next.pieces
|
||||||
@ -230,19 +232,18 @@ class TetrisLogic:
|
|||||||
|
|
||||||
def falling_phase(self):
|
def falling_phase(self):
|
||||||
self.timer.cancel(self.lock_phase)
|
self.timer.cancel(self.lock_phase)
|
||||||
|
self.timer.cancel(self.locks_down)
|
||||||
self.matrix.piece.locked = False
|
self.matrix.piece.locked = False
|
||||||
self.timer.postpone(self.lock_phase, self.stats.fall_delay)
|
self.timer.postpone(self.lock_phase, self.stats.fall_delay)
|
||||||
self.on_falling_phase(self.matrix.piece, self.matrix.ghost)
|
self.on_falling_phase(self.matrix.piece)
|
||||||
|
|
||||||
def on_falling_phase(self, falling_piece, ghost_piece):
|
def on_falling_phase(self, falling_piece):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def lock_phase(self):
|
def lock_phase(self):
|
||||||
self.matrix.piece.locked = True
|
self.move(Movement.DOWN)
|
||||||
if not self.move(Movement.DOWN):
|
|
||||||
self.locks_down()
|
|
||||||
|
|
||||||
def on_lock_phase(self, falling_piece):
|
def on_locked(self, falling_piece):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def move(self, movement, rotated_coords=None, lock=True):
|
def move(self, movement, rotated_coords=None, lock=True):
|
||||||
@ -256,11 +257,11 @@ class TetrisLogic:
|
|||||||
self.refresh_ghost()
|
self.refresh_ghost()
|
||||||
if movement != Movement.DOWN:
|
if movement != Movement.DOWN:
|
||||||
self.matrix.piece.last_rotation_point = None
|
self.matrix.piece.last_rotation_point = None
|
||||||
if self.matrix.space_to_fall:
|
if self.matrix.space_to_fall():
|
||||||
self.falling_phase()
|
self.falling_phase()
|
||||||
else:
|
else:
|
||||||
self.on_lock_phase(self.matrix.piece)
|
self.matrix.piece.locked = True
|
||||||
if self.matrix.piece.locked:
|
self.on_locked(self.matrix.piece)
|
||||||
self.timer.reset(self.locks_down, self.stats.lock_delay)
|
self.timer.reset(self.locks_down, self.stats.lock_delay)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
@ -284,6 +285,9 @@ class TetrisLogic:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def locks_down(self):
|
def locks_down(self):
|
||||||
|
#self.timer.cancel(self.repeat_action)
|
||||||
|
self.timer.cancel(self.lock_phase)
|
||||||
|
|
||||||
# Game over
|
# Game over
|
||||||
if all(
|
if all(
|
||||||
(mino.coord + self.matrix.piece.coord).y >= self.matrix.lines
|
(mino.coord + self.matrix.piece.coord).y >= self.matrix.lines
|
||||||
@ -292,8 +296,6 @@ class TetrisLogic:
|
|||||||
self.game_over()
|
self.game_over()
|
||||||
return
|
return
|
||||||
|
|
||||||
self.timer.cancel(self.repeat_action)
|
|
||||||
|
|
||||||
for mino in self.matrix.piece:
|
for mino in self.matrix.piece:
|
||||||
coord = mino.coord + self.matrix.piece.coord
|
coord = mino.coord + self.matrix.piece.coord
|
||||||
if coord.y <= self.matrix.lines + 3:
|
if coord.y <= self.matrix.lines + 3:
|
||||||
@ -352,7 +354,7 @@ class TetrisLogic:
|
|||||||
else:
|
else:
|
||||||
self.generation_phase()
|
self.generation_phase()
|
||||||
|
|
||||||
def on_locks_down(self, matrix, locked_piece):
|
def on_locks_down(self, matrix, falling_piece):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def on_animate_phase(self, matrix, lines_to_remove):
|
def on_animate_phase(self, matrix, lines_to_remove):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user