Feature/advanced game mechanics #5
@@ -9,6 +9,8 @@ export const PADDLE_SECTOR_AMOUNT = 20;
|
|||||||
|
|
||||||
export const BALL_RADIUS = 10;
|
export const BALL_RADIUS = 10;
|
||||||
export const BALL_SPEED = 3;
|
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 BALL_INITIAL_ANGLE = 0;
|
||||||
|
|
||||||
export const BRICK_WIDTH = 40;
|
export const BRICK_WIDTH = 40;
|
||||||
|
|||||||
@@ -56,4 +56,22 @@ export class Ball {
|
|||||||
this.status = 'moving';
|
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
@@ -2,6 +2,8 @@ import {
|
|||||||
BALL_INITIAL_ANGLE,
|
BALL_INITIAL_ANGLE,
|
||||||
BALL_RADIUS,
|
BALL_RADIUS,
|
||||||
BALL_SPEED,
|
BALL_SPEED,
|
||||||
|
BALL_SPEED_LEVEL_STEP,
|
||||||
|
BALL_SPEED_TIME_STEP,
|
||||||
BRICK_HEIGHT,
|
BRICK_HEIGHT,
|
||||||
BRICK_WIDTH,
|
BRICK_WIDTH,
|
||||||
CONTAINER_HEIGHT,
|
CONTAINER_HEIGHT,
|
||||||
@@ -13,7 +15,6 @@ import { Ball } from './entities/ball/ball';
|
|||||||
import { layBricks } from './entities/brick/layBricks/layBricks';
|
import { layBricks } from './entities/brick/layBricks/layBricks';
|
||||||
import { Paddle } from './entities/paddle/paddle';
|
import { Paddle } from './entities/paddle/paddle';
|
||||||
import { tick } from './lib/tick/tick';
|
import { tick } from './lib/tick/tick';
|
||||||
import { toRadians } from './lib/toRadians/toRadians';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Класс игры c информацией о всех игровых сущностях
|
* Класс игры c информацией о всех игровых сущностях
|
||||||
@@ -65,6 +66,8 @@ export class Game {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.ball.increaseSpeed(BALL_SPEED_TIME_STEP * deltaTime);
|
||||||
|
|
||||||
const isLevelComplete = this._checkLevelCompletion();
|
const isLevelComplete = this._checkLevelCompletion();
|
||||||
|
|
||||||
if (isLevelComplete) {
|
if (isLevelComplete) {
|
||||||
@@ -90,6 +93,7 @@ export class Game {
|
|||||||
* Запускает переход на новый уровень, возвращает мяч в дефоотное положение и отрисовывает кирпичи по карте уровня.
|
* Запускает переход на новый уровень, возвращает мяч в дефоотное положение и отрисовывает кирпичи по карте уровня.
|
||||||
*/
|
*/
|
||||||
_proceedToNextLevel() {
|
_proceedToNextLevel() {
|
||||||
|
this.ball.increaseSpeed(BALL_SPEED_LEVEL_STEP);
|
||||||
this._placeBallOnPaddle();
|
this._placeBallOnPaddle();
|
||||||
this.bricks = layBricks(this.levels[this.currentLevel], BRICK_WIDTH, BRICK_HEIGHT);
|
this.bricks = layBricks(this.levels[this.currentLevel], BRICK_WIDTH, BRICK_HEIGHT);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import {
|
import {
|
||||||
BALL_SPEED,
|
|
||||||
CONTAINER_HEIGHT,
|
CONTAINER_HEIGHT,
|
||||||
CONTAINER_WIDTH,
|
CONTAINER_WIDTH,
|
||||||
MAX_PADDLE_REFLECTION_ANGLE,
|
MAX_PADDLE_REFLECTION_ANGLE,
|
||||||
@@ -105,7 +104,7 @@ export function tick(game, containerWidth, containerHeight, deltaTime) {
|
|||||||
PADDLE_SECTOR_AMOUNT,
|
PADDLE_SECTOR_AMOUNT,
|
||||||
MIN_PADDLE_REFLECTION_ANGLE,
|
MIN_PADDLE_REFLECTION_ANGLE,
|
||||||
MAX_PADDLE_REFLECTION_ANGLE,
|
MAX_PADDLE_REFLECTION_ANGLE,
|
||||||
BALL_SPEED,
|
ball.speed,
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|||||||
Reference in New Issue
Block a user