feat(perk): Добавлен бонус clone который добавляет 2 дополнительных мяча

This commit is contained in:
Ilia Mashkov
2026-07-19 17:47:01 +03:00
parent a734600390
commit b72583290d
6 changed files with 94 additions and 100 deletions
+20 -4
View File
@@ -32,13 +32,21 @@ export class Game {
this.maxLevel = levels.length - 1;
this.paddle = new Paddle(0, CONTAINER_HEIGHT - PADDLE_HEIGHT, PADDLE_WIDTH, PADDLE_HEIGHT);
this.ball = new Ball(0, 0, BALL_RADIUS, BALL_SPEED, BALL_INITIAL_ANGLE);
this.balls = [new Ball(0, 0, BALL_RADIUS, BALL_SPEED, BALL_INITIAL_ANGLE)];
this.bricks = layBricks(this.levels[this.currentLevel], BRICK_WIDTH, BRICK_HEIGHT);
this.perks = [];
this._placeBallOnPaddle();
}
/**
* Основной (первый) мяч. Пока играет один мяч - это он.
* @returns {Ball}
*/
get ball() {
return this.balls[0];
}
/**
* Изменяет значения сущностей в зависимости от времени
* @param {*} deltaTime изменение времени из Ticker
@@ -56,7 +64,10 @@ export class Game {
tick(this, CONTAINER_WIDTH, CONTAINER_HEIGHT, deltaTime);
if (this.ball.status === 'out') {
// Убираем улетевшие мячи. Жизнь теряется только когда не осталось ни одного
const survivingBalls = this.balls.filter((ball) => ball.status !== 'out');
if (survivingBalls.length === 0) {
this.livesAmount -= 1;
if (this.livesAmount === 0) {
@@ -68,7 +79,11 @@ export class Game {
return;
}
this.ball.increaseSpeed(BALL_SPEED_TIME_STEP * deltaTime);
this.balls = survivingBalls;
for (const ball of this.balls) {
ball.increaseSpeed(BALL_SPEED_TIME_STEP * deltaTime);
}
const isLevelComplete = this._checkLevelCompletion();
@@ -101,9 +116,10 @@ export class Game {
}
/**
* Ставит мяч по центру ракетки
* Ставит мяч по центру ракетки, оставляя один мяч в игре
*/
_placeBallOnPaddle() {
this.balls = [this.ball];
this.ball.reset(this.paddle.x + this.paddle.width / 2, this.paddle.y - this.ball.radius);
}
}