feat(perk): Добавлен бонус clone который добавляет 2 дополнительных мяча

This commit is contained in:
Ilia Mashkov
2026-07-19 17:47:01 +03:00
parent a734600390
commit b72583290d
6 changed files with 94 additions and 100 deletions
+28 -5
View File
@@ -67,8 +67,12 @@ function createPerkView(perk) {
*/
export function createGameView(game, container) {
try {
const ball = createBallView(game.ball);
container.addChild(ball);
const balls = new Map();
for (const ball of game.balls) {
const ballView = createBallView(ball);
container.addChild(ballView);
balls.set(ball, ballView);
}
const paddle = createPaddleView(game.paddle);
container.addChild(paddle);
@@ -82,7 +86,7 @@ export function createGameView(game, container) {
const perks = new Map();
return {
ball,
balls,
paddle,
bricks,
perks,
@@ -107,6 +111,22 @@ export function managePerkViewsLifetime(views, game, container) {
container.addChild(views.paddle);
}
for (const [ball, ballView] of views.balls) {
if (!game.balls.includes(ball)) {
container.removeChild(ballView);
ballView.destroy();
views.balls.delete(ball);
}
}
for (const ball of game.balls) {
if (!views.balls.has(ball)) {
const ballView = createBallView(ball);
container.addChild(ballView);
views.balls.set(ball, ballView);
}
}
for (const [perk, perkView] of views.perks) {
if (!game.perks.includes(perk)) {
container.removeChild(perkView);
@@ -135,8 +155,11 @@ export function syncronizeViewsWithGame(views, game) {
throw new Error('Аргумент game должен быть экземпляром класса Game');
}
views.ball.x = game.ball.x;
views.ball.y = game.ball.y;
for (const ball of game.balls) {
const ballView = views.balls.get(ball);
ballView.x = ball.x;
ballView.y = ball.y;
}
views.paddle.x = game.paddle.x;
views.paddle.y = game.paddle.y;