refactor: Формат хранения кирпичей в классе Game переписан с вложенного массива на обычный массив. Входные данные для значений каждого кирпича берутся из карты уровней
This commit is contained in:
+22
-24
@@ -66,36 +66,34 @@ export function tick(game, containerWidth, containerHeight, deltaTime) {
|
||||
}
|
||||
|
||||
// Базоввое взаимодействие мяча и кирпича
|
||||
for (const row of bricks) {
|
||||
for (const brick of row) {
|
||||
if (!brick.alive) {
|
||||
continue;
|
||||
}
|
||||
for (const brick of bricks) {
|
||||
if (!brick.alive) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const ballLeft = ball.x - ball.radius;
|
||||
const ballRight = ball.x + ball.radius;
|
||||
const ballTop = ball.y - ball.radius;
|
||||
const ballBottom = ball.y + ball.radius;
|
||||
const ballLeft = ball.x - ball.radius;
|
||||
const ballRight = ball.x + ball.radius;
|
||||
const ballTop = ball.y - ball.radius;
|
||||
const ballBottom = ball.y + ball.radius;
|
||||
|
||||
const brickLeft = brick.x;
|
||||
const brickRight = brick.x + brick.width;
|
||||
const brickTop = brick.y;
|
||||
const brickBottom = brick.y + brick.height;
|
||||
const brickLeft = brick.x;
|
||||
const brickRight = brick.x + brick.width;
|
||||
const brickTop = brick.y;
|
||||
const brickBottom = brick.y + brick.height;
|
||||
|
||||
const ballObject = { left: ballLeft, right: ballRight, top: ballTop, bottom: ballBottom };
|
||||
const brickObject = { left: brickLeft, right: brickRight, top: brickTop, bottom: brickBottom };
|
||||
const ballObject = { left: ballLeft, right: ballRight, top: ballTop, bottom: ballBottom };
|
||||
const brickObject = { left: brickLeft, right: brickRight, top: brickTop, bottom: brickBottom };
|
||||
|
||||
const isCollided = calculateCollision(ballObject, brickObject);
|
||||
const isCollided = calculateCollision(ballObject, brickObject);
|
||||
|
||||
if (isCollided) {
|
||||
const directions = calculateDirection(ballObject, brickObject);
|
||||
if (isCollided) {
|
||||
const directions = calculateDirection(ballObject, brickObject);
|
||||
|
||||
if (directions !== null) {
|
||||
ball.horizontalSpeed *= directions[0];
|
||||
ball.verticalSpeed *= directions[1];
|
||||
brick.kill();
|
||||
return;
|
||||
}
|
||||
if (directions !== null) {
|
||||
ball.horizontalSpeed *= directions[0];
|
||||
ball.verticalSpeed *= directions[1];
|
||||
brick.kill();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user