Files
tetri5/entity/Well.py
2021-06-08 12:33:58 -04:00

45 lines
1.5 KiB
Python

from typing import List, Tuple
import pygame
from entity.Entity import Entity
from util.ConfigurationManager import ConfigurationManager
class Well(Entity):
WIDTH = 10 # standard tetris well width, should not be changed
HEIGHT = 20 # standard tetris well height, should not be changed
def __init__(self, position: Tuple):
self.points = self.__get_points(position)
def draw(self, surface: pygame.Surface) -> None:
well_color_hex = ConfigurationManager.configuration["color"]["border"] # TODO Should abstract out color call?
well_color = pygame.Color(well_color_hex)
for sub_points in self.points:
pygame.draw.polygon(surface, well_color, sub_points, 0)
def __get_points(self, position: Tuple) -> List:
tile_size = ConfigurationManager.configuration["engine"]["tile-size"]
shape = []
for i in range(self.WIDTH + 2):
for j in range(self.HEIGHT + 2):
if i == 0 or i == self.WIDTH + 1:
shape.append(((i, j), (i + 1, j), (i + 1, j + 1), (i, j + 1)))
elif j == 0 or j == self.HEIGHT + 1:
shape.append(((i, j), (i + 1, j), (i + 1, j + 1), (i, j + 1)))
points = []
for square in shape:
sub_points = []
for vertex in square:
point = [vertex[0] * tile_size + position[0], vertex[1] * tile_size + position[1]]
sub_points.append(point)
points.append(sub_points)
return points