feat: add soft drop and exit on full well

This commit is contained in:
2021-06-10 18:25:54 -04:00
parent 65f2d299b9
commit 4cd6b606f3
4 changed files with 35 additions and 17 deletions

View File

@@ -11,16 +11,17 @@ from util.ConfigurationManager import ConfigurationManager
https://tetris.fandom.com/wiki/Tetromino
'''
class Piece(Entity):
GRAVITY = 300 # A move down every 300 ms
PIECE_SET = 750
def __init__(self, shape: Tuple, position: Tuple, color: str, inner_border_color: str, border_color: str):
super().__init__(self.__get_points(shape, position), color, border_color)
self.inner_border_color = inner_border_color
self.center = self.__get_center(shape, position)
self.gravity_time = ConfigurationManager.configuration["engine"]["piece-gravity-time"]
self.current_gravity_time = 0
self.set_time = ConfigurationManager.configuration["engine"]["piece-set-time"]
self.current_set_time = 0
self.piece_set_sound = mixer.Channel(2)
self.piece_set_time = 0
self.previous_points = None
self.previous_center = None
@@ -32,20 +33,20 @@ class Piece(Entity):
stack = tetris.stack
tile_size = ConfigurationManager.configuration["engine"]["tile-size"]
if self.elapsed_time >= Piece.GRAVITY and self.piece_set_time == 0:
self.elapsed_time -= Piece.GRAVITY
if self.elapsed_time >= self.gravity_time and self.current_set_time == 0:
self.elapsed_time = 0
self.move((0, tile_size))
if well and self.collide(well) or stack and self.collide(stack):
self.revert()
self.piece_set_time += elapsed_time
self.current_set_time += elapsed_time
if self.piece_set_time > 0:
self.piece_set_time += elapsed_time
if self.piece_set_time >= Piece.PIECE_SET:
if self.current_set_time > 0:
self.current_set_time += elapsed_time
if self.current_set_time >= self.set_time:
self.__play_piece_set_sound()
self.piece_set_time = 0
self.current_set_time = 0
stack.add_piece(self)
tetris.current_piece = None