]> Untitled Git - catris.git/commitdiff
Finished rotations, still have border problems
authorClifton Palmer <clifton.james.palmer@protonmail.com>
Thu, 27 Mar 2025 13:19:41 +0000 (15:19 +0200)
committerClifton Palmer <clifton.james.palmer@protonmail.com>
Thu, 27 Mar 2025 13:19:41 +0000 (15:19 +0200)
script/board.gd
script/piece.gd

index 6109ed342269e6a87ccf8bcbf39ce953d1174234..2e90425247b3dd9d6f75842c03f14467cbba98a5 100644 (file)
@@ -16,6 +16,7 @@ var _grid_final_y_row: int = 0
 var _grid_final_x_row: int = 0
 
 var num_pieces: int = 0
 var _grid_final_x_row: int = 0
 
 var num_pieces: int = 0
+const start_pos: Vector2i = Vector2i(5, 2)
 
 func _ready() -> void:
        assert(piece_catalogue.size() >= 1, "Expected at least one piece in catalogue")
 
 func _ready() -> void:
        assert(piece_catalogue.size() >= 1, "Expected at least one piece in catalogue")
@@ -53,7 +54,7 @@ func _add_player_piece():
        piece.block_size = block_size
        
        # TODO: start piece at center of board
        piece.block_size = block_size
        
        # TODO: start piece at center of board
-       _player_position = Vector2i(5, 0)
+       _player_position = start_pos
        piece.position = _player_position * block_size
        _player_piece = piece
        
        piece.position = _player_position * block_size
        _player_piece = piece
        
index 33a9c7daf92b97e1e3d8ef07ea33f3b56bba9c4d..fb82e449a0542f75827d1e8209723f221821f537 100644 (file)
@@ -33,23 +33,30 @@ func _ready() -> void:
 
 
 func _to_string() -> String:
 
 
 func _to_string() -> String:
-       return "%d: %s" % [rotation_degrees, str(get_cell_grid())]
+       return "%d: %s" % [_rotation_angles[_rotation_index % _rotation_angles.size()], str(get_cell_grid())]
 
 
 func get_cell_grid() -> Array:
 
 
 func get_cell_grid() -> Array:
-       if rotation_degrees == 0.0:
-               return _cell_grid
-       elif rotation_degrees == 90.0:
-               return _cell_grid.map(func f(v): return Vector2i(v.y, v.x))
-       elif rotation_degrees == 180.0:
+       var rot = _rotation_angles[_rotation_index % _rotation_angles.size()]
+       
+       if rot == 0.0:
+               return _cell_grid.duplicate()
+       elif rot == 90.0:
+               return _cell_grid.map(func f(v): return Vector2i(-v.y, v.x))
+       elif rot == 180.0:
                return _cell_grid.map(func f(v): return Vector2i(-v.x, -v.y))
                return _cell_grid.map(func f(v): return Vector2i(-v.x, -v.y))
-       elif rotation_degrees == 270.0:
-               return _cell_grid.map(func f(v): return Vector2i(-v.y, -v.x))
+       elif rot == 270.0:
+               return _cell_grid.map(func f(v): return Vector2i(v.y, -v.x))
        else:
        else:
-               assert(false, "Invalid rotation: " + str(global_rotation_degrees))
-       return []
+               assert(false, "Invalid rotation: " + str(rot))
+       return _cell_grid.duplicate()
 
 
 func rotate_left():
        _rotation_index += 1
 
 
 func rotate_left():
        _rotation_index += 1
-       rotation_degrees = _rotation_angles[_rotation_index % _rotation_angles.size()]
+       var new_cell_grid = get_cell_grid()
+       
+       for c in cells:
+               var new_pos: Vector2i = new_cell_grid.pop_front()
+               c.position.x = new_pos.x * block_size
+               c.position.y = new_pos.y * block_size