Feautre/pixijs mvp #3

Merged
ilia merged 9 commits from feautre/pixijs-mvp into main 2026-07-17 05:07:43 +00:00
Showing only changes of commit 37ed43fdfa - Show all commits
+17 -6
View File
@@ -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;
} }
} }