feat: Добавлена логика отскока мяча и логика логика смерти кирпичей
Build and push / build (push) Skipped
Build and push / build (pull_request) Successful in 34s
Build and push / build (push) Skipped
Build and push / build (pull_request) Successful in 34s
This commit is contained in:
+17
-6
@@ -12,6 +12,7 @@ import {
|
|||||||
PADDLE_WIDTH,
|
PADDLE_WIDTH,
|
||||||
} from './config';
|
} from './config';
|
||||||
import { calculateCollision } from './lib/calculateCollision/calculateCollision';
|
import { calculateCollision } from './lib/calculateCollision/calculateCollision';
|
||||||
|
import { calculateDirection } from './lib/calculateDirection/calculateDirection';
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
// Create a new application
|
// Create a new application
|
||||||
@@ -54,6 +55,8 @@ import { calculateCollision } from './lib/calculateCollision/calculateCollision'
|
|||||||
});
|
});
|
||||||
|
|
||||||
const ball = new Graphics().circle(0, 0, BALL_RADIUS).fill('#ffffff');
|
const ball = new Graphics().circle(0, 0, BALL_RADIUS).fill('#ffffff');
|
||||||
|
ball.x = 100;
|
||||||
|
ball.y = 100;
|
||||||
container.addChild(ball);
|
container.addChild(ball);
|
||||||
|
|
||||||
const leftBoundary = BALL_RADIUS;
|
const leftBoundary = BALL_RADIUS;
|
||||||
@@ -80,13 +83,21 @@ import { calculateCollision } from './lib/calculateCollision/calculateCollision'
|
|||||||
const ballTop = ball.y - BALL_RADIUS;
|
const ballTop = ball.y - BALL_RADIUS;
|
||||||
const ballBottom = ball.y + BALL_RADIUS;
|
const ballBottom = ball.y + BALL_RADIUS;
|
||||||
|
|
||||||
const isCollided = calculateCollision(
|
const ballObject = { left: ballLeft, right: ballRight, top: ballTop, bottom: ballBottom };
|
||||||
{ left: ballLeft, right: ballRight, top: ballTop, bottom: ballBottom },
|
const brickObject = { left: brickLeft, right: brickRight, top: brickTop, bottom: brickBottom };
|
||||||
{ left: brickLeft, right: brickRight, top: brickTop, bottom: brickBottom },
|
|
||||||
);
|
|
||||||
|
|
||||||
if (isCollided) {
|
const isCollided = calculateCollision(ballObject, brickObject);
|
||||||
verticalSpeed *= -1;
|
const directions = calculateDirection(ballObject, brickObject);
|
||||||
|
|
||||||
|
if (isCollided && directions !== null) {
|
||||||
|
horizontalSpeed *= directions[0];
|
||||||
|
verticalSpeed *= directions[1];
|
||||||
|
|
||||||
|
container.removeChild(currentBrick);
|
||||||
|
currentBrick.destroy();
|
||||||
|
bricksRow.splice(i, 1);
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user