diff --git a/src/view.js b/src/view.js index b1a5efd..8ce1416 100644 --- a/src/view.js +++ b/src/view.js @@ -9,9 +9,10 @@ import { Game } from './game'; /** * Создает визуальное отображение мяча с помощью Pixi.js * @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); ballSprite.anchor.set(0.5); ballSprite.width = ball.radius * 2; @@ -23,9 +24,10 @@ function createBallView(ball, texture) { /** * Создает визуальное отображение ракетки с помощью Pixi.js * @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 }); paddleSprite.width = paddle.width; paddleSprite.height = paddle.height; @@ -37,10 +39,16 @@ function createPaddleView(paddle, texture) { * Создает визуальное отображение кирпича с помощью Pixi.js * @param {Brick} brick экземпляр класса кирпич * @returns {Graphics} графическое отображение кирпича - * @param {unknown} textures текстуры блоков + * @param {object} 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.height = brick.height; @@ -101,22 +109,16 @@ export function createGameView(game, container, textures) { const balls = new Map(); for (const ball of game.balls) { - const ballView = createBallView(ball, textures['/sprites/fire_ball_1.png']); + const ballView = createBallView(ball, textures); container.addChild(ballView); balls.set(ball, ballView); } - const paddle = createPaddleView(game.paddle, textures['/sprites/paddle.png']); + const paddle = createPaddleView(game.paddle, textures); 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 brickView = createBrickView(brick, bricksTextures); + const brickView = createBrickView(brick, textures); container.addChild(brickView); return brickView; }); @@ -158,7 +160,7 @@ export function managePerkViewsLifetime(views, game, container, textures) { for (const ball of game.balls) { if (!views.balls.has(ball)) { - const ballView = createBallView(ball, textures['/sprites/fire_ball_1.png']); + const ballView = createBallView(ball, textures); container.addChild(ballView); views.balls.set(ball, ballView); } @@ -234,13 +236,8 @@ export function rebuildBrickViews(views, game, container, textures) { 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) => { - const brickView = createBrickView(brick); + const brickView = createBrickView(brick, textures); container.addChild(brickView); return brickView; });