import './style.css'; import { Application, Assets, Container, Graphics, Sprite } from 'pixi.js'; import { BALL_INITIAL_ANGLE, BALL_RADIUS, BALL_SPEED, BRICK_COLUMN_AMOUNT, BRICK_HEIGHT, BRICK_ROW_AMOUNT, BRICK_WIDTH, CONTAINER_HEIGHT, CONTAINER_WIDTH, PADDLE_HEIGHT, PADDLE_WIDTH, } from './config'; import { LEVELS } from './const/levels'; import { Game } from './game'; import { calculateCollision } from './lib/calculateCollision/calculateCollision'; import { calculateDirection } from './lib/calculateDirection/calculateDirection'; import { createGameView, syncronizeViewsWithGame } from './view'; (async () => { // Create a new application const app = new Application(); // Initialize the application await app.init({ background: '#1099bb', width: CONTAINER_WIDTH, height: CONTAINER_HEIGHT }); // Append the application canvas to the document body document.body.appendChild(app.canvas); // Create and add a container to the stage const container = new Container({ eventMode: 'static', hitArea: app.screen, }); container.x = 0; container.y = 0; app.stage.addChild(container); const game = new Game(LEVELS); const views = createGameView(game, container); container.on('pointermove', (event) => { const localPosition = container.toLocal(event.global); game.paddle.moveTo(localPosition.x, 0, CONTAINER_WIDTH); }); console.log(game.paddle.x, game.paddle.y); app.ticker.add((time) => { game.update(time.deltaTime); syncronizeViewsWithGame(views, game); console.log(game.paddle.x, game.paddle.y); }); })();