Feature/appearance #6
+19
-22
@@ -9,9 +9,10 @@ import { Game } from './game';
|
|||||||
/**
|
/**
|
||||||
* Создает визуальное отображение мяча с помощью Pixi.js
|
* Создает визуальное отображение мяча с помощью Pixi.js
|
||||||
* @param {Ball} ball экземпляр класса мяч
|
* @param {Ball} ball экземпляр класса мяч
|
||||||
* @param {unknown} texture текстура мяча
|
* @param {object} textures объект с текстурами для визуального отображения
|
||||||
*/
|
*/
|
||||||
function createBallView(ball, texture) {
|
function createBallView(ball, textures) {
|
||||||
|
const texture = textures['/sprites/fire_ball_1.png'];
|
||||||
const ballSprite = new Sprite(texture);
|
const ballSprite = new Sprite(texture);
|
||||||
ballSprite.anchor.set(0.5);
|
ballSprite.anchor.set(0.5);
|
||||||
ballSprite.width = ball.radius * 2;
|
ballSprite.width = ball.radius * 2;
|
||||||
@@ -23,9 +24,10 @@ function createBallView(ball, texture) {
|
|||||||
/**
|
/**
|
||||||
* Создает визуальное отображение ракетки с помощью Pixi.js
|
* Создает визуальное отображение ракетки с помощью Pixi.js
|
||||||
* @param {Paddle} paddle экземпляр класса ракетка
|
* @param {Paddle} paddle экземпляр класса ракетка
|
||||||
* @param {unknown} texture текстура ракетки
|
* @param {object} textures объект с текстурами для визуального отображения
|
||||||
*/
|
*/
|
||||||
function createPaddleView(paddle, texture) {
|
function createPaddleView(paddle, textures) {
|
||||||
|
const texture = textures['/sprites/paddle.png'];
|
||||||
const paddleSprite = new NineSliceSprite({ texture, leftWidth: 150, rightWidth: 150, topHeight: 0, bottomHeight: 0 });
|
const paddleSprite = new NineSliceSprite({ texture, leftWidth: 150, rightWidth: 150, topHeight: 0, bottomHeight: 0 });
|
||||||
paddleSprite.width = paddle.width;
|
paddleSprite.width = paddle.width;
|
||||||
paddleSprite.height = paddle.height;
|
paddleSprite.height = paddle.height;
|
||||||
@@ -37,10 +39,16 @@ function createPaddleView(paddle, texture) {
|
|||||||
* Создает визуальное отображение кирпича с помощью Pixi.js
|
* Создает визуальное отображение кирпича с помощью Pixi.js
|
||||||
* @param {Brick} brick экземпляр класса кирпич
|
* @param {Brick} brick экземпляр класса кирпич
|
||||||
* @returns {Graphics} графическое отображение кирпича
|
* @returns {Graphics} графическое отображение кирпича
|
||||||
* @param {unknown} textures текстуры блоков
|
* @param {object} textures объект с текстурами для визуального отображения
|
||||||
*/
|
*/
|
||||||
function createBrickView(brick, textures) {
|
function createBrickView(brick, textures) {
|
||||||
const brickSprite = new Sprite(textures[brick.type - 1]);
|
const bricksTextures = [
|
||||||
|
textures['/sprites/block_1.png'],
|
||||||
|
textures['/sprites/block_2.png'],
|
||||||
|
textures['/sprites/block_3.png'],
|
||||||
|
];
|
||||||
|
|
||||||
|
const brickSprite = new Sprite(bricksTextures[brick.type - 1]);
|
||||||
brickSprite.width = brick.width;
|
brickSprite.width = brick.width;
|
||||||
brickSprite.height = brick.height;
|
brickSprite.height = brick.height;
|
||||||
|
|
||||||
@@ -101,22 +109,16 @@ export function createGameView(game, container, textures) {
|
|||||||
|
|
||||||
const balls = new Map();
|
const balls = new Map();
|
||||||
for (const ball of game.balls) {
|
for (const ball of game.balls) {
|
||||||
const ballView = createBallView(ball, textures['/sprites/fire_ball_1.png']);
|
const ballView = createBallView(ball, textures);
|
||||||
container.addChild(ballView);
|
container.addChild(ballView);
|
||||||
balls.set(ball, ballView);
|
balls.set(ball, ballView);
|
||||||
}
|
}
|
||||||
|
|
||||||
const paddle = createPaddleView(game.paddle, textures['/sprites/paddle.png']);
|
const paddle = createPaddleView(game.paddle, textures);
|
||||||
container.addChild(paddle);
|
container.addChild(paddle);
|
||||||
|
|
||||||
const bricksTextures = [
|
|
||||||
textures['/sprites/block_1.png'],
|
|
||||||
textures['/sprites/block_2.png'],
|
|
||||||
textures['/sprites/block_3.png'],
|
|
||||||
];
|
|
||||||
|
|
||||||
const bricks = game.bricks.map((brick) => {
|
const bricks = game.bricks.map((brick) => {
|
||||||
const brickView = createBrickView(brick, bricksTextures);
|
const brickView = createBrickView(brick, textures);
|
||||||
container.addChild(brickView);
|
container.addChild(brickView);
|
||||||
return brickView;
|
return brickView;
|
||||||
});
|
});
|
||||||
@@ -158,7 +160,7 @@ export function managePerkViewsLifetime(views, game, container, textures) {
|
|||||||
|
|
||||||
for (const ball of game.balls) {
|
for (const ball of game.balls) {
|
||||||
if (!views.balls.has(ball)) {
|
if (!views.balls.has(ball)) {
|
||||||
const ballView = createBallView(ball, textures['/sprites/fire_ball_1.png']);
|
const ballView = createBallView(ball, textures);
|
||||||
container.addChild(ballView);
|
container.addChild(ballView);
|
||||||
views.balls.set(ball, ballView);
|
views.balls.set(ball, ballView);
|
||||||
}
|
}
|
||||||
@@ -234,13 +236,8 @@ export function rebuildBrickViews(views, game, container, textures) {
|
|||||||
brickView.destroy();
|
brickView.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
const bricksTextures = [
|
|
||||||
textures['/sprites/brick_1.png'],
|
|
||||||
textures['/sprites/brick_2.png'],
|
|
||||||
textures['/sprites/brick_3.png'],
|
|
||||||
];
|
|
||||||
views.bricks = game.bricks.map((brick) => {
|
views.bricks = game.bricks.map((brick) => {
|
||||||
const brickView = createBrickView(brick);
|
const brickView = createBrickView(brick, textures);
|
||||||
container.addChild(brickView);
|
container.addChild(brickView);
|
||||||
return brickView;
|
return brickView;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user