feat: create class for well
This commit is contained in:
43
entity/Well.py
Normal file
43
entity/Well.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import pygame
|
||||
|
||||
from util.ConfigurationManager import ConfigurationManager
|
||||
|
||||
class Well:
|
||||
|
||||
WIDTH = 10 # standard tetris well width, should not be changed
|
||||
HEIGHT = 20 # standard tetris well height, should not be changed
|
||||
|
||||
def __init__(self, position):
|
||||
self.points = self.__get_points(position)
|
||||
|
||||
def draw(self, surface):
|
||||
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):
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
5
main.py
5
main.py
@@ -1,12 +1,14 @@
|
||||
'''
|
||||
Tetris 101:
|
||||
https://strategywiki.org/wiki/Tetris/Getting_Started
|
||||
https://tetris.com/play-tetris
|
||||
'''
|
||||
|
||||
import pygame
|
||||
|
||||
from util.ConfigurationManager import ConfigurationManager
|
||||
from util.PieceGenerator import PieceGenerator
|
||||
from entity.Well import Well
|
||||
|
||||
def draw(screen, objects):
|
||||
# draw window bg
|
||||
@@ -39,6 +41,7 @@ def main():
|
||||
pygame.display.set_icon(loaded_icon)
|
||||
|
||||
pieces = []
|
||||
well = Well((280, 80))
|
||||
x = 50
|
||||
y = 50
|
||||
for _ in range(6):
|
||||
@@ -65,7 +68,7 @@ def main():
|
||||
if event.key == pygame.K_DOWN:
|
||||
[piece.move((0, tile_size)) for piece in pieces]
|
||||
|
||||
draw(screen, pieces)
|
||||
draw(screen, pieces + [well])
|
||||
|
||||
pygame.quit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user