From fea05e6b97056115600f4263a173495e4458398f Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Sat, 18 Jul 2026 13:01:43 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B8=D0=B3=D1=80=D1=8B=D1=88=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entities/ball/ball.js | 2 ++ src/game.js | 16 ++++++++++++++++ src/lib/tick/tick.js | 12 +++++++++--- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/entities/ball/ball.js b/src/entities/ball/ball.js index 84deaa0..f2c96c0 100644 --- a/src/entities/ball/ball.js +++ b/src/entities/ball/ball.js @@ -16,6 +16,7 @@ export class Ball { this.radius = radius; this.verticalSpeed = verticalSpeed; this.horizontalSpeed = horizontalSpeed; + this.isOut = false; this.defaultX = x; this.defaultY = y; @@ -40,5 +41,6 @@ export class Ball { this.y = this.defaultY; this.verticalSpeed = this.defaultVerticalSpeed; this.horizontalSpeed = this.defaultHorizontalSpeed; + this.isOut = false; } } diff --git a/src/game.js b/src/game.js index 22c28cb..b6cfa4b 100644 --- a/src/game.js +++ b/src/game.js @@ -23,6 +23,9 @@ export class Game { * @param {number} rowAmount количество кирпичей по оси Y, неотрицателное, целое число */ constructor(columnAmount, rowAmount) { + this.livesAmount = 3; + this.status = 'in_process'; + this.ball = new Ball( CONTAINER_WIDTH / 2 - BALL_RADIUS, CONTAINER_HEIGHT / 2 - BALL_RADIUS, @@ -40,6 +43,19 @@ export class Game { * @param {*} deltaTime изменение времени из Ticker */ update(deltaTime) { + if (this.status !== 'in_process') { + return; + } tick(this, CONTAINER_WIDTH, CONTAINER_HEIGHT, deltaTime); + + if (this.ball.isOut) { + this.livesAmount -= 1; + + if (this.livesAmount === 0) { + this.status = 'over'; + } else { + this.ball.reset(); + } + } } } diff --git a/src/lib/tick/tick.js b/src/lib/tick/tick.js index 3ca17bc..ca0b9c1 100644 --- a/src/lib/tick/tick.js +++ b/src/lib/tick/tick.js @@ -43,12 +43,18 @@ export function tick(game, containerWidth, containerHeight, deltaTime) { ball.horizontalSpeed *= -1; } - // Не даем мячу выйти за границы стен сверху / снизу и меняем направление - if (ball.y <= topBoundary || ball.y >= bottomBoundary) { - ball.y = ball.y <= topBoundary ? topBoundary : bottomBoundary; + // Не даем мячу выйти за границу стены сверху и меняем направление + if (ball.y <= topBoundary) { + ball.y = topBoundary; ball.verticalSpeed *= -1; } + // Проверяем выход за границу стены снизу + if (ball.y >= bottomBoundary) { + game.ball.isOut = true; + return; + } + // Базоввое взаимодействие мяча и кирпича for (const row of bricks) { for (const brick of row) {