X-Git-Url: http://git.purplebirdman.com/catris.git/blobdiff_plain/a626f4d0c215bd5f18ad3073ef9bda8e48ab8138..refs/heads/tetris:/script/piece.gd diff --git a/script/piece.gd b/script/piece.gd index 33a9c7d..5158241 100644 --- a/script/piece.gd +++ b/script/piece.gd @@ -33,23 +33,39 @@ func _ready() -> void: 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: - 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)) - 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: - assert(false, "Invalid rotation: " + str(global_rotation_degrees)) - return [] + assert(false, "Invalid rotation: " + str(rot)) + return _cell_grid.duplicate() + +func rotate_cells_right(): + _rotation_index -= 1 + rotate_cells() -func rotate_left(): + +func rotate_cells_left(): _rotation_index += 1 - rotation_degrees = _rotation_angles[_rotation_index % _rotation_angles.size()] + rotate_cells() + + +func rotate_cells(): + 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