From b05fb89bc55da219c2db2768e70b50ba3207ef4c Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Sun, 19 Jul 2026 13:20:10 +0300 Subject: [PATCH] =?UTF-8?q?feat(ball):=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2=D0=BE=D0=B9=20=D1=81=D0=BA=D0=BE?= =?UTF-8?q?=D1=80=D0=BE=D1=81=D1=82=D0=B8=20=D0=BC=D1=8F=D1=87=D0=B0.=20?= =?UTF-8?q?=D0=A1=20=D1=82=D0=B5=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC=20?= =?UTF-8?q?=D0=B2=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=B8=20=D0=B8=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BA=D0=B0=D0=B6=D0=B4=D0=BE=D0=BC=20=D1=81=D0=BB?= =?UTF-8?q?=D0=B5=D0=B4=D1=83=D1=8E=D1=89=D0=B5=D0=BC=20=D1=83=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=BD=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config.js | 2 ++ src/entities/ball/ball.js | 18 ++++++++++++++++++ src/game.js | 6 +++++- src/lib/tick/tick.js | 3 +-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/config.js b/src/config.js index 14bae67..c61245a 100644 --- a/src/config.js +++ b/src/config.js @@ -9,6 +9,8 @@ export const PADDLE_SECTOR_AMOUNT = 20; export const BALL_RADIUS = 10; export const BALL_SPEED = 3; +export const BALL_SPEED_LEVEL_STEP = 2; +export const BALL_SPEED_TIME_STEP = 0.002; export const BALL_INITIAL_ANGLE = 0; export const BRICK_WIDTH = 40; diff --git a/src/entities/ball/ball.js b/src/entities/ball/ball.js index edeab9b..a265bc2 100644 --- a/src/entities/ball/ball.js +++ b/src/entities/ball/ball.js @@ -56,4 +56,22 @@ export class Ball { this.status = 'moving'; } } + + /** + * Увеличивает скорость мяча не меняя направление + * @param {number} step положительное числовое значение прибавки к скорости + */ + increaseSpeed(step) { + if (this.speed <= 0) { + return; + } + + const magnifyingCoeficient = (this.speed + step) / this.speed; + this.speed += step; + + this.verticalSpeed *= magnifyingCoeficient; + this.horizontalSpeed *= magnifyingCoeficient; + this.defaultVerticalSpeed *= magnifyingCoeficient; + this.defaultHorizontalSpeed *= magnifyingCoeficient; + } } diff --git a/src/game.js b/src/game.js index 9fd9dff..d1d25a7 100644 --- a/src/game.js +++ b/src/game.js @@ -2,6 +2,8 @@ import { BALL_INITIAL_ANGLE, BALL_RADIUS, BALL_SPEED, + BALL_SPEED_LEVEL_STEP, + BALL_SPEED_TIME_STEP, BRICK_HEIGHT, BRICK_WIDTH, CONTAINER_HEIGHT, @@ -13,7 +15,6 @@ 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'; -import { toRadians } from './lib/toRadians/toRadians'; /** * Класс игры c информацией о всех игровых сущностях @@ -65,6 +66,8 @@ export class Game { return; } + this.ball.increaseSpeed(BALL_SPEED_TIME_STEP * deltaTime); + const isLevelComplete = this._checkLevelCompletion(); if (isLevelComplete) { @@ -90,6 +93,7 @@ export class Game { * Запускает переход на новый уровень, возвращает мяч в дефоотное положение и отрисовывает кирпичи по карте уровня. */ _proceedToNextLevel() { + this.ball.increaseSpeed(BALL_SPEED_LEVEL_STEP); this._placeBallOnPaddle(); this.bricks = layBricks(this.levels[this.currentLevel], BRICK_WIDTH, BRICK_HEIGHT); } diff --git a/src/lib/tick/tick.js b/src/lib/tick/tick.js index 8394cf6..5e951dc 100644 --- a/src/lib/tick/tick.js +++ b/src/lib/tick/tick.js @@ -1,5 +1,4 @@ import { - BALL_SPEED, CONTAINER_HEIGHT, CONTAINER_WIDTH, MAX_PADDLE_REFLECTION_ANGLE, @@ -105,7 +104,7 @@ export function tick(game, containerWidth, containerHeight, deltaTime) { PADDLE_SECTOR_AMOUNT, MIN_PADDLE_REFLECTION_ANGLE, MAX_PADDLE_REFLECTION_ANGLE, - BALL_SPEED, + ball.speed, ); } catch (err) { console.error(err);