Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/4 tetris block #7

Merged
merged 4 commits into from
Mar 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions src/game/block.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
class Block:
def __init__(self, x, y, blockType):
self.x = x
self.y = y
self.type = blockType
self.color = self.colors[blockType]
self.rotation = 0


figures = [
[[1, 5, 9, 13], [4, 5, 6, 7]], # I
[[4, 5, 9, 10], [2, 6, 5, 9]], # Z
[[6, 7, 9, 10], [1, 5, 6, 10]], # S
[[1, 2, 5, 9], [0, 4, 5, 6], [1, 5, 9, 8], [4, 5, 6, 10]], #L
[[1, 2, 6, 10], [5, 6, 7, 9], [2, 6, 10, 11], [3, 5, 6, 7]], # J
[[1, 4, 5, 6], [1, 4, 5, 9], [4, 5, 6, 9], [1, 5, 6, 9]], # T
[[1, 2, 5, 6]] # O
]

# Colors for the blocks
colors = [
(0, 255, 255), # I
(255, 0, 0), # Z
(0, 255, 0), # S
(255, 165, 0), # L
(0, 0, 255), # J
(128, 0, 128), # T
(255, 255, 0) # O
]

def rotate_left(self):
self.rotation = (self.rotation + 1) % len(self.figures[self.type])

def rotate_right(self):
self.rotation = (self.rotation - 1) % len(self.figures[self.type])

def get_block(self):
return self.figures[self.type][self.rotation]

def get_color(self):
return self.colors[self.type]

def get_x(self):
return self.x

def get_y(self):
return self.y

def set_x(self, x):
self.x = x

def set_y(self, y):
self.y = y

def get_position(self):
return self.x, self.y

def image(self):
return self.figures[self.type][self.rotation]

def get_block_coordinates(self):
# Calculate the coordinates for each block in the figure
positions = self.figures[self.type][self.rotation]
for i in range(4):
for j in range(4):
return
# If the block is in the figure, calculate the coordinates
## TODO: Fix the coordinates
Loading