Feature/advanced game mechanics #5

Merged
ilia merged 30 commits from feature/advanced-game-mechanics into main 2026-07-19 15:09:22 +00:00
2 changed files with 27 additions and 7 deletions
Showing only changes of commit e303535250 - Show all commits
+20 -3
View File
@@ -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
View File
@@ -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);