feat: implement gravity on current piece
This commit is contained in:
@@ -9,7 +9,9 @@ from util.ConfigurationManager import ConfigurationManager
|
||||
https://tetris.fandom.com/wiki/Tetromino
|
||||
'''
|
||||
class Piece(Entity):
|
||||
|
||||
|
||||
GRAVITY = 800 # A move down every 800 ms
|
||||
|
||||
def __init__(self, shape: Tuple, position: Tuple, color: str, border_color: str):
|
||||
super().__init__(self.__get_points(shape, position), color, border_color)
|
||||
self.center = self.__get_center(shape, position)
|
||||
@@ -17,7 +19,24 @@ class Piece(Entity):
|
||||
self.previous_points = None
|
||||
self.previous_center = None
|
||||
|
||||
def update(self, elapsed_time: int, well: Entity, stack: Entity):
|
||||
super().update(elapsed_time)
|
||||
|
||||
tile_size = ConfigurationManager.configuration["engine"]["tile-size"]
|
||||
if self.elapsed_time >= Piece.GRAVITY:
|
||||
self.elapsed_time -= Piece.GRAVITY
|
||||
|
||||
self.move((0, tile_size))
|
||||
if well and self.collide(well):
|
||||
self.revert()
|
||||
if stack and self.collide(stack):
|
||||
self.revert()
|
||||
|
||||
def move(self, vector: Tuple) -> None:
|
||||
# reset elapsed time if user moves down to stall gravity
|
||||
if vector[1] > 0:
|
||||
self.elapsed_time = 0
|
||||
|
||||
self.previous_points = copy.deepcopy(self.points)
|
||||
self.previous_center = copy.deepcopy(self.center)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user