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);