Feature/advanced game mechanics #5
+20
-2
@@ -25,6 +25,7 @@ export class Game {
|
|||||||
constructor(levels) {
|
constructor(levels) {
|
||||||
this.livesAmount = 3;
|
this.livesAmount = 3;
|
||||||
this.status = 'in_process';
|
this.status = 'in_process';
|
||||||
|
this.levels = levels;
|
||||||
this.currentLevel = 0;
|
this.currentLevel = 0;
|
||||||
this.maxLevel = levels.length - 1;
|
this.maxLevel = levels.length - 1;
|
||||||
|
|
||||||
@@ -36,7 +37,7 @@ export class Game {
|
|||||||
-1 * BALL_SPEED * Math.sin(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.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') {
|
if (this.status !== 'in_process') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tick(this, CONTAINER_WIDTH, CONTAINER_HEIGHT, deltaTime);
|
tick(this, CONTAINER_WIDTH, CONTAINER_HEIGHT, deltaTime);
|
||||||
|
|
||||||
if (this.ball.isOut) {
|
if (this.ball.isOut) {
|
||||||
@@ -57,12 +59,28 @@ export class Game {
|
|||||||
} else {
|
} else {
|
||||||
this.ball.reset();
|
this.ball.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isAnyBrickAlive = this.bricks.some((brick) => brick.alive);
|
const isAnyBrickAlive = this.bricks.some((brick) => brick.alive);
|
||||||
|
|
||||||
if (!isAnyBrickAlive) {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user