Мне нужна помощь с проблемой, с которой я столкнулся в игре «Тетрис», которую я создаю. Блоки частей тетриса расположены на расстоянии пикселей друг от друга, поэтому они выглядят как один квадрат.
Фрагменты по сути являются классами:
class Piece:
def __init__(self, name: str):
self.name = name
self.rotation = 0
self.x = GRID_W / 2
self.y = -2
self.color = COLORS[name]
@property
def cells(self):
rot = self.rotation % 4
# print("rot : ",rot)
shape = SHAPES[self.name][rot]
cells = [(self.x + cx, self.y + cy) for (cx, cy) in shape]
return cells
def draw_piece(self):
# for x, y in self.cells:
# pygame.draw.rect(screen,self.color,(x-1,y+3,26,26),0,3)
cells = self.cells
cell1 = cells[0]
cell2 = cells[1]
cell3 = cells[2]
cell4 = cells[3]
# print(cell1,cell2,cell3,cell4)
# print(cell1[0],cell2[0],cell3[0],cell4[0])
# print(cell1[1],cell2[1],cell3[1],cell4[1]) # KNOW PROBLEM THE CELLS ARE CORRECT BUT THE POSITION IS EACH CELL IS JUST PIXELS AWAY FROM EACH OTHER AND WHEN ALL 4 OF THE CELLS ARE TOGETHER IT MAKES
filling = 0
if fill is False:
filling = 1
elif fill is not False:
filling = 0
t = 0
for x,y in cells:
t += 1
print(cells)
if t == 2:
filling = 0
pygame.draw.rect(screen,self.color,(x * times +x_offs,y * times +y_offs,size_x,size_y),filling,roundness)
# pygame.draw.rect(screen,self.color,(cell1[0] * times +x_offs,cell1[1] * times +y_offs,size_x,size_y),filling,roundness)
# pygame.draw.rect(screen,self.color,(cell2[0] * times +x_offs,cell2[1] * times +y_offs,size_x,size_y),filling,roundness)
# pygame.draw.rect(screen,self.color,(cell3[0] * times +x_offs,cell3[1] * times +y_offs,size_x,size_y),filling,roundness)
# pygame.draw.rect(screen,self.color,(cell4[0] * times +x_offs,cell4[1] * times +y_offs,size_x,size_y),filling,roundness)
Мне нужна помощь с проблемой, с которой я столкнулся в игре «Тетрис», которую я создаю. Блоки частей тетриса расположены на расстоянии пикселей друг от друга, поэтому они выглядят как один квадрат. Фрагменты по сути являются классами: [code]class Piece: def __init__(self, name: str): self.name = name self.rotation = 0 self.x = GRID_W / 2 self.y = -2 self.color = COLORS[name]
def draw_piece(self): # for x, y in self.cells: # pygame.draw.rect(screen,self.color,(x-1,y+3,26,26),0,3) cells = self.cells cell1 = cells[0] cell2 = cells[1] cell3 = cells[2] cell4 = cells[3] # print(cell1,cell2,cell3,cell4) # print(cell1[0],cell2[0],cell3[0],cell4[0]) # print(cell1[1],cell2[1],cell3[1],cell4[1]) # KNOW PROBLEM THE CELLS ARE CORRECT BUT THE POSITION IS EACH CELL IS JUST PIXELS AWAY FROM EACH OTHER AND WHEN ALL 4 OF THE CELLS ARE TOGETHER IT MAKES filling = 0 if fill is False: filling = 1 elif fill is not False: filling = 0 t = 0 for x,y in cells: t += 1 print(cells) if t == 2: filling = 0 pygame.draw.rect(screen,self.color,(x * times +x_offs,y * times +y_offs,size_x,size_y),filling,roundness)
# pygame.draw.rect(screen,self.color,(cell1[0] * times +x_offs,cell1[1] * times +y_offs,size_x,size_y),filling,roundness) # pygame.draw.rect(screen,self.color,(cell2[0] * times +x_offs,cell2[1] * times +y_offs,size_x,size_y),filling,roundness) # pygame.draw.rect(screen,self.color,(cell3[0] * times +x_offs,cell3[1] * times +y_offs,size_x,size_y),filling,roundness) # pygame.draw.rect(screen,self.color,(cell4[0] * times +x_offs,cell4[1] * times +y_offs,size_x,size_y),filling,roundness) [/code] Может ли кто-нибудь попытаться мне помочь?