2026-07-14 19:11:15 +03:00
|
|
|
import './style.css';
|
2026-07-16 08:30:14 +03:00
|
|
|
import { Application, Assets, Container, Graphics, Sprite } from 'pixi.js';
|
|
|
|
|
import { CONTAINER_HEIGHT, CONTAINER_WIDTH, PADDLE_HEIGHT, PADDLE_WIDTH } from './config';
|
2026-07-14 19:44:13 +03:00
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
|
// Create a new application
|
|
|
|
|
const app = new Application();
|
|
|
|
|
|
|
|
|
|
// Initialize the application
|
2026-07-16 08:30:14 +03:00
|
|
|
await app.init({ background: '#1099bb', width: CONTAINER_WIDTH, height: CONTAINER_HEIGHT });
|
2026-07-14 19:44:13 +03:00
|
|
|
|
|
|
|
|
// Append the application canvas to the document body
|
|
|
|
|
document.body.appendChild(app.canvas);
|
|
|
|
|
|
|
|
|
|
// Create and add a container to the stage
|
2026-07-16 08:30:14 +03:00
|
|
|
const container = new Container({
|
|
|
|
|
eventMode: 'static',
|
|
|
|
|
hitArea: app.screen,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
container.x = 0;
|
|
|
|
|
container.y = 0;
|
2026-07-14 19:44:13 +03:00
|
|
|
|
|
|
|
|
app.stage.addChild(container);
|
|
|
|
|
|
2026-07-16 08:30:14 +03:00
|
|
|
const paddle = new Graphics().rect(0, CONTAINER_HEIGHT - PADDLE_HEIGHT, PADDLE_WIDTH, PADDLE_HEIGHT).fill('#fff000');
|
2026-07-14 19:44:13 +03:00
|
|
|
|
2026-07-16 08:30:14 +03:00
|
|
|
container.addChild(paddle);
|
2026-07-14 19:44:13 +03:00
|
|
|
|
2026-07-16 08:30:14 +03:00
|
|
|
container.on('pointermove', (event) => {
|
|
|
|
|
const localPosition = container.toLocal(event.global);
|
2026-07-14 19:44:13 +03:00
|
|
|
|
2026-07-16 08:30:14 +03:00
|
|
|
if (localPosition.x < CONTAINER_WIDTH - PADDLE_WIDTH) {
|
|
|
|
|
paddle.x = localPosition.x;
|
|
|
|
|
}
|
2026-07-14 19:44:13 +03:00
|
|
|
});
|
|
|
|
|
})();
|