Feature/advanced game mechanics #5
@@ -1,3 +1,5 @@
|
|||||||
|
import { toRadians } from '../../lib/toRadians/toRadians';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Класс сущности "мяч"
|
* Класс сущности "мяч"
|
||||||
* @class
|
* @class
|
||||||
@@ -7,21 +9,23 @@ export class Ball {
|
|||||||
* @param {number} x координата положения мяча по оси X
|
* @param {number} x координата положения мяча по оси X
|
||||||
* @param {number} y координата положения мяча по оси Y
|
* @param {number} y координата положения мяча по оси Y
|
||||||
* @param {number} radius положительное числовое значение радиуса мяча
|
* @param {number} radius положительное числовое значение радиуса мяча
|
||||||
* @param {number} verticalSpeed вектор движения мяча по оси Y
|
* @param {number} speed положительное числовое значение скорости мяча
|
||||||
* @param {number} horizontalSpeed вектор движения мяча по оси X
|
* @param {number} angle угол направления движения мяча в градусах
|
||||||
*/
|
*/
|
||||||
constructor(x, y, radius, verticalSpeed = 0, horizontalSpeed = 0) {
|
constructor(x, y, radius, speed = 0, angle = 0) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.radius = radius;
|
this.radius = radius;
|
||||||
this.verticalSpeed = verticalSpeed;
|
this.speed = speed;
|
||||||
this.horizontalSpeed = horizontalSpeed;
|
this.angle = angle;
|
||||||
|
this.verticalSpeed = speed * Math.cos(toRadians(angle));
|
||||||
|
this.horizontalSpeed = -1 * speed * Math.sin(toRadians(angle));
|
||||||
this.status = 'idle';
|
this.status = 'idle';
|
||||||
|
|
||||||
this.defaultX = x;
|
this.defaultX = x;
|
||||||
this.defaultY = y;
|
this.defaultY = y;
|
||||||
this.defaultVerticalSpeed = verticalSpeed;
|
this.defaultVerticalSpeed = this.verticalSpeed;
|
||||||
this.defaultHorizontalSpeed = horizontalSpeed;
|
this.defaultHorizontalSpeed = this.horizontalSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-7
@@ -30,13 +30,7 @@ export class Game {
|
|||||||
this.maxLevel = levels.length - 1;
|
this.maxLevel = levels.length - 1;
|
||||||
|
|
||||||
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.ball = new Ball(
|
this.ball = new Ball(0, 0, BALL_RADIUS, BALL_SPEED, BALL_INITIAL_ANGLE);
|
||||||
0,
|
|
||||||
0,
|
|
||||||
BALL_RADIUS,
|
|
||||||
BALL_SPEED * Math.cos(toRadians(BALL_INITIAL_ANGLE)),
|
|
||||||
-1 * BALL_SPEED * Math.sin(toRadians(BALL_INITIAL_ANGLE)),
|
|
||||||
);
|
|
||||||
this.bricks = layBricks(this.levels[this.currentLevel], BRICK_WIDTH, BRICK_HEIGHT);
|
this.bricks = layBricks(this.levels[this.currentLevel], BRICK_WIDTH, BRICK_HEIGHT);
|
||||||
|
|
||||||
this._placeBallOnPaddle();
|
this._placeBallOnPaddle();
|
||||||
|
|||||||
Reference in New Issue
Block a user