Ich habe ein Problem und benötige eine Lösung für mein Tetris-SpielPython

Python-Programme
Anonymous
 Ich habe ein Problem und benötige eine Lösung für mein Tetris-Spiel

Post by Anonymous »

Ich brauche Hilfe bei einem Problem mit einem Tetris-Spiel, das ich mache. Die Blöcke der Tetris-Teile sind Pixel voneinander entfernt, sodass es wie ein einzelnes Quadrat aussieht.
Die Teile sind im Wesentlichen Klassen:

Code: Select all

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 [url=viewtopic.php?t=26065]PROBLEM[/url] 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)
Kann jemand versuchen, mir zu helfen?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post