diff --git a/src/lib/tick/tick.js b/src/lib/tick/tick.js index ca0b9c1..95ac1f8 100644 --- a/src/lib/tick/tick.js +++ b/src/lib/tick/tick.js @@ -41,12 +41,14 @@ export function tick(game, containerWidth, containerHeight, deltaTime) { if (ball.x <= leftBoundary || ball.x >= rightBoundary) { ball.x = ball.x <= leftBoundary ? leftBoundary : rightBoundary; ball.horizontalSpeed *= -1; + return; } // Не даем мячу выйти за границу стены сверху и меняем направление if (ball.y <= topBoundary) { ball.y = topBoundary; ball.verticalSpeed *= -1; + return; } // Проверяем выход за границу стены снизу @@ -84,7 +86,7 @@ export function tick(game, containerWidth, containerHeight, deltaTime) { ball.horizontalSpeed *= directions[0]; ball.verticalSpeed *= directions[1]; brick.kill(); - break; + return; } } } diff --git a/src/lib/tick/tick.test.js b/src/lib/tick/tick.test.js index 879c79f..6e3b181 100644 --- a/src/lib/tick/tick.test.js +++ b/src/lib/tick/tick.test.js @@ -50,7 +50,7 @@ describe('tick', () => { const game = new Game(1, 1); const brick = game.bricks[0][0]; - game.ball.x = brick.x + 1; + game.ball.x = brick.x + game.ball.radius + 1; game.ball.y = brick.y + brick.height + game.ball.radius + 1; game.ball.horizontalSpeed = 0; game.ball.verticalSpeed = -10; @@ -65,7 +65,7 @@ describe('tick', () => { const game = new Game(2, 1); const [firstBrick, secondBrick] = game.bricks[0]; - game.ball.x = firstBrick.x + 1; + game.ball.x = firstBrick.x + game.ball.radius + 1; game.ball.y = firstBrick.y + firstBrick.height + game.ball.radius + 1; game.ball.horizontalSpeed = 0; game.ball.verticalSpeed = -10;