diff --git a/src/game.js b/src/game.js index 71df444..f37876d 100644 --- a/src/game.js +++ b/src/game.js @@ -25,6 +25,7 @@ export class Game { constructor(levels) { this.livesAmount = 3; this.status = 'in_process'; + this.levels = levels; this.currentLevel = 0; this.maxLevel = levels.length - 1; @@ -36,7 +37,7 @@ export class Game { -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(levels[this.currentLevel], BRICK_WIDTH, BRICK_HEIGHT); + this.bricks = layBricks(this.levels[this.currentLevel], BRICK_WIDTH, BRICK_HEIGHT); } /** @@ -47,6 +48,7 @@ export class Game { if (this.status !== 'in_process') { return; } + tick(this, CONTAINER_WIDTH, CONTAINER_HEIGHT, deltaTime); if (this.ball.isOut) { @@ -57,12 +59,28 @@ export class Game { } else { this.ball.reset(); } + + return; } const isAnyBrickAlive = this.bricks.some((brick) => brick.alive); if (!isAnyBrickAlive) { - this.status = 'completed'; + this.currentLevel += 1; + + if (this.currentLevel <= this.maxLevel) { + this._proceedToNextLevel(); + } else { + this.status = 'completed'; + } } } + + /** + * Запускает переход на новый уровень, возвращает мяч в дефоотное положение и отрисовывает кирпичи по карте уровня. + */ + _proceedToNextLevel() { + this.ball.reset(); + this.bricks = layBricks(this.levels[this.currentLevel], BRICK_WIDTH, BRICK_HEIGHT); + } }