From d149721a84b4ef3e6a8ea546c54cb2953294fa9c Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Fri, 17 Jul 2026 08:31:42 +0300 Subject: [PATCH 01/18] =?UTF-8?q?feature:=20=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D1=8C?= =?UTF-8?q?=20=D0=BC=D1=8F=D1=87=D0=B0=20=D0=B2=D1=8B=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D0=B0=D1=8F=20=D0=B2=20=D0=BA=D0=BB=D0=B0?= =?UTF-8?q?=D1=81=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entities/ball/ball.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/entities/ball/ball.js diff --git a/src/entities/ball/ball.js b/src/entities/ball/ball.js new file mode 100644 index 0000000..d79b869 --- /dev/null +++ b/src/entities/ball/ball.js @@ -0,0 +1,27 @@ +/** + * Класс сущности "мяч" + * @class + */ +export class Ball { + /** + * @param {number} x координата положения мяча по оси X + * @param {number} y координата положения мяча по оси Y + * @param {number} radius положительное числовое значение радиуса мяча + */ + constructor(x, y, radius) { + this.x = x; + this.y = y; + this.horizontalSpeed = 0; + this.verticalSpeed = 0; + this.radius = radius; + } + + /** + * Изменяет координаты в зависимости от скорости и времени + * @param {*} deltaTime изменение времени из Ticker + */ + moveForvard(deltaTime) { + this.x += this.horizontalSpeed * deltaTime; + this.y += this.verticalSpeed * deltaTime; + } +} -- 2.54.0 From e03b71d4afd44cc5dbe0bacb367cc9a20ce96ba5 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Fri, 17 Jul 2026 08:36:06 +0300 Subject: [PATCH 02/18] =?UTF-8?q?feature:=20=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D1=8C?= =?UTF-8?q?=20=D0=BA=D0=B8=D1=80=D0=BF=D0=BF=D0=B8=D1=87=D0=B0=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=BD=D0=B0=D1=8F=20=D0=B2?= =?UTF-8?q?=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entities/brick/brick.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/entities/brick/brick.js diff --git a/src/entities/brick/brick.js b/src/entities/brick/brick.js new file mode 100644 index 0000000..8151678 --- /dev/null +++ b/src/entities/brick/brick.js @@ -0,0 +1,24 @@ +/** + * Класс сущности "кирпич" + * @class + */ +export class Brick { + /** + * + * @param {number} x координата положения кирпича по оси X + * @param {number} y координата положения кирпича по оси Y + * @param {number} width положительное числовое значение ширины кирпича + * @param {number} height положительное числовое значение высоты кирпича + */ + constructor(x, y, width, height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + this.alive = true; + } + + kill() { + this.alive = false; + } +} -- 2.54.0 From 2c61825642fcd7371cdc28679332e75571351e38 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Fri, 17 Jul 2026 08:37:25 +0300 Subject: [PATCH 03/18] =?UTF-8?q?feature:=20=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D1=8C?= =?UTF-8?q?=20=D1=80=D0=B0=D0=BA=D0=B5=D1=82=D0=BA=D0=B8=20=D0=B2=D1=8B?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=BD=D0=B0=D1=8F=20=D0=B2=20?= =?UTF-8?q?=D0=BA=D0=BB=D0=B0=D1=81=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entities/paddle/paddle.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/entities/paddle/paddle.js diff --git a/src/entities/paddle/paddle.js b/src/entities/paddle/paddle.js new file mode 100644 index 0000000..80eb32b --- /dev/null +++ b/src/entities/paddle/paddle.js @@ -0,0 +1,17 @@ +/** + * Класс сущности "ракетка" + */ +export class Paddle { + /** + * @param {number} x координата положения ракетки по оси X + * @param {number} y координата положения ракетки по оси Y + * @param {number} width положительное числовое значение ширины ракетки + * @param {number} height положительное числовое значение высоты ракетки + */ + constructor(x, y, width, height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } +} -- 2.54.0 From 67c98a3773294dd8a0c04872885fc40780572b93 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Fri, 17 Jul 2026 10:39:59 +0300 Subject: [PATCH 04/18] =?UTF-8?q?feat(layBricks):=20=D0=94=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D1=84=D1=83=D0=BD=D0=BA?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=20layBricks=20=D1=81=D0=BE=D0=B7=D0=B4?= =?UTF-8?q?=D0=B0=D1=8E=D1=89=D0=B0=D1=8F=20=D0=BC=D0=B0=D1=81=D1=81=D0=B8?= =?UTF-8?q?=D0=B2=20=D1=80=D1=8F=D0=B4=D0=BE=D0=B2=20=D0=BA=D0=B8=D1=80?= =?UTF-8?q?=D0=BF=D0=B8=D1=87=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entities/brick/layBricks/layBricks.js | 41 +++++++++++++ .../brick/layBricks/layBricks.test.js | 59 +++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 src/entities/brick/layBricks/layBricks.js create mode 100644 src/entities/brick/layBricks/layBricks.test.js diff --git a/src/entities/brick/layBricks/layBricks.js b/src/entities/brick/layBricks/layBricks.js new file mode 100644 index 0000000..9dc722b --- /dev/null +++ b/src/entities/brick/layBricks/layBricks.js @@ -0,0 +1,41 @@ +import { Brick } from '../brick'; + +/** + * Ложит кирпичи по заданым размерам + * @param {number} columnAmount количество кирпичей по оси X, неотрицателное, целое число + * @param {number} rowAmount количество кирпичей по оси Y, неотрицателное, целое число + * @param {number} brickWidth ширина кирпича, неотрицателное число + * @param {number} brickHeight длина кирпича, неотрицателное число + * @returns {Brick[][]} массив с массивами кирпичей + */ +export function layBricks(columnAmount, rowAmount, brickWidth, brickHeight) { + try { + const someArgsArentNumbers = [columnAmount, rowAmount, brickWidth, brickHeight].some( + (arg) => typeof arg !== 'number', + ); + if (someArgsArentNumbers) { + throw new Error('Параметры кладки кирпичей должны являться числами'); + } + + const someArgsLessThanZero = [columnAmount, rowAmount, brickWidth, brickHeight].some((arg) => arg < 0); + if (someArgsLessThanZero) { + throw new Error('Параметры кладки кирпичей должны являться положительными целыми числами'); + } + + const rowsOrColumnsAreFloat = [columnAmount, rowAmount].some((amount) => amount % 1 !== 0); + if (rowsOrColumnsAreFloat) { + throw new Error('Размеры рядов и колонок должны являться целыми числами'); + } + + const bricks = Array.from({ length: rowAmount }).map((_, rowIndex) => + Array.from({ length: columnAmount }).map( + (_, columnIndex) => new Brick(columnIndex * brickWidth, rowIndex * brickHeight, brickWidth, brickHeight), + ), + ); + + return bricks; + } catch (err) { + console.error(err); + return null; + } +} diff --git a/src/entities/brick/layBricks/layBricks.test.js b/src/entities/brick/layBricks/layBricks.test.js new file mode 100644 index 0000000..7e665bb --- /dev/null +++ b/src/entities/brick/layBricks/layBricks.test.js @@ -0,0 +1,59 @@ +import { expect } from 'vitest'; +import { layBricks } from './layBricks'; + +describe('layBricks', () => { + it('Возвращает корректное значение в случае неверного типа параметра', () => { + const wrongType = 'wrong'; + + expect(layBricks(wrongType, 1, 1, 1)).toBeNull(); + expect(layBricks(1, wrongType, 1, 1)).toBeNull(); + expect(layBricks(1, 1, wrongType, 1)).toBeNull(); + expect(layBricks(1, 1, 1, wrongType)).toBeNull(); + }); + + it('Возвращает корректное значение в случае неверных размеров кирпича', () => { + const wrongWidth = -1; + const wrongHeight = -1; + + expect(layBricks(1, 1, wrongWidth, 1)).toBeNull(); + expect(layBricks(1, 1, 1, wrongHeight)).toBeNull(); + }); + + it('Возвращает корректное значение в случае неверных значений рядов и колонок', () => { + const negativeRow = -1; + const negativeColumn = -1; + const decimalRow = 1.5; + const decimalColumn = 1.5; + + expect(layBricks(negativeRow, 1, 1, 1)).toBeNull(); + expect(layBricks(1, negativeColumn, 1, 1)).toBeNull(); + expect(layBricks(decimalRow, 1, 1, 1)).toBeNull(); + expect(layBricks(1, decimalColumn, 1, 1)).toBeNull(); + }); + + it('Возвращает массив корректных размеров', () => { + const columnAmount = 10; + const rowAmount = 5; + + const bricks = layBricks(columnAmount, rowAmount, 1, 1); + expect(bricks.length).toEqual(rowAmount); + for (const row of bricks) { + expect(row.length).toEqual(columnAmount); + } + }); + + it('Задает корректные координаты кирпичам', () => { + const bricks = layBricks(3, 3, 1, 1); + const columnAmount = 10; + const rowAmount = 5; + + const brickss = layBricks(columnAmount, rowAmount, 1, 1); + + for (let i = 0; i < rowAmount; i++) { + for (let j = 0; j < columnAmount; j++) { + expect(brickss[i][j].x).toEqual(j); + expect(brickss[i][j]?.y).toEqual(i); + } + } + }); +}); -- 2.54.0 From a4f56674a7771dc7ff5a841eb8fa204f899332e6 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Fri, 17 Jul 2026 10:51:43 +0300 Subject: [PATCH 05/18] =?UTF-8?q?feat:=20=D0=92=20=D0=BA=D0=BB=D0=B0=D1=81?= =?UTF-8?q?=D1=81=20Paddle=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=BE=D0=B3=D1=80=D0=B0=D0=BD=D0=B8=D1=87=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=BE=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D1=80=D0=B0=D0=BA=D0=B5=D1=82=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entities/paddle/paddle.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/entities/paddle/paddle.js b/src/entities/paddle/paddle.js index 80eb32b..23c24d0 100644 --- a/src/entities/paddle/paddle.js +++ b/src/entities/paddle/paddle.js @@ -14,4 +14,16 @@ export class Paddle { this.width = width; this.height = height; } + + /** + * Ограничивает минимальные и максимальные координаты положения ракетки на оси X + * @param {number} containerWidth ширина игрового поля + */ + clampTo(containerWidth) { + if (this.x <= 0) { + this.x = 0; + } else if (this.x >= containerWidth - this.width) { + this.x = containerWidth - this.width; + } + } } -- 2.54.0 From 384b04f363752ae64c0df16b6eb1fb0bde8dabbb Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Fri, 17 Jul 2026 11:06:27 +0300 Subject: [PATCH 06/18] =?UTF-8?q?feat:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20Game=20?= =?UTF-8?q?=D1=81=20=D0=B8=D0=BD=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B5=D0=B9=20=D0=BE=20=D0=B2=D1=81=D0=B5=D1=85=20=D0=B8=D0=B3?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D1=8B=D1=85=20=D1=81=D1=83=D1=89=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=8F=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/game.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/game.js diff --git a/src/game.js b/src/game.js new file mode 100644 index 0000000..aca5f7e --- /dev/null +++ b/src/game.js @@ -0,0 +1,33 @@ +import { + BALL_INITIAL_ANGLE, + BALL_RADIUS, + BALL_SPEED, + BRICK_HEIGHT, + BRICK_WIDTH, + CONTAINER_HEIGHT, + CONTAINER_WIDTH, + PADDLE_HEIGHT, + PADDLE_WIDTH, +} from './config'; +import { Ball } from './entities/ball/ball'; +import { layBricks } from './entities/brick/layBricks/layBricks'; +import { Paddle } from './entities/paddle/paddle'; + +/** + * Класс игры c информацией о всех игровых сущностях + */ +export class Game { + /** + * @param {number} columnAmount количество кирпичей по оси X, неотрицателное, целое число + * @param {number} rowAmount количество кирпичей по оси Y, неотрицателное, целое число + */ + constructor(columnAmount, rowAmount) { + this.ball = new Ball(100, 100, BALL_RADIUS); + this.ball.horizontalSpeed = BALL_SPEED * Math.cos(BALL_INITIAL_ANGLE); + this.ball.verticalSpeed = -1 * BALL_SPEED * Math.sin(BALL_INITIAL_ANGLE); + + this.paddle = new Paddle(0, CONTAINER_HEIGHT - PADDLE_HEIGHT, PADDLE_WIDTH, PADDLE_HEIGHT); + + this.bricks = layBricks(columnAmount, rowAmount, BRICK_WIDTH, BRICK_HEIGHT); + } +} -- 2.54.0 From dfd21ab8378aee85e6595d8b23dbd0eb253dc805 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Fri, 17 Jul 2026 12:28:28 +0300 Subject: [PATCH 07/18] =?UTF-8?q?fix:=20=D0=98=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entities/ball/ball.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/entities/ball/ball.js b/src/entities/ball/ball.js index d79b869..0a0c3d4 100644 --- a/src/entities/ball/ball.js +++ b/src/entities/ball/ball.js @@ -20,7 +20,7 @@ export class Ball { * Изменяет координаты в зависимости от скорости и времени * @param {*} deltaTime изменение времени из Ticker */ - moveForvard(deltaTime) { + moveForward(deltaTime) { this.x += this.horizontalSpeed * deltaTime; this.y += this.verticalSpeed * deltaTime; } -- 2.54.0 From b4daf7203641d0d12de9f4911c4f69e818ff0fd7 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Fri, 17 Jul 2026 12:30:09 +0300 Subject: [PATCH 08/18] =?UTF-8?q?feat(tick)=20=D0=B4=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D1=84=D1=83=D0=BD=D0=BA=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20tick=20=D0=BE=D0=BF=D0=B8=D1=81=D1=8B=D0=B2?= =?UTF-8?q?=D0=B0=D1=8E=D1=89=D0=B0=D1=8F=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA?= =?UTF-8?q?=D1=83=20=D0=B2=D0=B7=D0=B0=D0=B8=D0=BC=D0=BE=D0=B4=D0=B5=D0=B9?= =?UTF-8?q?=D1=81=D1=82=D0=B2=D0=B8=D1=8F=20=D1=81=D1=83=D1=89=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=B5=D0=B9=20=D0=B8=D0=B3=D1=80=D1=8B=20=D0=B2?= =?UTF-8?q?=D0=BE=20=D0=B2=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/tick/tick.js | 100 ++++++++++++++++++++++++++++++++++++++ src/lib/tick/tick.test.js | 78 +++++++++++++++++++++++++++++ 2 files changed, 178 insertions(+) create mode 100644 src/lib/tick/tick.js create mode 100644 src/lib/tick/tick.test.js diff --git a/src/lib/tick/tick.js b/src/lib/tick/tick.js new file mode 100644 index 0000000..49715d6 --- /dev/null +++ b/src/lib/tick/tick.js @@ -0,0 +1,100 @@ +import { CONTAINER_HEIGHT, CONTAINER_WIDTH } from '../../config'; +import { Game } from '../../game'; +import { calculateCollision } from '../calculateCollision/calculateCollision'; +import { calculateDirection } from '../calculateDirection/calculateDirection'; + +/** + * Функция для вычисления взаимодействий сущностей игры в зависимости от времени из Ticker + * @param {Game} game экземпляр класса игры + * @param {number} containerWidth ширина игрового контейнера в пикселях + * @param {number} containerHeight высота игрового контейнера в пикселях + * @param {number} deltaTime изменение времени из Ticker + */ +export function tick(game, containerWidth, containerHeight, deltaTime) { + try { + if (!(game instanceof Game)) { + throw new Error('Аргумент game должен быть экземпляром класса игры'); + } + + if ([containerWidth, containerHeight].some((element) => typeof element !== 'number')) { + throw new Error('Значения размеров игрового контейнера должены являться числами'); + } + + if (containerWidth <= 0 || containerHeight <= 0) { + throw new Error('Размеры игрового контейнера должены быть положительными числами'); + } + + if (typeof deltaTime !== 'number' || deltaTime <= 0) { + throw new Error('Значение изменения времени должно быть положительным числом'); + } + + const { ball, paddle, bricks } = game; + + ball.moveForward(deltaTime); + + const leftBoundary = ball.radius; + const rightBoundary = containerWidth - ball.radius; + const topBoundary = ball.radius; + const bottomBoundary = containerHeight - ball.radius; + + // Не даем мячу выйти за границы стен слева / справав и меняем направление + if (ball.x <= leftBoundary || ball.x >= rightBoundary) { + ball.x = ball.x <= leftBoundary ? leftBoundary : rightBoundary; + ball.horizontalSpeed *= -1; + } + + // Не даем мячу выйти за границы стен сверху / снизу и меняем направление + if (ball.y <= topBoundary || ball.y >= bottomBoundary) { + ball.y = ball.y <= topBoundary ? topBoundary : bottomBoundary; + ball.verticalSpeed *= -1; + } + + // Базоввое взаимодействие мяча и кирпича + for (const row of bricks) { + for (const brick of row) { + if (!brick.alive) { + continue; + } + + const ballLeft = ball.x - ball.radius; + const ballRight = ball.x + ball.radius; + const ballTop = ball.y - ball.radius; + const ballBottom = ball.y + ball.radius; + + const brickLeft = brick.x; + const brickRight = brick.x + brick.width; + const brickTop = brick.y; + const brickBottom = brick.y + brick.height; + + const ballObject = { left: ballLeft, right: ballRight, top: ballTop, bottom: ballBottom }; + const brickObject = { left: brickLeft, right: brickRight, top: brickTop, bottom: brickBottom }; + + const isCollided = calculateCollision(ballObject, brickObject); + + if (isCollided) { + const directions = calculateDirection(ballObject, brickObject); + + if (directions !== null) { + ball.horizontalSpeed *= directions[0]; + ball.verticalSpeed *= directions[1]; + brick.kill(); + break; + } + } + } + } + + // Базоввое взаимодействие мяча и ракетки + if ( + ball.verticalSpeed > 0 && + ball.y + ball.radius >= paddle.y && + ball.x >= paddle.x && + ball.x <= paddle.x + paddle.width + ) { + verticalSpeed *= -1; + } + } catch (err) { + console.error(err); + return null; + } +} diff --git a/src/lib/tick/tick.test.js b/src/lib/tick/tick.test.js new file mode 100644 index 0000000..879c79f --- /dev/null +++ b/src/lib/tick/tick.test.js @@ -0,0 +1,78 @@ +import { CONTAINER_HEIGHT, CONTAINER_WIDTH } from '../../config'; +import { Game } from '../../game'; +import { tick } from './tick'; + +describe('tick', () => { + it('Возвращает корректное значние при неверных типах аргументов', () => { + expect(tick(null, 1, 1, 1)).toBeNull(); + expect(tick(1, null, 1, 1)).toBeNull(); + expect(tick(1, 1, null, 1)).toBeNull(); + expect(tick(1, 1, 1, null)).toBeNull(); + }); + + it('Возвращает корректное значние и не изменяет свойства game при неверых размерах контейнера', () => { + const game = new Game(1, 1); + const ballX = game.ball.x; + const ballY = game.ball.y; + expect(tick(game, -1, -1, 1)).toBeNull(); + expect(game.ball.x).toBe(ballX); + expect(game.ball.y).toBe(ballY); + }); + + it('Возвращает корректное значние и не изменяет свойства game при неверном значении времени', () => { + const game = new Game(1, 1); + const ballX = game.ball.x; + const ballY = game.ball.y; + expect(tick(game, 1, 1, -1)).toBeNull(); + expect(game.ball.x).toBe(ballX); + expect(game.ball.y).toBe(ballY); + }); + + it('Меняет направление мяча при столкновении со стеной', () => { + const game = new Game(1, 1); + game.ball.x = 0; + game.ball.horizontalSpeed = -10; + tick(game, CONTAINER_WIDTH, CONTAINER_HEIGHT, 1); + expect(game.ball.x).toBe(10); + expect(game.ball.horizontalSpeed).toBe(10); + }); + + it('Меняет направление мяча при столкновении с потолком', () => { + const game = new Game(0, 0); + game.ball.y = 0; + game.ball.verticalSpeed = -10; + tick(game, CONTAINER_WIDTH, CONTAINER_HEIGHT, 1); + expect(game.ball.y).toBe(game.ball.radius); + expect(game.ball.verticalSpeed).toBe(10); + }); + + it('Убивает кирпич при столкновении и отражает мяч', () => { + const game = new Game(1, 1); + const brick = game.bricks[0][0]; + + game.ball.x = brick.x + 1; + game.ball.y = brick.y + brick.height + game.ball.radius + 1; + game.ball.horizontalSpeed = 0; + game.ball.verticalSpeed = -10; + + tick(game, CONTAINER_WIDTH, CONTAINER_HEIGHT, 0.1); + + expect(brick.alive).toBe(false); + expect(game.ball.verticalSpeed).toBe(10); + }); + + it('Убивает только один кирпич за тик', () => { + const game = new Game(2, 1); + const [firstBrick, secondBrick] = game.bricks[0]; + + game.ball.x = firstBrick.x + 1; + game.ball.y = firstBrick.y + firstBrick.height + game.ball.radius + 1; + game.ball.horizontalSpeed = 0; + game.ball.verticalSpeed = -10; + + tick(game, CONTAINER_WIDTH, CONTAINER_HEIGHT, 0.1); + + const killedCount = game.bricks[0].filter((b) => !b.alive).length; + expect(killedCount).toBe(1); + }); +}); -- 2.54.0 From 5835aed8032beefa5a17c56cbc2d250d2c8b5ca6 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Fri, 17 Jul 2026 12:32:47 +0300 Subject: [PATCH 09/18] =?UTF-8?q?feat(game):=20=D0=92=20=D0=BA=D0=BB=D0=B0?= =?UTF-8?q?=D1=81=D1=81=20Game=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20update=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=B7=D1=8B=D0=B2=D0=B0=D1=8E=D1=89=D0=B8=D0=B9=20=D1=84?= =?UTF-8?q?=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8E=20tick?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/game.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/game.js b/src/game.js index aca5f7e..a6b1ee6 100644 --- a/src/game.js +++ b/src/game.js @@ -30,4 +30,12 @@ export class Game { this.bricks = layBricks(columnAmount, rowAmount, BRICK_WIDTH, BRICK_HEIGHT); } + + /** + * Изменяет значения сущностей в зависимости от времени + * @param {*} deltaTime изменение времени из Ticker + */ + update(deltaTime) { + tick(this, CONTAINER_WIDTH, CONTAINER_HEIGHT, deltaTime); + } } -- 2.54.0 From bc8903366a75333de4c132e8ea1cf4e8fc7e9e61 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Sat, 18 Jul 2026 09:29:37 +0300 Subject: [PATCH 10/18] =?UTF-8?q?feat(view):=20=D0=A1=D0=BE=D0=B7=D0=B4?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B8=D0=B7=D1=83=D0=B0=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80?= =?UTF-8?q?=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D0=B5=D0=B9=20=D0=B8?= =?UTF-8?q?=D0=B3=D1=80=D1=8B=20=D0=B2=D1=8B=D0=BD=D0=B5=D1=81=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=8B=D0=B9=20=D1=84=D0=B0=D0=B9=D0=BB=20=D0=B8=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B7=D0=B1=D0=B8=D1=82=D0=BE=20=D0=BD=D0=B0=20=D0=BE=D1=82?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20=D1=84=D1=83=D0=BD?= =?UTF-8?q?=D0=BA=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/view.js diff --git a/src/view.js b/src/view.js new file mode 100644 index 0000000..82ff17b --- /dev/null +++ b/src/view.js @@ -0,0 +1,52 @@ +import { Graphics } from 'pixi.js'; +import { Ball } from './entities/ball/ball'; +import { Brick } from './entities/brick/brick'; +import { Paddle } from './entities/paddle/paddle'; +import { Game } from './game'; + +/** + * Создает визуальное отображение мяча с помощью Pixi.js + * @param {Ball} ball экземпляр класса мяч + */ +function createBallView(ball) { + return new Graphics().circle(0, 0, ball.radius).fill('#ffffff'); +} + +/** + * Создает визуальное отображение ракетки с помощью Pixi.js + * @param {Paddle} paddle экземпляр класса ракетка + */ +function createPaddleView(paddle) { + return new Graphics().rect(0, 0, paddle.width, paddle.height).fill('#fff000'); +} + +/** + * Создает визуальное отображение кирпича с помощью Pixi.js + * @param {Brick} brick экземпляр класса кирпич + */ +function createBrickView(brick) { + return new Graphics().rect(0, 0, brick.width, brick.height).fill('#000fff'); +} + +/** + * Создает визуальное отображение всех сущностей в игре с помощью Pixi.js + * @param {Game} game экземпляр класса игра + */ +export function createGameView(game) { + try { + const ball = createBallView(game.ball); + + const paddle = createPaddleView(game.paddle); + + const bricks = game.bricks.map((row) => row.map((brick) => createBrickView(brick))); + + return { + ball, + paddle, + bricks, + }; + } catch (err) { + console.error(err); + return null; + } +} -- 2.54.0 From 1c975838985da23eee0182249502eb606003b6fc Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Sat, 18 Jul 2026 09:45:25 +0300 Subject: [PATCH 11/18] =?UTF-8?q?feat(view):=20=D0=94=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D1=84=D1=83=D0=BD=D0=BA=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B4=D0=BB=D1=8F=20=D1=81=D0=B8=D0=BD=D1=85?= =?UTF-8?q?=D1=80=D0=BE=D0=BD=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=81=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=BE=D0=B9:=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BE=D1=80=D0=B4=D0=B8=D0=BD=D0=B0=D1=82=D1=8B=20=D0=B8?= =?UTF-8?q?=20=D1=82=D0=B4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/view.js b/src/view.js index 82ff17b..fbb25b1 100644 --- a/src/view.js +++ b/src/view.js @@ -50,3 +50,30 @@ export function createGameView(game) { return null; } } + +/** + * Синхронизирует отображение сущностей Pixi.js с логикой игры (координаты и тд.) + * @param {object} views объект с визуальными отображениями сущностей игры + * @param {Game} game экземпляр класса игра + */ +export function syncronizeViewsWithGame(views, game) { + try { + views.ball.x = game.ball.x; + views.ball.y = game.ball.y; + + views.paddle.x = game.paddle.x; + views.paddle.y = game.paddle.y; + + for (let i = 0; i < game.bricks.length; i++) { + for (let j = 0; j < game.bricks[i].length; j++) { + const brick = game.bricks[i][j]; + const brickView = views.bricks[i][j]; + brickView.x = brick.x; + brickView.y = brick.y; + brickView.visible = brick.alive; + } + } + } catch (err) { + console.error(err); + } +} -- 2.54.0 From 068cf4aa79b43646462dbedc1f602b2479a8de81 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Sat, 18 Jul 2026 10:03:31 +0300 Subject: [PATCH 12/18] =?UTF-8?q?refactor(paddle):=20=D0=BC=D0=B5=D1=82?= =?UTF-8?q?=D0=BE=D0=B4=20clampTo=20=D0=B7=D0=B0=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BD=D0=B0=20moveTo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entities/paddle/paddle.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/entities/paddle/paddle.js b/src/entities/paddle/paddle.js index 23c24d0..e534883 100644 --- a/src/entities/paddle/paddle.js +++ b/src/entities/paddle/paddle.js @@ -16,14 +16,21 @@ export class Paddle { } /** - * Ограничивает минимальные и максимальные координаты положения ракетки на оси X - * @param {number} containerWidth ширина игрового поля + * Изменяет X координату ракетки, ограничивая минимальные и максимальные координаты + * @param {number} x новая X координата + * @param {number} minX минимальное положение на оси X + * @param {number} maxX максимальное положение на оси X */ - clampTo(containerWidth) { - if (this.x <= 0) { - this.x = 0; - } else if (this.x >= containerWidth - this.width) { - this.x = containerWidth - this.width; + moveTo(x, minX, maxX) { + switch (true) { + case minX !== undefined && x <= minX: + this.x = minX; + return; + case maxX !== undefined && x >= maxX - this.width: + this.x = maxX - this.width; + return; + default: + this.x = x; } } } -- 2.54.0 From 832e52c0603c7f33c9fdadb21e8b0f38e309d955 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Sat, 18 Jul 2026 10:11:34 +0300 Subject: [PATCH 13/18] =?UTF-8?q?feat(view):=20=D0=92=20=D1=84=D1=83=D0=BD?= =?UTF-8?q?=D0=BA=D1=86=D0=B8=D1=8E=20createGameView=20=D0=B4=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D1=80=20container=20=D0=B8=20=D0=B4=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D0=BE=D0=B7?= =?UTF-8?q?=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=BE=D1=82=D0=BE=D0=B1?= =?UTF-8?q?=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=B2=20=D1=8D?= =?UTF-8?q?=D1=82=D0=BE=D1=82=20=D0=BA=D0=BE=D0=BD=D1=82=D0=B5=D0=B9=D0=BD?= =?UTF-8?q?=D0=B5=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/view.js b/src/view.js index fbb25b1..0c86337 100644 --- a/src/view.js +++ b/src/view.js @@ -1,4 +1,4 @@ -import { Graphics } from 'pixi.js'; +import { Container, Graphics } from 'pixi.js'; import { Ball } from './entities/ball/ball'; import { Brick } from './entities/brick/brick'; import { Paddle } from './entities/paddle/paddle'; @@ -29,16 +29,25 @@ function createBrickView(brick) { } /** - * Создает визуальное отображение всех сущностей в игре с помощью Pixi.js + * Создает визуальное отображение всех сущностей в игре с помощью Pixi.js и добавляет в контейнер * @param {Game} game экземпляр класса игра + * @param {Container} container контейнер Pixi.js */ -export function createGameView(game) { +export function createGameView(game, container) { try { const ball = createBallView(game.ball); + container.addChild(ball); const paddle = createPaddleView(game.paddle); + container.addChild(paddle); - const bricks = game.bricks.map((row) => row.map((brick) => createBrickView(brick))); + const bricks = game.bricks.map((row) => + row.map((brick) => { + const brickView = createBrickView(brick); + container.addChild(brickView); + return brickView; + }), + ); return { ball, -- 2.54.0 From a28ec312ab5278b9c9a6529c8f84dda18b3d8ff1 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Sat, 18 Jul 2026 10:18:38 +0300 Subject: [PATCH 14/18] =?UTF-8?q?fix(game):=20=D0=94=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=B8=D0=BC=D0=BF=D0=BE=D1=80=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/game.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/game.js b/src/game.js index a6b1ee6..45a8bae 100644 --- a/src/game.js +++ b/src/game.js @@ -12,6 +12,7 @@ import { import { Ball } from './entities/ball/ball'; import { layBricks } from './entities/brick/layBricks/layBricks'; import { Paddle } from './entities/paddle/paddle'; +import { tick } from './lib/tick/tick'; /** * Класс игры c информацией о всех игровых сущностях -- 2.54.0 From 8d807f3349f62901087cb7f17bea5d6cea0e4cca Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Sat, 18 Jul 2026 10:34:07 +0300 Subject: [PATCH 15/18] =?UTF-8?q?fix(tick):=20=D0=98=D1=81=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=BE=D1=82=D1=81=D1=83?= =?UTF-8?q?=D1=82=D1=81=D1=82=D0=B2=D0=B8=D0=B5=20=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D1=89=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BA=20=D1=81=D0=B2=D0=BE?= =?UTF-8?q?=D0=B9=D1=81=D1=82=D0=B2=D1=83=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/tick/tick.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/tick/tick.js b/src/lib/tick/tick.js index 49715d6..3ca17bc 100644 --- a/src/lib/tick/tick.js +++ b/src/lib/tick/tick.js @@ -91,7 +91,7 @@ export function tick(game, containerWidth, containerHeight, deltaTime) { ball.x >= paddle.x && ball.x <= paddle.x + paddle.width ) { - verticalSpeed *= -1; + ball.verticalSpeed *= -1; } } catch (err) { console.error(err); -- 2.54.0 From 82dcc3e0b594765165e3adf0bfa3b894c3efa957 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Sat, 18 Jul 2026 10:52:19 +0300 Subject: [PATCH 16/18] =?UTF-8?q?chore(view):=20=D0=94=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=BA=D0=B0=20=D0=BD=D0=B0=20=D1=82=D0=B8=D0=BF=20=D0=B0?= =?UTF-8?q?=D1=80=D0=B3=D1=83=D0=BC=D0=B5=D0=BD=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/view.js b/src/view.js index 0c86337..4aaec1b 100644 --- a/src/view.js +++ b/src/view.js @@ -67,6 +67,10 @@ export function createGameView(game, container) { */ export function syncronizeViewsWithGame(views, game) { try { + if (!(game instanceof Game)) { + throw new Error('Аргумент game должен быть экземпляром класса Game'); + } + views.ball.x = game.ball.x; views.ball.y = game.ball.y; -- 2.54.0 From 3c86eb1f98889f45c3feba1fc821666342ba7ff3 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Sat, 18 Jul 2026 10:53:38 +0300 Subject: [PATCH 17/18] =?UTF-8?q?refactor:=20=D0=98=D0=BD=D1=82=D0=B5?= =?UTF-8?q?=D0=B3=D1=80=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BD=D0=BE=D0=B2=D0=BE?= =?UTF-8?q?=D0=B9=20=D1=80=D0=B0=D0=B7=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D0=BE=D0=B9=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config.js | 3 ++ src/main.js | 94 ++++++--------------------------------------------- 2 files changed, 14 insertions(+), 83 deletions(-) diff --git a/src/config.js b/src/config.js index 6784004..20c039a 100644 --- a/src/config.js +++ b/src/config.js @@ -10,3 +10,6 @@ export const BALL_INITIAL_ANGLE = 180; export const BRICK_WIDTH = 40; export const BRICK_HEIGHT = 10; + +export const BRICK_ROW_AMOUNT = 5; +export const BRICK_COLUMN_AMOUNT = 20; diff --git a/src/main.js b/src/main.js index 9754c58..ed9fa34 100644 --- a/src/main.js +++ b/src/main.js @@ -4,15 +4,19 @@ import { BALL_INITIAL_ANGLE, BALL_RADIUS, BALL_SPEED, + BRICK_COLUMN_AMOUNT, BRICK_HEIGHT, + BRICK_ROW_AMOUNT, BRICK_WIDTH, CONTAINER_HEIGHT, CONTAINER_WIDTH, PADDLE_HEIGHT, PADDLE_WIDTH, } from './config'; +import { Game } from './game'; import { calculateCollision } from './lib/calculateCollision/calculateCollision'; import { calculateDirection } from './lib/calculateDirection/calculateDirection'; +import { createGameView, syncronizeViewsWithGame } from './view'; (async () => { // Create a new application @@ -35,95 +39,19 @@ import { calculateDirection } from './lib/calculateDirection/calculateDirection' app.stage.addChild(container); - const paddle = new Graphics().rect(0, CONTAINER_HEIGHT - PADDLE_HEIGHT, PADDLE_WIDTH, PADDLE_HEIGHT).fill('#fff000'); - container.addChild(paddle); + const game = new Game(BRICK_COLUMN_AMOUNT, BRICK_ROW_AMOUNT); + const views = createGameView(game, container); container.on('pointermove', (event) => { const localPosition = container.toLocal(event.global); - - if (localPosition.x < CONTAINER_WIDTH - PADDLE_WIDTH) { - paddle.x = localPosition.x; - } + game.paddle.moveTo(localPosition.x, 0, CONTAINER_WIDTH); }); - const bricksRow = Array.from({ length: Math.floor(CONTAINER_WIDTH / BRICK_WIDTH) }).map((_, index) => { - const brick = new Graphics().rect(0, 0, BRICK_WIDTH, BRICK_HEIGHT).fill('#000fff'); - brick.x = index * BRICK_WIDTH; - brick.y = 1; - container.addChild(brick); - return brick; - }); - - const ball = new Graphics().circle(0, 0, BALL_RADIUS).fill('#ffffff'); - ball.x = 100; - ball.y = 100; - container.addChild(ball); - - const leftBoundary = BALL_RADIUS; - const rightBoundary = CONTAINER_WIDTH - BALL_RADIUS; - const topBoundary = BALL_RADIUS; - const bottomBoundary = CONTAINER_HEIGHT - BALL_RADIUS; - const paddleTop = CONTAINER_HEIGHT - PADDLE_HEIGHT; - const bricksBottom = BRICK_HEIGHT; - - let horizontalSpeed = BALL_SPEED * Math.cos(BALL_INITIAL_ANGLE); - let verticalSpeed = -1 * BALL_SPEED * Math.sin(BALL_INITIAL_ANGLE); + console.log(game.paddle.x, game.paddle.y); app.ticker.add((time) => { - // Базоввое взаимодействие мяча и кирпича - for (let i = bricksRow.length - 1; i >= 0; i--) { - const currentBrick = bricksRow[i]; - const brickLeft = currentBrick.x; - const brickRight = currentBrick.x + BRICK_WIDTH; - const brickTop = currentBrick.y; - const brickBottom = currentBrick.y + BRICK_HEIGHT; - - const ballLeft = ball.x - BALL_RADIUS; - const ballRight = ball.x + BALL_RADIUS; - const ballTop = ball.y - BALL_RADIUS; - const ballBottom = ball.y + BALL_RADIUS; - - const ballObject = { left: ballLeft, right: ballRight, top: ballTop, bottom: ballBottom }; - const brickObject = { left: brickLeft, right: brickRight, top: brickTop, bottom: brickBottom }; - - const isCollided = calculateCollision(ballObject, brickObject); - const directions = calculateDirection(ballObject, brickObject); - - if (isCollided && directions !== null) { - horizontalSpeed *= directions[0]; - verticalSpeed *= directions[1]; - - container.removeChild(currentBrick); - currentBrick.destroy(); - bricksRow.splice(i, 1); - - break; - } - } - - // Не даем мячу выйти за границы стен слева / справав и меняем направление - if (ball.x <= leftBoundary || ball.x >= rightBoundary) { - ball.x = ball.x <= leftBoundary ? leftBoundary : rightBoundary; - horizontalSpeed *= -1; - } - - // Не даем мячу выйти за границы стен сверху / снизу и меняем направление - if (ball.y <= topBoundary || ball.y >= bottomBoundary) { - ball.y = ball.y <= topBoundary ? topBoundary : bottomBoundary; - verticalSpeed *= -1; - } - - // Базоввое взаимодействие мяча и ракетки - if ( - verticalSpeed > 0 && - ball.y + BALL_RADIUS >= paddleTop && - ball.x >= paddle.x && - ball.x <= paddle.x + PADDLE_WIDTH - ) { - verticalSpeed *= -1; - } - - ball.x += horizontalSpeed * time.deltaTime; - ball.y += verticalSpeed * time.deltaTime; + game.update(time.deltaTime); + syncronizeViewsWithGame(views, game); + console.log(game.paddle.x, game.paddle.y); }); })(); -- 2.54.0 From 96ed22157e1eded0a098b44a8a48cae530db3c28 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Sat, 18 Jul 2026 10:55:11 +0300 Subject: [PATCH 18/18] =?UTF-8?q?chore:=20=D0=98=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3?= =?UTF-8?q?=20biome,=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=D0=BE=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BE=D1=82=D1=81=D0=BB=D0=B5=D0=B6=D0=B8=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BD=D0=B5=D0=BE=D0=B1=D1=8A=D1=8F?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=BD=D1=8B=D1=85=20=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- biome.json | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/biome.json b/biome.json index 1a1cb10..0029fce 100644 --- a/biome.json +++ b/biome.json @@ -3,8 +3,17 @@ "vcs": { "enabled": true, "clientKind": "git", "useIgnoreFile": true }, "files": { "includes": ["src/**/*", "*.js", "*.json"] }, "formatter": { "enabled": true, "indentStyle": "space", "indentWidth": 2, "lineWidth": 120 }, - "linter": { "enabled": true, "rules": { "preset": "recommended" } }, + "linter": { + "enabled": true, + "rules": { + "recommended": true, + "correctness": { + "noUndeclaredVariables": "error" + } + } + }, "javascript": { + "globals": ["describe", "it", "expect"], "formatter": { "quoteStyle": "single", "semicolons": "always", -- 2.54.0