feat: added border to piece
This commit is contained in:
@@ -9,8 +9,10 @@ engine:
|
||||
tile-size: 20
|
||||
|
||||
# https://coolors.co/6495ed-ee6352-59cd90-fac05e-f79d84
|
||||
# TODO change config color names, should be generic
|
||||
color:
|
||||
cornflower-blue: "#6495ED"
|
||||
fire-opal: "#EE6352"
|
||||
emerald: "#59CD90"
|
||||
maximum-yellow-red: "#59CD90"
|
||||
languid-lavender: "#DFD9E2"
|
||||
|
||||
@@ -7,8 +7,6 @@ from util.ConfigurationManager import ConfigurationManager
|
||||
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
|
||||
@@ -16,14 +14,31 @@ class Piece:
|
||||
|
||||
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)
|
||||
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
|
||||
|
||||
def draw(self, surface):
|
||||
pygame_color = pygame.Color(self.color)
|
||||
pygame.draw.polygon(surface, pygame_color, self.points, 0)
|
||||
tile_size = ConfigurationManager.configuration["engine"]["tile-size"]
|
||||
hex_color = ConfigurationManager.configuration["color"]["languid-lavender"]
|
||||
|
||||
base_color = pygame.Color(self.color) # TODO Should abstract color call?
|
||||
border_color = pygame.Color(hex_color)
|
||||
|
||||
for sub_points in self.points:
|
||||
pygame.draw.polygon(surface, base_color, sub_points, 0)
|
||||
pygame.draw.polygon(surface, border_color, sub_points, max(tile_size // 6, 1))
|
||||
|
||||
# rotate the piece clockwise
|
||||
def rotate():
|
||||
pass
|
||||
|
||||
# shape attributes
|
||||
I_SHAPE = (((0, 0), (1, 0), (1, 1), (0, 1)), ((1, 0), (2, 0), (2, 1), (1, 1)), ((2, 0), (3, 0), (3, 1), (2, 1)), ((3, 0), (4, 0), (4, 1), (3, 1)))
|
||||
4
main.py
4
main.py
@@ -10,8 +10,8 @@ def draw(screen):
|
||||
|
||||
fire_opal = ConfigurationManager.configuration["color"]["fire-opal"]
|
||||
|
||||
j_piece = Piece(Piece.J_SHAPE, (100, 100), fire_opal)
|
||||
j_piece.draw(screen)
|
||||
i_piece = Piece(Piece.I_SHAPE, (100, 100), fire_opal)
|
||||
i_piece.draw(screen)
|
||||
|
||||
# update display
|
||||
pygame.display.update()
|
||||
|
||||
Reference in New Issue
Block a user