feat(ball): Добавлена логика изменения базовой скорости мяча. С течением времени и на каждом следующем уровне

This commit is contained in:
Ilia Mashkov
2026-07-19 13:20:10 +03:00
parent 62abd8b77d
commit b05fb89bc5
4 changed files with 26 additions and 3 deletions
+2
View File
@@ -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;
+18
View File
@@ -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;
}
}
+5 -1
View File
@@ -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);
}
+1 -2
View File
@@ -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);