Feature/advanced game mechanics #5

Merged
ilia merged 30 commits from feature/advanced-game-mechanics into main 2026-07-19 15:09:22 +00:00
2 changed files with 26 additions and 5 deletions
Showing only changes of commit 500803db84 - Show all commits
+6 -4
View File
@@ -17,7 +17,7 @@ import { LEVELS } from './const/levels';
import { Game } from './game'; import { Game } from './game';
import { calculateCollision } from './lib/calculateCollision/calculateCollision'; import { calculateCollision } from './lib/calculateCollision/calculateCollision';
import { calculateDirection } from './lib/calculateDirection/calculateDirection'; import { calculateDirection } from './lib/calculateDirection/calculateDirection';
import { createGameView, syncronizeViewsWithGame } from './view'; import { createGameView, rebuildBrickViews, syncronizeViewsWithGame } from './view';
(async () => { (async () => {
// Create a new application // Create a new application
@@ -42,17 +42,19 @@ import { createGameView, syncronizeViewsWithGame } from './view';
const game = new Game(LEVELS); const game = new Game(LEVELS);
const views = createGameView(game, container); const views = createGameView(game, container);
const currentLevel = game.currentLevel;
container.on('pointermove', (event) => { container.on('pointermove', (event) => {
const localPosition = container.toLocal(event.global); const localPosition = container.toLocal(event.global);
game.paddle.moveTo(localPosition.x, 0, CONTAINER_WIDTH); game.paddle.moveTo(localPosition.x, 0, CONTAINER_WIDTH);
}); });
console.log(game.paddle.x, game.paddle.y);
app.ticker.add((time) => { app.ticker.add((time) => {
game.update(time.deltaTime); game.update(time.deltaTime);
if (game.currentLevel !== currentLevel) {
rebuildBrickViews(views, game, container);
}
syncronizeViewsWithGame(views, game); syncronizeViewsWithGame(views, game);
console.log(game.paddle.x, game.paddle.y);
}); });
})(); })();
+20 -1
View File
@@ -42,7 +42,7 @@ function createBrickView(brick) {
/** /**
* Создает визуальное отображение всех сущностей в игре с помощью Pixi.js и добавляет в контейнер * Создает визуальное отображение всех сущностей в игре с помощью Pixi.js и добавляет в контейнер
* @param {Game} game экземпляр класса игра * @param {Game} game экземпляр класса игра
* @param {Container} container контейнер Pixi.js * @param {Container} container экземпляр класса контейнер Pixi.js
*/ */
export function createGameView(game, container) { export function createGameView(game, container) {
try { try {
@@ -97,3 +97,22 @@ export function syncronizeViewsWithGame(views, game) {
console.error(err); console.error(err);
} }
} }
/**
* Пересоздает отображения кирпичей под текущий уровень игры.
* @param {object} views объект с визуальными отображениями сущностей игры
* @param {Game} game экземпляр класса игра
* @param {Container} container экземпляр класса контейнер Pixi.js
*/
export function rebuildBrickViews(views, game, container) {
for (const brickView of views.bricks) {
container.removeChild(brickView);
brickView.destroy();
}
views.bricks = game.bricks.map((brick) => {
const brickView = createBrickView(brick);
container.addChild(brickView);
return brickView;
});
}