]> Untitled Git - catris.git/commitdiff
Broken: doesn't rotate correctly on the right side tetris
authorClifton Palmer <clifton.james.palmer@protonmail.com>
Mon, 7 Apr 2025 18:04:12 +0000 (21:04 +0300)
committerClifton Palmer <clifton.james.palmer@protonmail.com>
Tue, 8 Apr 2025 13:55:35 +0000 (16:55 +0300)
script/board.gd
script/piece.gd

index 4e7e80236619c75f66d35b19197f5213a27b2a2d..bc056160704b329a67381e209e3e16c80105faa1 100644 (file)
@@ -41,8 +41,26 @@ func _input(event: InputEvent) -> void:
                
        if event.is_action_pressed("player_up"):
                if _player_piece:
-                       _player_piece.rotate_left()
-                       print(_player_piece.to_string())
+                       _player_piece.rotate_cells_left()
+                       
+                       # if player piece has cells off to the right or left of the board,
+                       # then shift it back onto the board
+                       var leftmost: int = 0
+                       var rightmost: int = 0
+                       for pos: Vector2i in _player_piece.get_cell_grid():
+                               pos += _player_position # remember, pos is relative!
+                               if pos.x < leftmost:
+                                       leftmost = pos.x
+                               elif pos.x > _grid_final_x_row - 1 and pos.x > rightmost:
+                                       rightmost = pos.x - _grid_final_x_row - 1
+                       
+       
+                       print("l,r: %d, %d" % [leftmost, rightmost])
+                       
+                       if leftmost < 0:
+                               _move(-Vector2i(leftmost, 0))
+                       elif rightmost > 0:
+                               _move(-Vector2i(rightmost, 0))
 
        if event.is_action_pressed("player_down"):
                # move piece to bottom 
index fb82e449a0542f75827d1e8209723f221821f537..51582416c87a1cd8f8b6445425dee077a2196de4 100644 (file)
@@ -52,8 +52,17 @@ func get_cell_grid() -> Array:
        return _cell_grid.duplicate()
 
 
-func rotate_left():
+func rotate_cells_right():
+       _rotation_index -= 1
+       rotate_cells()
+
+
+func rotate_cells_left():
        _rotation_index += 1
+       rotate_cells()
+
+
+func rotate_cells():
        var new_cell_grid = get_cell_grid()
        
        for c in cells: