Feature/advanced game mechanics #5
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user