29 lines
907 B
Python
29 lines
907 B
Python
import pygame
|
|
|
|
from util.ConfigurationManager import ConfigurationManager
|
|
|
|
'''
|
|
For information on the Tetris piece Tetromino go here:
|
|
https://tetris.fandom.com/wiki/Tetromino
|
|
'''
|
|
class Piece:
|
|
|
|
J_SHAPE = ((0, 0), (1, 0), (2, 0), (3, 0), (3, 1), (3, 2), (2, 2), (2, 1), (1, 1), (0, 1))
|
|
|
|
def __init__(self, shape, position, color):
|
|
self.color = color
|
|
self.points = self.__get_points(shape, position)
|
|
|
|
def __get_points(self, shape, position):
|
|
tile_size = ConfigurationManager.configuration["engine"]["tile-size"]
|
|
points = []
|
|
|
|
for vertex in shape:
|
|
point = [vertex[0] * tile_size + position[0], vertex[1] * tile_size + position[1]]
|
|
points.append(point)
|
|
|
|
return points
|
|
|
|
def draw(self, surface):
|
|
pygame_color = pygame.Color(self.color)
|
|
pygame.draw.polygon(surface, pygame_color, self.points, 0) |