From bc8903366a75333de4c132e8ea1cf4e8fc7e9e61 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Sat, 18 Jul 2026 09:29:37 +0300 Subject: [PATCH] =?UTF-8?q?feat(view):=20=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B8=D0=B7=D1=83=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=BB=D1=8F=20=D1=81?= =?UTF-8?q?=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D0=B5=D0=B9=20=D0=B8=D0=B3?= =?UTF-8?q?=D1=80=D1=8B=20=D0=B2=D1=8B=D0=BD=D0=B5=D1=81=D0=B5=D0=BD=D0=BE?= =?UTF-8?q?=20=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B?= =?UTF-8?q?=D0=B9=20=D1=84=D0=B0=D0=B9=D0=BB=20=D0=B8=20=D1=80=D0=B0=D0=B7?= =?UTF-8?q?=D0=B1=D0=B8=D1=82=D0=BE=20=D0=BD=D0=B0=20=D0=BE=D1=82=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20=D1=84=D1=83=D0=BD=D0=BA?= =?UTF-8?q?=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/view.js diff --git a/src/view.js b/src/view.js new file mode 100644 index 0000000..82ff17b --- /dev/null +++ b/src/view.js @@ -0,0 +1,52 @@ +import { Graphics } from 'pixi.js'; +import { Ball } from './entities/ball/ball'; +import { Brick } from './entities/brick/brick'; +import { Paddle } from './entities/paddle/paddle'; +import { Game } from './game'; + +/** + * Создает визуальное отображение мяча с помощью Pixi.js + * @param {Ball} ball экземпляр класса мяч + */ +function createBallView(ball) { + return new Graphics().circle(0, 0, ball.radius).fill('#ffffff'); +} + +/** + * Создает визуальное отображение ракетки с помощью Pixi.js + * @param {Paddle} paddle экземпляр класса ракетка + */ +function createPaddleView(paddle) { + return new Graphics().rect(0, 0, paddle.width, paddle.height).fill('#fff000'); +} + +/** + * Создает визуальное отображение кирпича с помощью Pixi.js + * @param {Brick} brick экземпляр класса кирпич + */ +function createBrickView(brick) { + return new Graphics().rect(0, 0, brick.width, brick.height).fill('#000fff'); +} + +/** + * Создает визуальное отображение всех сущностей в игре с помощью Pixi.js + * @param {Game} game экземпляр класса игра + */ +export function createGameView(game) { + try { + const ball = createBallView(game.ball); + + const paddle = createPaddleView(game.paddle); + + const bricks = game.bricks.map((row) => row.map((brick) => createBrickView(brick))); + + return { + ball, + paddle, + bricks, + }; + } catch (err) { + console.error(err); + return null; + } +}