function bounceOffBricks() {
let {x, y, vx, vy, r} = mutable ball;
eachBrick(mutable bricks, (brick, row, col) => {
const hit = collideWithBrick(brick, mutable ball);
if (hit === direction.none) return false;
mutable score += brick.points;
if (hit === direction.vertical) {
if (vy > 0) {
let highBoundary = brick.y - r;
y = -y + 2 * highBoundary;
} else {
let lowBoundary = brick.y + brick.h + r;
y = -y + 2 * lowBoundary;
}
vy = -vy;
} else {
if (vx > 0) {
let leftBoundary = brick.x - r;
x = -x + 2 * leftBoundary;
} else {
let rightBoundary = brick.x + brick.w + r;
x = -x + 2 * rightBoundary;
}
vx = -vx;
}
bricks[row][col] = undefined;
return hit !== direction.none;
});
mutable ball = {x, y, vx, vy, r};
}