feat(ball): Флаг isOut заменен на поле status, изменено начальное положение мяча при старте игры, добавлена функция запуска мяча по клику

This commit is contained in:
Ilia Mashkov
2026-07-19 11:24:37 +03:00
parent e7b52bdbd9
commit 0f057c1add
4 changed files with 40 additions and 12 deletions
+21 -6
View File
@@ -29,15 +29,17 @@ export class Game {
this.currentLevel = 0;
this.maxLevel = levels.length - 1;
this.paddle = new Paddle(0, CONTAINER_HEIGHT - PADDLE_HEIGHT, PADDLE_WIDTH, PADDLE_HEIGHT);
this.ball = new Ball(
CONTAINER_WIDTH / 2 - BALL_RADIUS / 2,
CONTAINER_HEIGHT / 2 - BALL_RADIUS / 2,
0,
0,
BALL_RADIUS,
BALL_SPEED * Math.cos(toRadians(BALL_INITIAL_ANGLE)),
-1 * BALL_SPEED * Math.sin(toRadians(BALL_INITIAL_ANGLE)),
);
this.paddle = new Paddle(0, CONTAINER_HEIGHT - PADDLE_HEIGHT, PADDLE_WIDTH, PADDLE_HEIGHT);
this.bricks = layBricks(this.levels[this.currentLevel], BRICK_WIDTH, BRICK_HEIGHT);
this._placeBallOnPaddle();
}
/**
@@ -49,15 +51,21 @@ export class Game {
return;
}
// Пока мяч не запущен - держим его на ракетке и не считаем физику
if (this.ball.status === 'idle') {
this._placeBallOnPaddle();
return;
}
tick(this, CONTAINER_WIDTH, CONTAINER_HEIGHT, deltaTime);
if (this.ball.isOut) {
if (this.ball.status === 'out') {
this.livesAmount -= 1;
if (this.livesAmount === 0) {
this.status = 'over';
} else {
this.ball.reset();
this._placeBallOnPaddle();
}
return;
@@ -88,7 +96,14 @@ export class Game {
* Запускает переход на новый уровень, возвращает мяч в дефоотное положение и отрисовывает кирпичи по карте уровня.
*/
_proceedToNextLevel() {
this.ball.reset();
this._placeBallOnPaddle();
this.bricks = layBricks(this.levels[this.currentLevel], BRICK_WIDTH, BRICK_HEIGHT);
}
/**
* Ставит мяч по центру ракетки
*/
_placeBallOnPaddle() {
this.ball.reset(this.paddle.x + this.paddle.width / 2, this.paddle.y - this.ball.radius);
}
}