feat(ball): В конструктор класса добавлены значения скорости, Добавлено сохранение аргументов конструктора и метод reset, использующий сохраненные дефолтные значения
This commit is contained in:
@@ -7,13 +7,20 @@ export class Ball {
|
||||
* @param {number} x координата положения мяча по оси X
|
||||
* @param {number} y координата положения мяча по оси Y
|
||||
* @param {number} radius положительное числовое значение радиуса мяча
|
||||
* @param {number} verticalSpeed вектор движения мяча по оси Y
|
||||
* @param {number} horizontalSpeed вектор движения мяча по оси X
|
||||
*/
|
||||
constructor(x, y, radius) {
|
||||
constructor(x, y, radius, verticalSpeed = 0, horizontalSpeed = 0) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.horizontalSpeed = 0;
|
||||
this.verticalSpeed = 0;
|
||||
this.radius = radius;
|
||||
this.verticalSpeed = verticalSpeed;
|
||||
this.horizontalSpeed = horizontalSpeed;
|
||||
|
||||
this.defaultX = x;
|
||||
this.defaultY = y;
|
||||
this.defaultVerticalSpeed = verticalSpeed;
|
||||
this.defaultHorizontalSpeed = horizontalSpeed;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,4 +31,14 @@ export class Ball {
|
||||
this.x += this.horizontalSpeed * deltaTime;
|
||||
this.y += this.verticalSpeed * deltaTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает значения к дефолтным
|
||||
*/
|
||||
reset() {
|
||||
this.x = this.defaultX;
|
||||
this.y = this.defaultY;
|
||||
this.verticalSpeed = this.defaultVerticalSpeed;
|
||||
this.horizontalSpeed = this.defaultHorizontalSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-4
@@ -23,10 +23,13 @@ export class Game {
|
||||
* @param {number} rowAmount количество кирпичей по оси Y, неотрицателное, целое число
|
||||
*/
|
||||
constructor(columnAmount, rowAmount) {
|
||||
this.ball = new Ball(100, 100, BALL_RADIUS);
|
||||
this.ball.horizontalSpeed = BALL_SPEED * Math.cos(BALL_INITIAL_ANGLE);
|
||||
this.ball.verticalSpeed = -1 * BALL_SPEED * Math.sin(BALL_INITIAL_ANGLE);
|
||||
|
||||
this.ball = new Ball(
|
||||
100,
|
||||
100,
|
||||
BALL_RADIUS,
|
||||
BALL_SPEED * Math.cos(BALL_INITIAL_ANGLE),
|
||||
-1 * BALL_SPEED * Math.sin(BALL_INITIAL_ANGLE),
|
||||
);
|
||||
this.paddle = new Paddle(0, CONTAINER_HEIGHT - PADDLE_HEIGHT, PADDLE_WIDTH, PADDLE_HEIGHT);
|
||||
|
||||
this.bricks = layBricks(columnAmount, rowAmount, BRICK_WIDTH, BRICK_HEIGHT);
|
||||
|
||||
Reference in New Issue
Block a user