Feautre/pixijs mvp #3
+11
@@ -49,6 +49,7 @@ import {
|
|||||||
const rightBoundary = CONTAINER_WIDTH - BALL_RADIUS;
|
const rightBoundary = CONTAINER_WIDTH - BALL_RADIUS;
|
||||||
const topBoundary = BALL_RADIUS;
|
const topBoundary = BALL_RADIUS;
|
||||||
const bottomBoundary = CONTAINER_HEIGHT - BALL_RADIUS;
|
const bottomBoundary = CONTAINER_HEIGHT - BALL_RADIUS;
|
||||||
|
const paddleTop = CONTAINER_HEIGHT - PADDLE_HEIGHT;
|
||||||
|
|
||||||
let horizontalSpeed = BALL_SPEED * Math.cos(BALL_INITIAL_ANGLE);
|
let horizontalSpeed = BALL_SPEED * Math.cos(BALL_INITIAL_ANGLE);
|
||||||
let verticalSpeed = -1 * BALL_SPEED * Math.sin(BALL_INITIAL_ANGLE);
|
let verticalSpeed = -1 * BALL_SPEED * Math.sin(BALL_INITIAL_ANGLE);
|
||||||
@@ -66,6 +67,16 @@ import {
|
|||||||
verticalSpeed *= -1;
|
verticalSpeed *= -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Базоввое взаимодействие мяча и ракетки
|
||||||
|
if (
|
||||||
|
verticalSpeed > 0 &&
|
||||||
|
ball.y + BALL_RADIUS >= paddleTop &&
|
||||||
|
ball.x >= paddle.x &&
|
||||||
|
ball.x <= paddle.x + PADDLE_WIDTH
|
||||||
|
) {
|
||||||
|
verticalSpeed *= -1;
|
||||||
|
}
|
||||||
|
|
||||||
ball.x += horizontalSpeed * time.deltaTime;
|
ball.x += horizontalSpeed * time.deltaTime;
|
||||||
ball.y += verticalSpeed * time.deltaTime;
|
ball.y += verticalSpeed * time.deltaTime;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user