Skip to content

Commit e4ef3a8

Browse files
committed
working on TetrisTwoBlockApp
1 parent 9774463 commit e4ef3a8

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

dumbdisplay_examples/tetris/_common.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,31 @@ def rotate(self, grid: Grid) -> bool:
8989
return False
9090
self.block_grid = rotated_block_grid
9191
self.y += y_offset
92-
self.rotation = (self.rotation + 90) % 360
92+
self.rotation = (self.rotation + 1) % 4
9393
if self.rotate_with_level:
9494
self.sync_image(self.move_reach_in_millis)
9595
else:
9696
self.block_pen.clear()
97+
#self.sync_image(self.move_reach_in_millis)
9798
_draw_grid(self.block_grid, self.block_pen)
9899
return True
99100

100101

101102
def sync_image(self, reach_in_millis: int = 0):
102-
anchor_x = self.x * _block_unit_width
103-
anchor_y = self.y * _block_unit_width
104-
self.block_pen.setLevelAnchor(anchor_x, anchor_y, reach_in_millis)
105103
if self.rotate_with_level:
106-
self.block_pen.setLevelRotation(self.rotation + 2, 90 + 10, 120 + 10, reach_in_millis) # calculated from _left and _top
104+
angle = 90 * self.rotation + 2
105+
pivot_x = 90 + 10
106+
pivot_y = 120 + 10
107+
anchor_x = self.x * _block_unit_width
108+
anchor_y = self.y * _block_unit_width
109+
# if self.rotation == 2:
110+
# anchor_x += _block_unit_width
111+
self.block_pen.setLevelRotation(angle, pivot_x, pivot_y, reach_in_millis) # calculated from _left and _top
112+
self.block_pen.setLevelAnchor(anchor_x, anchor_y, reach_in_millis)
113+
else:
114+
anchor_x = self.x * _block_unit_width
115+
anchor_y = self.y * _block_unit_width
116+
self.block_pen.setLevelAnchor(anchor_x, anchor_y, reach_in_millis)
107117

108118

109119

@@ -202,7 +212,8 @@ def _check_bad_block_grid_placement(block_grid: Grid, block_grid_x_off: int, blo
202212
def _rotate_block_grid_if_possible(block_grid: Grid, block_grid_x_off: int, block_grid_y_offset: int, grid: Grid) -> (Grid, int):
203213
block_grid_cells = block_grid.grid_cells
204214
rotated_cells = _rotate_block_grid_cells(block_grid_cells)
205-
y_offset = len(rotated_cells) - len(block_grid_cells)
215+
#y_offset = len(rotated_cells) - len(block_grid_cells)
216+
y_offset = 0
206217
if _check_bad_block_grid_cells_placement(rotated_cells, block_grid_x_off, block_grid_y_offset + y_offset, grid, check_boundary=True):
207218
return (None, None)
208219
rotated_block_grid = Grid(grid_cells=rotated_cells)

dumbdisplay_examples/tetris/tetris_classic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from dumbdisplay_examples.utils import DDAppBase, create_example_wifi_dd
1919

2020
_RANDOMIZE_ROW_COUNT = 2
21-
_ROTATE_WITH_LEVEL = True
21+
_ROTATE_WITH_LEVEL = False
2222

2323

2424
_delay = 0.3 # For time/sleep

0 commit comments

Comments
 (0)